[lld] r324461 - [ELF] - Make defsym to work correctly with reserved symbols.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 01:00:34 PST 2018
Author: grimar
Date: Wed Feb 7 01:00:34 2018
New Revision: 324461
URL: http://llvm.org/viewvc/llvm-project?rev=324461&view=rev
Log:
[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
Added:
lld/trunk/test/ELF/defsym-reserved-syms.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=324461&r1=324460&r2=324461&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Feb 7 01:00:34 2018
@@ -74,7 +74,7 @@ uint64_t ExprValue::getSectionOffset() c
// 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();
}
Added: lld/trunk/test/ELF/defsym-reserved-syms.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/defsym-reserved-syms.s?rev=324461&view=auto
==============================================================================
--- lld/trunk/test/ELF/defsym-reserved-syms.s (added)
+++ lld/trunk/test/ELF/defsym-reserved-syms.s Wed Feb 7 01:00:34 2018
@@ -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
More information about the llvm-commits
mailing list