diff options
| author | George Rimar <grimar@accesssoftek.com> | 2019-04-18 10:00:37 +0000 |
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2019-04-18 10:00:37 +0000 |
| commit | 69186f82f3f557423618d7e5ffeb3355e89ce73a (patch) | |
| tree | dab4a2823d5eb269b3e19c0d9a7cc60054753887 | |
| parent | 8f87e53462a652921acd0c36c3fc96427ee44932 (diff) | |
| download | bcm5719-llvm-69186f82f3f557423618d7e5ffeb3355e89ce73a.tar.gz bcm5719-llvm-69186f82f3f557423618d7e5ffeb3355e89ce73a.zip | |
[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
| -rw-r--r-- | lld/ELF/Relocations.cpp | 5 | ||||
| -rw-r--r-- | lld/test/ELF/linkerscript/symbol-alias-relocation.s | 36 | ||||
| -rw-r--r-- | lld/test/ELF/linkerscript/symbol-location.s | 15 |
3 files changed, 41 insertions, 15 deletions
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index ac62666e461..14d3c1d2f35 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -421,6 +421,11 @@ static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym, if (E == R_SIZE) return true; + // We set the final symbols values for linker script defined symbols later. + // They always can be computed as a link time constant. + if (Sym.ScriptDefined) + return true; + // For the target and the relocation, we want to know if they are // absolute or relative. bool AbsVal = isAbsoluteValue(Sym); diff --git a/lld/test/ELF/linkerscript/symbol-alias-relocation.s b/lld/test/ELF/linkerscript/symbol-alias-relocation.s new file mode 100644 index 00000000000..6fa258c589d --- /dev/null +++ b/lld/test/ELF/linkerscript/symbol-alias-relocation.s @@ -0,0 +1,36 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "aliasto__text = __text; SECTIONS { .text 0x1000 : { __text = . ; *(.text) } }" > %t.script +# RUN: ld.lld -pie -o %t --script %t.script %t.o +# RUN: llvm-readobj -symbols %t | FileCheck %s + +## Check that alias 'aliasto__text' has the correct value. +## (It should belong to the section .text and point to it's start). + +# CHECK: Symbol { +# CHECK: Name: __text +# CHECK-NEXT: Value: 0x1000 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } + +# CHECK: Symbol { +# CHECK: Name: aliasto__text +# CHECK-NEXT: Value: 0x1000 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } + +.text +.globl _start +.type _start, %function +_start: +.globl aliasto__text + call __text + call aliasto__text diff --git a/lld/test/ELF/linkerscript/symbol-location.s b/lld/test/ELF/linkerscript/symbol-location.s deleted file mode 100644 index 323d237e153..00000000000 --- a/lld/test/ELF/linkerscript/symbol-location.s +++ /dev/null @@ -1,15 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "foo = 1;" > %t.script -# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | FileCheck %s - -## Here we check that symbol 'foo' location is reported properly. - -# CHECK: error: relocation R_X86_64_PLT32 cannot refer to absolute symbol: foo -# CHECK: >>> defined in {{.*}}.script:1 -# CHECK: >>> referenced by {{.*}}.o:(.text+0x1) - -.text -.globl _start -_start: - call foo@PLT |

