[llvm-commits] [PATCH] ELF file alignments

Krister Wombell kuwerty at gmail.com
Mon Sep 6 02:48:06 PDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100906/85d01d24/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: elf_alignment.patch
Type: text/x-patch
Size: 2977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100906/85d01d24/attachment.bin>


More information about the llvm-commits mailing list