Skip to content

lld default of --no-apply-dynamic-relocs is not ideal when no dynamic linking is required. #136704

Open
@smithp35

Description

@smithp35

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions