[PATCH] D42911: [ELF] - Make defsym to work correctly with reserved symbols.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 6 11:04:54 PST 2018
LGTM
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar updated this revision to Diff 132949.
> grimar added a comment.
>
> - Updated.
>
>
> https://reviews.llvm.org/D42911
>
> Files:
> ELF/LinkerScript.cpp
> test/ELF/defsym-reserved-syms.s
>
>
> Index: test/ELF/defsym-reserved-syms.s
> ===================================================================
> --- test/ELF/defsym-reserved-syms.s
> +++ 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
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -74,7 +74,7 @@
> // 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();
> }
>
>
> Index: test/ELF/defsym-reserved-syms.s
> ===================================================================
> --- test/ELF/defsym-reserved-syms.s
> +++ 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
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -74,7 +74,7 @@
> // 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();
> }
More information about the llvm-commits
mailing list