[PATCH] Change how we iterate over relocations on ELF

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Fri May 24 20:36:18 PDT 2013


Hi Bigcheese,

Hi Michael,

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.


http://llvm-reviews.chandlerc.com/D866

Files:
  include/llvm/Object/ELF.h
  include/llvm/Object/ObjectFile.h
  lib/DebugInfo/DWARFContext.cpp
  lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
  lib/MC/MCObjectSymbolizer.cpp
  lib/Object/ObjectFile.cpp
  test/CodeGen/AArch64/adrp-relocation.ll
  test/CodeGen/AArch64/basic-pic.ll
  test/CodeGen/AArch64/elf-extern.ll
  test/CodeGen/AArch64/jump-table.ll
  test/CodeGen/ARM/2010-11-30-reloc-movt.ll
  test/CodeGen/ARM/ehabi-mc-compact-pr0.ll
  test/CodeGen/ARM/ehabi-mc-compact-pr1.ll
  test/CodeGen/PowerPC/mcm-obj-2.ll
  test/CodeGen/PowerPC/mcm-obj.ll
  test/CodeGen/PowerPC/tls-gd-obj.ll
  test/CodeGen/PowerPC/tls-ie-obj.ll
  test/CodeGen/PowerPC/tls-ld-obj.ll
  test/MC/AArch64/elf-globaladdress.ll
  test/MC/AArch64/elf-reloc-addsubimm.s
  test/MC/AArch64/elf-reloc-condbr.s
  test/MC/AArch64/elf-reloc-ldrlit.s
  test/MC/AArch64/elf-reloc-ldstunsimm.s
  test/MC/AArch64/elf-reloc-movw.s
  test/MC/AArch64/elf-reloc-pcreladdressing.s
  test/MC/AArch64/elf-reloc-tstb.s
  test/MC/AArch64/elf-reloc-uncondbrimm.s
  test/MC/AArch64/tls-relocs.s
  test/MC/ARM/eh-compact-pr0.s
  test/MC/ARM/eh-compact-pr1.s
  test/MC/ARM/eh-directive-cantunwind.s
  test/MC/ARM/eh-directive-handlerdata.s
  test/MC/ARM/eh-directive-personality.s
  test/MC/ARM/eh-directive-section-multiple-func.s
  test/MC/ARM/eh-directive-section.s
  test/MC/ARM/eh-directive-text-section-multiple-func.s
  test/MC/ARM/eh-directive-text-section.s
  test/MC/ARM/elf-movt.s
  test/MC/ARM/elf-reloc-01.ll
  test/MC/ARM/elf-reloc-02.ll
  test/MC/ARM/elf-reloc-03.ll
  test/MC/ARM/elf-reloc-condcall.s
  test/MC/ARM/elf-thumbfunc-reloc.ll
  test/MC/ARM/elf-thumbfunc-reloc.s
  test/MC/ELF/alias-reloc.s
  test/MC/ELF/basic-elf-32.s
  test/MC/ELF/basic-elf-64.s
  test/MC/ELF/cfi-adjust-cfa-offset.s
  test/MC/ELF/cfi-advance-loc2.s
  test/MC/ELF/cfi-def-cfa-offset.s
  test/MC/ELF/cfi-def-cfa-register.s
  test/MC/ELF/cfi-def-cfa.s
  test/MC/ELF/cfi-escape.s
  test/MC/ELF/cfi-offset.s
  test/MC/ELF/cfi-register.s
  test/MC/ELF/cfi-rel-offset.s
  test/MC/ELF/cfi-rel-offset2.s
  test/MC/ELF/cfi-remember.s
  test/MC/ELF/cfi-restore.s
  test/MC/ELF/cfi-same-value.s
  test/MC/ELF/cfi-undefined.s
  test/MC/ELF/cfi-zero-addr-delta.s
  test/MC/ELF/cfi.s
  test/MC/ELF/gen-dwarf.s
  test/MC/ELF/got.s
  test/MC/ELF/local-reloc.s
  test/MC/ELF/merge.s
  test/MC/ELF/relocation-386.s
  test/MC/ELF/relocation-pc.s
  test/MC/ELF/relocation.s
  test/MC/ELF/rename.s
  test/MC/ELF/symref.s
  test/MC/ELF/weak-relocation.s
  test/MC/ELF/x86_64-reloc-sizetest.s
  test/MC/Mips/eh-frame.s
  test/MC/Mips/elf-gprel-32-64.ll
  test/MC/Mips/elf-tls.ll
  test/MC/PowerPC/ppc64-initial-cfa.ll
  test/MC/PowerPC/ppc64-relocs-01.ll
  test/MC/PowerPC/ppc64-tls-relocs-01.ll
  test/Object/relocation-executable.test
  test/tools/llvm-readobj/relocations.test
  test/tools/llvm-readobj/sections-ext.test
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D866.1.patch
Type: text/x-patch
Size: 81803 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130524/7b0b3ead/attachment.bin>


More information about the llvm-commits mailing list