Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Exit codes: 0 = no issues, 1 = issues found, 2 = error.
-q, --quiet Suppress summary line
--no-packed-check Skip "should be packed" detection
--no-alignment-check Skip misaligned member detection
-m, --max-align <N> Override maximum alignment boundary in bytes (default: 4 for 32-bit, 8 for 64-bit ELF)
```

### Custom patterns
Expand All @@ -70,7 +71,7 @@ struct-lint reads ELF binaries using `gimli` for zero-copy DWARF parsing. It doe
2. For packed structs: check if each member's offset is naturally aligned (`offset % min(member_size, arch_max_align) == 0`)
3. For structs matching the name pattern: check if `sizeof(struct)` equals the sum of member sizes (i.e. no padding)

Natural alignment uses the ELF header to determine the architecture's maximum alignment (4 for 32-bit, 8 for 64-bit).
Natural alignment uses the ELF header to determine the architecture's maximum alignment (4 for 32-bit, 8 for 64-bit), overridable with `--max-align`.

## License

Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ struct Cli {
/// Skip misaligned member detection
#[arg(long)]
no_alignment_check: bool,

/// Maximum alignment boundary in bytes (default: 4 for 32-bit, 8 for 64-bit ELF).
#[arg(short, long)]
max_align: Option<u64>,
}

fn make_relative(path: &str) -> String {
Expand Down Expand Up @@ -148,7 +152,7 @@ fn main() {
}
};

let max_align: u64 = if obj.is_64() { 8 } else { 4 };
let max_align = cli.max_align.unwrap_or(if obj.is_64() { 8 } else { 4 });

let dwarf = match gimli::Dwarf::load(|section_id| -> Result<R, gimli::Error> {
let data = obj
Expand Down