[LLD][ELF] - A fix for "linker script assignment loses relative nature of section...
authorGeorge Rimar <grimar@accesssoftek.com>
Thu, 18 Apr 2019 10:00:37 +0000 (10:00 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Thu, 18 Apr 2019 10:00:37 +0000 (10:00 +0000)
commit69186f82f3f557423618d7e5ffeb3355e89ce73a
treedab4a2823d5eb269b3e19c0d9a7cc60054753887
parent8f87e53462a652921acd0c36c3fc96427ee44932
[LLD][ELF] - A fix for "linker script assignment loses relative nature of section" bug.

This is https://bugs.llvm.org//show_bug.cgi?id=39857.
I added the comment with much more details to the bug page,
the short version is below.

The following script and code demonstrates the issue:

aliasto__text = __text;
 SECTIONS {
  .text 0x1000 : { __text = . ; *(.text) }
 }
...
call aliasto__text

LLD fails with "cannot refer to absolute symbol: aliasto__text" error.
It happens because at the moment of scanning the relocations
we do not yet assign the correct/final/any section value for the symbol aliasto__text.
I made a change to Relocations.cpp to fix that.

Also, I had to remove the symbol-location.s test case completely, because now it does not
trigger any error. Since now all linker scripts symbols are resolved to constants, no
errors can be triggered at all it seems. I checked that it is consistent with the behavior
of bfd and gold (they do not trigger errors for the case from symbol-location.s), so it should
be OK. I.e. at least it is probably not the best possible, but natural behavior we obtained.

Differential revision: https://reviews.llvm.org/D55423

llvm-svn: 358652
lld/ELF/Relocations.cpp
lld/test/ELF/linkerscript/symbol-alias-relocation.s [new file with mode: 0644]
lld/test/ELF/linkerscript/symbol-location.s [deleted file]