[llvm-commits] [PATCH] ELF file alignments

Benjamin Kramer benny.kra at googlemail.com
Mon Sep 6 09:13:35 PDT 2010


On 06.09.2010, at 11:48, Krister Wombell wrote:

> The ELF spec says:
> 
> All data structures that the object file format defines follow the
>> "natural'' size and alignment guidelines for the relevant class. If
>> necessary, data structures contain explicit padding to ensure 4-byte
>> alignment for 4-byte objects, to force structure sizes to a multiple of 4,
>> and so on. Data also have suitable alignment from the beginning of the file.
>> Thus, for example, a structure containing an Elf32_Addr member will be
>> aligned on a 4-byte boundary within the file.
>> 
> 
> 1. ELFObjectWriter doesn't write the following objects with correct file
> alignment: symtab, relocation sections, section headers. It probably goes
> unnoticed because most CPUs support unaligned memory accesses and get to the
> data without a problem plus linkers tend to fix things up too.  CPUs without
> unaligned accesses don't fare as well.
> 
> 2. gas goes a step further than the rules above and ensures that even in
> relocatable output that a section's file offset is also a multiple of the
> section alignment. This behaviour falls out of the patch as well.
> 
> Krister

Thanks, the patch looks great. Applied in r113155.



More information about the llvm-commits mailing list