NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
50.61k stars 5.78k forks source link

m68000: wrong alignment for structure members #2375

Open th-otto opened 3 years ago

th-otto commented 3 years ago

On m68k, the alignment of all types >= 2 bytes should be 2, not 4 as specified in 68000.cspec. To verify:

$ cat foo.c
struct foo {
        short x;
        double y;
};

int x = __builtin_offsetof(struct foo, y);

$ m68k-elf-gcc -S -o - foo.c
x:
        .long   2
        .ident  "GCC: (GNU) 10.0.1 20200501 (prerelease)"

The value of the global variable "x" there is 2. That would be the case also for other types of y in the structure.

quietust commented 3 years ago

I've encountered this multiple times when analyzing old Amiga programs - many of the standard structures contain pointers which straddle a 32-bit boundary and thus end up being the wrong size.