Description
The --apply-dynamic-relocs
option controls whether the static linker should write the result of a RELA dynamic relocation into the place, when the relocation can be resolved statically.
lld defaults to --no-apply-dynamic-relocs
whereas GNU ld defaults to --apply-dynamic-relocs
Normally it doesn't matter whether the dynamic relocations are resolved statically or not. However this can catch people out that have used --pie
, and static linking. With --apply-dynamic-relocs
the binary can be run at its static link time address without relocation, whereas with --no-apply-dynamic-relocs
some relocations need to be resolved. We had an internal team that found their project trusted-firmware didn't work with clang/lld when linked with --pie but worked with gcc/ld.bfd. This was fixed by adding --apply-dynamic-relocs
but that option isn't very discoverable.
This is a somewhat niche use-case, but there may be some tweaks we can make, either in lld or potentially the clang bare-metal driver to help out. Some thoughts:
- The bare metal driver could pass
--apply-dynamic-relocs
through to lld. - LLD could switch to
--apply-dynamic-relocs
when static linking.