[PATCH] D54759: [LLD][ELF] Use more specific method to calculate DT_PLTRELSZ

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 20 08:46:20 PST 2018


peter.smith created this revision.
peter.smith added reviewers: ruiu, grimar.
Herald added subscribers: kristof.beyls, arichardson, javed.absar, emaste, srhines.
Herald added a reviewer: espindola.

The DT_PLTRELSZ dynamic tag is calculated using the size of the OutputSection containing the In.RelaPlt InputSection. This will work for the default no linker script case and the majority of linker scripts. Unfortunately it doesn't work for some 'almost' sensible linker scripts. It is permitted by ELF to have a single OutputSection containing both In.RelaDyn, In.RelaPlt and In.RelaIPlt. It is also permissible for the range of memory [DT_RELA, DT_RELA + DT_RELASZ) and the range [DT_JMPREL, DT_JMPREL + DT_JMPRELSZ) to overlap as long as the the latter range is at the end (see comment in glibc dynamic loader) https://code.woboq.org/userspace/glibc/elf/dynamic-link.h.html#108).

To support a linker script containing something like: .rela.dyn : { *(.rela.dyn) *(.rela.plt) } use the InputSections to determine DT_JMPRELSZ rather than the OutputSection size. I've left the calculation of the .rela.dyn to be the size of the OutputSection as that is the most literal reading of ELF and the smallest change. This affects all targets, I've added tests for AArch64, x86 (cited in PR) and ARM (as the irelative relocations do not go in the .rel.plt).

There will be no change to any project using the default linker script or the more modern

  .rela.dyn       : { *(.rela.dyn) }
  .rela.plt         : { *(.rela.plt) *(.rela.iplt) }

fixes pr39678 (https://bugs.llvm.org/show_bug.cgi?id=39678)

I considered giving an error message rather than trying to support this case but the logic of working out when there is an error is no simpler. It also risked faulting existing programs.


https://reviews.llvm.org/D54759

Files:
  ELF/SyntheticSections.cpp
  ELF/SyntheticSections.h
  test/ELF/aarch64-combined-dynrel-ifunc.s
  test/ELF/aarch64-combined-dynrel.s
  test/ELF/arm-combined-dynrel-ifunc.s
  test/ELF/x86-64-combined-dynrel.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54759.174783.patch
Type: text/x-patch
Size: 8375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181120/4b3ff167/attachment.bin>


More information about the llvm-commits mailing list