Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 8a60ae5

Browse files
author
George Rimar
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@324461 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4b3915e commit 8a60ae5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

ELF/LinkerScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ uint64_t ExprValue::getSectionOffset() const {
7474
// If the alignment is trivial, we don't have to compute the full
7575
// value to know the offset. This allows this function to succeed in
7676
// cases where the output section is not yet known.
77-
if (Alignment == 1)
77+
if (Alignment == 1 && (!Sec || !Sec->getOutputSection()))
7878
return Val;
7979
return getValue() - getSecAddr();
8080
}

test/ELF/defsym-reserved-syms.s

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3+
# RUN: ld.lld -o %t %t.o --defsym=foo2=etext
4+
# RUN: llvm-readobj -t -s %t | FileCheck %s
5+
6+
## Check 'foo2' value is equal to value of 'etext'.
7+
# CHECK: Symbol {
8+
# CHECK: Name: foo2
9+
# CHECK-NEXT: Value: 0x[[VAL:.*]]
10+
# CHECK: Symbol {
11+
# CHECK: Name: etext
12+
# CHECK-NEXT: Value: 0x[[VAL]]
13+
14+
## Check 'foo2' value set correctly when using
15+
## reserved symbol 'etext' in expression.
16+
# RUN: ld.lld -o %t %t.o --defsym=foo2=etext+2
17+
# RUN: llvm-readobj -t -s %t | FileCheck %s --check-prefix=EXPR
18+
# EXPR: Symbol {
19+
# EXPR: Name: foo2
20+
# EXPR-NEXT: Value: 0x201007
21+
# EXPR: Symbol {
22+
# EXPR: Name: etext
23+
# EXPR-NEXT: Value: 0x201005
24+
25+
.globl foo1
26+
foo1 = 0x123
27+
28+
.global _start
29+
_start:
30+
movl $foo2, %edx

0 commit comments

Comments
 (0)