Change how we iterate over relocations on ELF.

For COFF and MachO, sections semantically have relocations that apply to them.
That is not the case on ELF.

In relocatable objects (.o), a section with relocations in ELF has offsets to
another section where the relocations should be applied.

In dynamic objects and executables, relocations don't have an offset, they have
a virtual address. The section sh_info may or may not point to another section,
but that is not actually used for resolving the relocations.

This patch exposes that in the ObjectFile API. It has the following advantages:

* Most (all?) clients can handle this more efficiently. They will normally walk
all relocations, so doing an effort to iterate in a particular order doesn't
save time.

* llvm-readobj now prints relocations in the same way the native readelf does.

* probably most important, relocations that don't point to any section are now
visible. This is the case of relocations in the rela.dyn section. See the
updated relocation-executable.test for example.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182908 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2013-05-30 03:05:14 +00:00
parent d2df98f3aa
commit 7486d92a6c
83 changed files with 423 additions and 339 deletions

View File

@ -108,10 +108,6 @@ ELF-NEXT: Info: 0
ELF-NEXT: AddressAlignment: 16
ELF-NEXT: EntrySize: 0
ELF-NEXT: Relocations [
ELF-NEXT: 0xC R_386_GOTPC _GLOBAL_OFFSET_TABLE_ 0x0
ELF-NEXT: 0x12 R_386_GOTOFF .L.str 0x0
ELF-NEXT: 0x1A R_386_PLT32 puts 0x0
ELF-NEXT: 0x1F R_386_PLT32 SomeOtherFunction 0x0
ELF-NEXT: ]
ELF-NEXT: Symbols [
ELF-NEXT: Symbol {
@ -139,6 +135,32 @@ ELF-NEXT: 0010: 8D830000 00008904 24E8FCFF FFFFE8FC |........$.......|
ELF-NEXT: 0020: FFFFFF31 C083C408 5BC3 |...1....[.|
ELF-NEXT: )
ELF-NEXT: }
ELF-NEXT: Section {
ELF-NEXT: Index: 2
ELF-NEXT: Name: .rel.text (1)
ELF-NEXT: Type: SHT_REL (0x9)
ELF-NEXT: Flags [ (0x0)
ELF-NEXT: ]
ELF-NEXT: Address: 0x0
ELF-NEXT: Offset: 0x360
ELF-NEXT: Size: 32
ELF-NEXT: Link: 8
ELF-NEXT: Info: 1
ELF-NEXT: AddressAlignment: 4
ELF-NEXT: EntrySize: 8
ELF-NEXT: Relocations [
ELF-NEXT: 0xC R_386_GOTPC _GLOBAL_OFFSET_TABLE_ 0x0
ELF-NEXT: 0x12 R_386_GOTOFF .L.str 0x0
ELF-NEXT: 0x1A R_386_PLT32 puts 0x0
ELF-NEXT: 0x1F R_386_PLT32 SomeOtherFunction 0x0
ELF-NEXT: ]
ELF-NEXT: Symbols [
ELF-NEXT: ]
ELF-NEXT: SectionData (
ELF-NEXT: 0000: 0C000000 0A0A0000 12000000 09020000 |................|
ELF-NEXT: 0010: 1A000000 040B0000 1F000000 04090000 |................|
ELF-NEXT: )
ELF-NEXT: }
MACHO-I386: Sections [
MACHO-I386-NEXT: Section {