[PATCH] D41477: [LLD] [ELF] Result of subtracting two symbols should be absolute

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 11:23:14 PST 2017


LGTM.

It is not clear that this will work in all cases when the symbols are in
different sections but is is an improvement.

Do you have commit access?

Cheers,
Rafael

Erick Reyes via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:

> erickreyes created this revision.
> erickreyes added a reviewer: lld.
> erickreyes added a project: lld.
> Herald added subscribers: llvm-commits, emaste.
>
> When two linker script symbols are subtracted, the result should be absolute.
>
> This is the behavior of binutils' ld.
>
>
> Repository:
>   rLLD LLVM Linker
>
> https://reviews.llvm.org/D41477
>
> Files:
>   ELF/ScriptParser.cpp
>   test/ELF/linkerscript/operators.s
>
>
> Index: test/ELF/linkerscript/operators.s
> ===================================================================
> --- test/ELF/linkerscript/operators.s
> +++ test/ELF/linkerscript/operators.s
> @@ -1,6 +1,7 @@
>  # REQUIRES: x86
>  # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
>  # RUN: echo "SECTIONS { \
> +# RUN:  _start = .; \
>  # RUN:  plus = 1 + 2 + 3; \
>  # RUN:  minus = 5 - 1; \
>  # RUN:  div = 6 / 2; \
> @@ -26,6 +27,9 @@
>  # RUN:  . = 0xfff0; \
>  # RUN:  datasegmentalign = DATA_SEGMENT_ALIGN (0xffff, 0); \
>  # RUN:  datasegmentalign2 = DATA_SEGMENT_ALIGN (0, 0); \
> +# RUN:  _end = .; \
> +# RUN:  minus_rel = _end - 0x10; \
> +# RUN:  minus_abs = _end - _start; \
>  # RUN: }" > %t.script
>  # RUN: ld.lld %t --script %t.script -o %t2
>  # RUN: llvm-objdump -t %t2 | FileCheck %s
> @@ -53,6 +57,8 @@
>  # CHECK: 00000000001000 *ABS* 00000000 commonpagesize
>  # CHECK: 0000000000ffff *ABS* 00000000 datasegmentalign
>  # CHECK: 0000000000fff0 *ABS* 00000000 datasegmentalign2
> +# CHECK: 0000000000ffe0 .text 00000000 minus_rel
> +# CHECK: 0000000000fff0 *ABS* 00000000 minus_abs
>  
>  ## Mailformed number error.
>  # RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script
> Index: ELF/ScriptParser.cpp
> ===================================================================
> --- ELF/ScriptParser.cpp
> +++ ELF/ScriptParser.cpp
> @@ -151,6 +151,8 @@
>  }
>  
>  static ExprValue sub(ExprValue A, ExprValue B) {
> +  if (!A.isAbsolute() && !B.isAbsolute())
> +    return A.getValue() - B.getValue();
>    return {A.Sec, false, A.getSectionOffset() - B.getValue(), A.Loc};
>  }
>  
>
>
> Index: test/ELF/linkerscript/operators.s
> ===================================================================
> --- test/ELF/linkerscript/operators.s
> +++ test/ELF/linkerscript/operators.s
> @@ -1,6 +1,7 @@
>  # REQUIRES: x86
>  # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
>  # RUN: echo "SECTIONS { \
> +# RUN:  _start = .; \
>  # RUN:  plus = 1 + 2 + 3; \
>  # RUN:  minus = 5 - 1; \
>  # RUN:  div = 6 / 2; \
> @@ -26,6 +27,9 @@
>  # RUN:  . = 0xfff0; \
>  # RUN:  datasegmentalign = DATA_SEGMENT_ALIGN (0xffff, 0); \
>  # RUN:  datasegmentalign2 = DATA_SEGMENT_ALIGN (0, 0); \
> +# RUN:  _end = .; \
> +# RUN:  minus_rel = _end - 0x10; \
> +# RUN:  minus_abs = _end - _start; \
>  # RUN: }" > %t.script
>  # RUN: ld.lld %t --script %t.script -o %t2
>  # RUN: llvm-objdump -t %t2 | FileCheck %s
> @@ -53,6 +57,8 @@
>  # CHECK: 00000000001000 *ABS* 00000000 commonpagesize
>  # CHECK: 0000000000ffff *ABS* 00000000 datasegmentalign
>  # CHECK: 0000000000fff0 *ABS* 00000000 datasegmentalign2
> +# CHECK: 0000000000ffe0 .text 00000000 minus_rel
> +# CHECK: 0000000000fff0 *ABS* 00000000 minus_abs
>  
>  ## Mailformed number error.
>  # RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script
> Index: ELF/ScriptParser.cpp
> ===================================================================
> --- ELF/ScriptParser.cpp
> +++ ELF/ScriptParser.cpp
> @@ -151,6 +151,8 @@
>  }
>  
>  static ExprValue sub(ExprValue A, ExprValue B) {
> +  if (!A.isAbsolute() && !B.isAbsolute())
> +    return A.getValue() - B.getValue();
>    return {A.Sec, false, A.getSectionOffset() - B.getValue(), A.Loc};
>  }
>  
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list