summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2018-02-07 09:00:34 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2018-02-07 09:00:34 +0000
commit27ae7ae7740a89e24f9a670037c6a534884428e9 (patch)
tree04cc1be2421be8a201c826da247b68167ce590f8
parent9d9e9e1889419575b742a98c5c3da2de9b1baaac (diff)
downloadbcm5719-llvm-27ae7ae7740a89e24f9a670037c6a534884428e9.tar.gz
bcm5719-llvm-27ae7ae7740a89e24f9a670037c6a534884428e9.zip
[ELF] - Make defsym to work correctly with reserved symbols.
Previously --defsym=foo2=etext+2 would produce incorrect value for foo2 because expressions did not work correctly with reserved symbols, section offset was calculated wrong for them. Fixes PR35744. Differential revision: https://reviews.llvm.org/D42911 llvm-svn: 324461
-rw-r--r--lld/ELF/LinkerScript.cpp2
-rw-r--r--lld/test/ELF/defsym-reserved-syms.s30
2 files changed, 31 insertions, 1 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 24885e04fe1..309755e6197 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -74,7 +74,7 @@ uint64_t ExprValue::getSectionOffset() const {
// If the alignment is trivial, we don't have to compute the full
// value to know the offset. This allows this function to succeed in
// cases where the output section is not yet known.
- if (Alignment == 1)
+ if (Alignment == 1 && (!Sec || !Sec->getOutputSection()))
return Val;
return getValue() - getSecAddr();
}
diff --git a/lld/test/ELF/defsym-reserved-syms.s b/lld/test/ELF/defsym-reserved-syms.s
new file mode 100644
index 00000000000..fdab00fed66
--- /dev/null
+++ b/lld/test/ELF/defsym-reserved-syms.s
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -o %t %t.o --defsym=foo2=etext
+# RUN: llvm-readobj -t -s %t | FileCheck %s
+
+## Check 'foo2' value is equal to value of 'etext'.
+# CHECK: Symbol {
+# CHECK: Name: foo2
+# CHECK-NEXT: Value: 0x[[VAL:.*]]
+# CHECK: Symbol {
+# CHECK: Name: etext
+# CHECK-NEXT: Value: 0x[[VAL]]
+
+## Check 'foo2' value set correctly when using
+## reserved symbol 'etext' in expression.
+# RUN: ld.lld -o %t %t.o --defsym=foo2=etext+2
+# RUN: llvm-readobj -t -s %t | FileCheck %s --check-prefix=EXPR
+# EXPR: Symbol {
+# EXPR: Name: foo2
+# EXPR-NEXT: Value: 0x201007
+# EXPR: Symbol {
+# EXPR: Name: etext
+# EXPR-NEXT: Value: 0x201005
+
+.globl foo1
+ foo1 = 0x123
+
+.global _start
+_start:
+ movl $foo2, %edx
OpenPOWER on IntegriCloud