Page MenuHomePhabricator

[ELF] Check the Elf_Rel addends for dynamic relocations
Needs ReviewPublic

Authored by arichardson on Apr 28 2021, 6:38 AM.



There used to be many cases where addends for Elf_Rel were not emitted in
the final object file (mostly when building for MIPS64 since the input .o
files use RELA but the output uses REL). These cases have been fixed since,
but this patch adds a check to ensure that the written values are correct.
It is based on a previous patch that I added to the CHERI fork of LLD since
we were using MIPS64 as a baseline. The work has now almost entirely
shifted to RISC-V and Arm Morello (which use Elf_Rela), but I thought
it would be useful to upstream our local changes anyway.

This patch adds a (hidden) command line flag --check-dynamic-relocations
that can be used to enable these checks. It is also on by default in
assertions builds for targets that handle all dynamic relocations kinds
that LLD can emit in Target::getImplicitAddend(). Currently this is
enabled for ARM, MIPS, and I386.

Depends on D100490

Diff Detail

Unit TestsFailed

80 msx64 debian > lld.ELF::reloc-sec-before-relocated.test
Script: -- : 'RUN: at line 7'; /mnt/disks/ssd0/agent/llvm-project/build/bin/yaml2obj /mnt/disks/ssd0/agent/llvm-project/lld/test/ELF/reloc-sec-before-relocated.test -DTYPE=SHT_RELA -o /mnt/disks/ssd0/agent/llvm-project/build/tools/lld/test/ELF/Output/reloc-sec-before-relocated.test.tmp1.o
70 msx64 debian > lld.ELF/invalid::broken-relaxation-x64.test
Script: -- : 'RUN: at line 3'; /mnt/disks/ssd0/agent/llvm-project/build/bin/yaml2obj /mnt/disks/ssd0/agent/llvm-project/lld/test/ELF/invalid/broken-relaxation-x64.test -o /mnt/disks/ssd0/agent/llvm-project/build/tools/lld/test/ELF/invalid/Output/broken-relaxation-x64.test.tmp.o
340 msx64 windows > lld.ELF::reloc-sec-before-relocated.test
Script: -- : 'RUN: at line 7'; c:\ws\w32-1\llvm-project\premerge-checks\build\bin\yaml2obj.exe C:\ws\w32-1\llvm-project\premerge-checks\lld\test\ELF\reloc-sec-before-relocated.test -DTYPE=SHT_RELA -o C:\ws\w32-1\llvm-project\premerge-checks\build\tools\lld\test\ELF\Output\reloc-sec-before-relocated.test.tmp1.o
180 msx64 windows > lld.ELF/invalid::broken-relaxation-x64.test
Script: -- : 'RUN: at line 3'; c:\ws\w32-1\llvm-project\premerge-checks\build\bin\yaml2obj.exe C:\ws\w32-1\llvm-project\premerge-checks\lld\test\ELF\invalid\broken-relaxation-x64.test -o C:\ws\w32-1\llvm-project\premerge-checks\build\tools\lld\test\ELF\invalid\Output\broken-relaxation-x64.test.tmp.o

Event Timeline

arichardson created this revision.Apr 28 2021, 6:38 AM
arichardson requested review of this revision.Apr 28 2021, 6:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2021, 6:38 AM

Thanks for splitting out. I'm happy with this. Will be good to wait for MaskRay to have a look.

MaskRay added inline comments.Apr 30 2021, 2:30 PM

The value is not used. implementations don't use addend for JUMP_SLOT/GLOB_DAT.


perhaps use

dynamic relocation XXX at offset YYY[ against symbol ZZZ]