<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/136704>136704</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            lld default of --no-apply-dynamic-relocs is not ideal when no dynamic linking is required.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          smithp35
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVE1z4zYP_jXyBWONTFm2c9Ah7-6b9pDZQ7udPUMibKKhSJWErPrfd0gp2aTdZE-esYgHeD4AjJEvjqgtmv8VzecNTmJ8aOPAYsa62XRe39qvhqA4VNstjqO9bfXN4cD9NpD1fSwOFfhR2DvovZPgbYTZkBgKIIYgCgr3YNk9UYBo_GQ1zIGF8udAcbIC_gwIv_3_8R5WdMjomHHZic-PR4s9FepTauDW8pdXPTroMqC3V9JrY7T2VhbVfVHdW6tB0xknKxHEL5Scf5fVbCgQRvjlyx_wo9J36pZmX3wYUm9gA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