[PATCH] D43887: Write some tests as linker scripts instead of assembly files.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 11:33:47 PST 2018
LGTM
Rui Ueyama via Phabricator <reviews at reviews.llvm.org> writes:
> ruiu created this revision.
> ruiu added reviewers: rafael, grimar.
> Herald added subscribers: arichardson, emaste.
>
> Some linker script test cases contain only a few lines of assembly
> and a long linker script. Such tests are easier to maintain if we
> write the main test file as a linkier script instead of assembly.
>
>
> https://reviews.llvm.org/D43887
>
> Files:
> lld/test/ELF/linkerscript/absolute-expr.s
> lld/test/ELF/linkerscript/absolute-expr.test
> lld/test/ELF/linkerscript/align-empty.s
> lld/test/ELF/linkerscript/align-empty.test
> lld/test/ELF/linkerscript/operators.s
> lld/test/ELF/linkerscript/operators.test
>
> Index: lld/test/ELF/linkerscript/operators.test
> ===================================================================
> --- lld/test/ELF/linkerscript/operators.test
> +++ lld/test/ELF/linkerscript/operators.test
> @@ -1,40 +1,41 @@
> # 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; \
> -# RUN: mod = 20 % 7; \
> -# RUN: mul = 1 + 2 * 3; \
> -# RUN: nospace = 1+2*6/3; \
> -# RUN: braces = 1 + (2 + 3) * 4; \
> -# RUN: and = 0xbb & 0xee; \
> -# RUN: ternary1 = 1 ? 1 : 2; \
> -# RUN: ternary2 = 0 ? 1 : 2; \
> -# RUN: less = 1 < 0 ? 1 : 2; \
> -# RUN: lesseq = 1 <= 1 ? 1 : 2; \
> -# RUN: greater = 0 > 1 ? 1 : 2; \
> -# RUN: greatereq = 1 >= 1 ? 1 : 2; \
> -# RUN: eq = 1 == 1 ? 1 : 2; \
> -# RUN: neq = 1 != 1 ? 1 : 2; \
> -# RUN: plusassign = 1; \
> -# RUN: plusassign += 2; \
> -# RUN: unary = -1 + 3; \
> -# RUN: lshift = 1 << 5; \
> -# RUN: rshift = 0xff >> 3; \
> -# RUN: maxpagesize = CONSTANT (MAXPAGESIZE); \
> -# RUN: commonpagesize = CONSTANT (COMMONPAGESIZE); \
> -# 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: echo ".globl _start;_start:" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t
> +# RUN: ld.lld %t --script %s -o %t2
> # RUN: llvm-objdump -t %t2 | FileCheck %s
>
> +SECTIONS {
> + _start = .;
> + plus = 1 + 2 + 3;
> + minus = 5 - 1;
> + div = 6 / 2;
> + mod = 20 % 7;
> + mul = 1 + 2 * 3;
> + nospace = 1+2*6/3;
> + braces = 1 + (2 + 3) * 4;
> + and = 0xbb & 0xee;
> + ternary1 = 1 ? 1 : 2;
> + ternary2 = 0 ? 1 : 2;
> + less = 1 < 0 ? 1 : 2;
> + lesseq = 1 <= 1 ? 1 : 2;
> + greater = 0 > 1 ? 1 : 2;
> + greatereq = 1 >= 1 ? 1 : 2;
> + eq = 1 == 1 ? 1 : 2;
> + neq = 1 != 1 ? 1 : 2;
> + plusassign = 1;
> + plusassign += 2;
> + unary = -1 + 3;
> + lshift = 1 << 5;
> + rshift = 0xff >> 3;
> + maxpagesize = CONSTANT (MAXPAGESIZE);
> + commonpagesize = CONSTANT (COMMONPAGESIZE);
> + . = 0xfff0;
> + datasegmentalign = DATA_SEGMENT_ALIGN (0xffff, 0);
> + datasegmentalign2 = DATA_SEGMENT_ALIGN (0, 0);
> + _end = .;
> + minus_rel = _end - 0x10;
> + minus_abs = _end - _start;
> +}
> +
> # CHECK: 00000000000006 *ABS* 00000000 plus
> # CHECK: 00000000000004 *ABS* 00000000 minus
> # CHECK: 00000000000003 *ABS* 00000000 div
> @@ -97,7 +98,3 @@
> # RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \
> # RUN: FileCheck --check-prefix=TERNERR %s
> # TERNERR: : expected, but got ;
> -
> -.globl _start
> -_start:
> -nop
> Index: lld/test/ELF/linkerscript/align-empty.test
> ===================================================================
> --- /dev/null
> +++ lld/test/ELF/linkerscript/align-empty.test
> @@ -0,0 +1,18 @@
> +# REQUIRES: x86
> +# RUN: echo '.section foo, "a"; .byte 0' \
> +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o
> +
> +# RUN: ld.lld -o %t1 --script %s %t.o -shared
> +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
> +
> +SECTIONS {
> + . = SIZEOF_HEADERS;
> + abc : { }
> + . = ALIGN(0x1000);
> + foo : { *(foo) }
> +}
> +
> +# CHECK: Sections:
> +# CHECK-NEXT: Idx Name Size Address
> +# CHECK-NEXT: 0 00000000 0000000000000000
> +# CHECK-NEXT: 1 foo 00000001 0000000000001000
> Index: lld/test/ELF/linkerscript/align-empty.s
> ===================================================================
> --- lld/test/ELF/linkerscript/align-empty.s
> +++ /dev/null
> @@ -1,18 +0,0 @@
> -# REQUIRES: x86
> -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> -
> -# RUN: echo "SECTIONS { \
> -# RUN: . = SIZEOF_HEADERS; \
> -# RUN: abc : { } \
> -# RUN: . = ALIGN(0x1000); \
> -# RUN: foo : { *(foo) } \
> -# RUN: }" > %t.script
> -# RUN: ld.lld -o %t1 --script %t.script %t -shared
> -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
> -# CHECK: Sections:
> -# CHECK-NEXT: Idx Name Size Address
> -# CHECK-NEXT: 0 00000000 0000000000000000
> -# CHECK-NEXT: 1 foo 00000001 0000000000001000
> -
> - .section foo, "a"
> - .byte 0
> Index: lld/test/ELF/linkerscript/absolute-expr.test
> ===================================================================
> --- lld/test/ELF/linkerscript/absolute-expr.test
> +++ lld/test/ELF/linkerscript/absolute-expr.test
> @@ -1,21 +1,19 @@
> # REQUIRES: x86
> -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
> -# RUN: echo "SECTIONS { \
> -# RUN: .text : { \
> -# RUN: bar1 = ALIGNOF(.text); \
> -# RUN: bar2 = CONSTANT (MAXPAGESIZE); \
> -# RUN: bar3 = SIZEOF (.text); \
> -# RUN: bar4 = SIZEOF_HEADERS; \
> -# RUN: bar5 = 0x42; \
> -# RUN: bar6 = foo + 1; \
> -# RUN: *(.text) \
> -# RUN: } \
> -# RUN: };" > %t.script
> -# RUN: ld.lld -o %t.so --script %t.script %t.o -shared
> +# RUN: echo ".global foo; foo = 0x123" | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o
> +# RUN: l.lld -o %t.so --script %s %t.o -shared
> # RUN: llvm-readobj -t %t.so | FileCheck %s
>
> -.global foo
> -foo = 0x123
> +SECTIONS {
> + .text : {
> + bar1 = ALIGNOF(.text);
> + bar2 = CONSTANT (MAXPAGESIZE);
> + bar3 = SIZEOF (.text);
> + bar4 = SIZEOF_HEADERS;
> + bar5 = 0x42;
> + bar6 = foo + 1;
> + *(.text)
> + }
> +}
>
> # CHECK: Symbol {
> # CHECK: Name: foo
More information about the llvm-commits
mailing list