Write some tests as linker scripts instead of assembly files.

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.

Differential Revision: https://reviews.llvm.org/D43887

llvm-svn: 326363
This commit is contained in:
Rui Ueyama 2018-02-28 20:22:42 +00:00
parent f181f1a6a2
commit 2dfe49a441
6 changed files with 79 additions and 83 deletions

View File

@ -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: ld.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

View File

@ -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

View File

@ -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

View File

@ -1,12 +0,0 @@
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/../Inputs/shared.s -o %t2.o
// RUN: ld.lld -shared %t2.o -o %t2.so
// RUN: echo "PHDRS { text PT_LOAD FILEHDR PHDRS; } \
// RUN: SECTIONS { . = SIZEOF_HEADERS; .text : { *(.text) } : text }" > %t.script
// RUN: ld.lld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -rpath foo -rpath bar --script %t.script --export-dynamic %t.o %t2.so -o %t
// RUN: llvm-readobj -s %t | FileCheck %s
// CHECK-NOT: Name: .interp
.global _start
_start:

View File

@ -0,0 +1,13 @@
# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux /dev/null -o %t.o
# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/../Inputs/shared.s -o %t2.o
# RUN: ld.lld -shared %t2.o -o %t2.so
# RUN: ld.lld -dynamic-linker foo -rpath bar -rpath baz --script %s --export-dynamic %t.o %t2.so -o %t
# RUN: llvm-readobj -s %t | FileCheck %s
# CHECK-NOT: Name: .interp
PHDRS { text PT_LOAD FILEHDR PHDRS; }
SECTIONS {
. = SIZEOF_HEADERS;
.text : { *(.text) } : text
}

View File

@ -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: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -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