Index: test/ELF/linkerscript/absolute-expr.s =================================================================== --- test/ELF/linkerscript/absolute-expr.s +++ test/ELF/linkerscript/absolute-expr.s @@ -1,82 +0,0 @@ -# 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: llvm-readobj -t %t.so | FileCheck %s - -.global foo -foo = 0x123 - -# CHECK: Symbol { -# CHECK: Name: foo -# CHECK-NEXT: Value: 0x123 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute (0xFFF1) -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: bar1 -# CHECK-NEXT: Value: 0x4 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: bar2 -# CHECK-NEXT: Value: 0x1000 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: bar3 -# CHECK-NEXT: Value: 0x0 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: bar4 -# CHECK-NEXT: Value: 0x190 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: bar5 -# CHECK-NEXT: Value: 0x42 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: bar6 -# CHECK-NEXT: Value: 0x124 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global (0x1) -# CHECK-NEXT: Type: None (0x0) -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute (0xFFF1) -# CHECK-NEXT: } Index: test/ELF/linkerscript/absolute-expr.test =================================================================== --- test/ELF/linkerscript/absolute-expr.test +++ test/ELF/linkerscript/absolute-expr.test @@ -0,0 +1,80 @@ +# REQUIRES: x86 +# 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 + +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 +# CHECK-NEXT: Value: 0x123 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute (0xFFF1) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar1 +# CHECK-NEXT: Value: 0x4 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar2 +# CHECK-NEXT: Value: 0x1000 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar3 +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar4 +# CHECK-NEXT: Value: 0x190 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar5 +# CHECK-NEXT: Value: 0x42 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar6 +# CHECK-NEXT: Value: 0x124 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute (0xFFF1) +# CHECK-NEXT: } Index: test/ELF/linkerscript/align-empty.s =================================================================== --- test/ELF/linkerscript/align-empty.s +++ test/ELF/linkerscript/align-empty.s @@ -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: test/ELF/linkerscript/align-empty.test =================================================================== --- test/ELF/linkerscript/align-empty.test +++ 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: test/ELF/linkerscript/discard-interp.s =================================================================== --- test/ELF/linkerscript/discard-interp.s +++ test/ELF/linkerscript/discard-interp.s @@ -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: Index: test/ELF/linkerscript/discard-interp.test =================================================================== --- test/ELF/linkerscript/discard-interp.test +++ test/ELF/linkerscript/discard-interp.test @@ -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 +} Index: test/ELF/linkerscript/operators.s =================================================================== --- test/ELF/linkerscript/operators.s +++ test/ELF/linkerscript/operators.s @@ -1,103 +0,0 @@ -# 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-objdump -t %t2 | FileCheck %s - -# CHECK: 00000000000006 *ABS* 00000000 plus -# CHECK: 00000000000004 *ABS* 00000000 minus -# CHECK: 00000000000003 *ABS* 00000000 div -# CHECK: 00000000000006 *ABS* 00000000 mod -# CHECK: 00000000000007 *ABS* 00000000 mul -# CHECK: 00000000000005 *ABS* 00000000 nospace -# CHECK: 00000000000015 *ABS* 00000000 braces -# CHECK: 000000000000aa *ABS* 00000000 and -# CHECK: 00000000000001 *ABS* 00000000 ternary1 -# CHECK: 00000000000002 *ABS* 00000000 ternary2 -# CHECK: 00000000000002 *ABS* 00000000 less -# CHECK: 00000000000001 *ABS* 00000000 lesseq -# CHECK: 00000000000002 *ABS* 00000000 greater -# CHECK: 00000000000001 *ABS* 00000000 greatereq -# CHECK: 00000000000001 *ABS* 00000000 eq -# CHECK: 00000000000002 *ABS* 00000000 neq -# CHECK: 00000000000003 *ABS* 00000000 plusassign -# CHECK: 00000000000002 *ABS* 00000000 unary -# CHECK: 00000000000020 *ABS* 00000000 lshift -# CHECK: 0000000000001f *ABS* 00000000 rshift -# CHECK: 00000000001000 *ABS* 00000000 maxpagesize -# 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 -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=NUMERR %s -# NUMERR: malformed number: 0x12Q41 - -## Missing closing bracket. -# RUN: echo "SECTIONS { . = (1; }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=BRACKETERR %s -# BRACKETERR: ) expected, but got ; - -## Missing opening bracket. -# RUN: echo "SECTIONS { . = 1); }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=BRACKETERR2 %s -# BRACKETERR2: ; expected, but got ) - -## Empty expression. -# RUN: echo "SECTIONS { . = ; }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=ERREXPR %s -# ERREXPR: malformed number: ; - -## Div by zero error. -# RUN: echo "SECTIONS { . = 1 / 0; }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=DIVZERO %s -# DIVZERO: division by zero - -## Broken ternary operator expression. -# RUN: echo "SECTIONS { . = 1 ? 2; }" > %t.script -# 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: test/ELF/linkerscript/operators.test =================================================================== --- test/ELF/linkerscript/operators.test +++ test/ELF/linkerscript/operators.test @@ -0,0 +1,100 @@ +# REQUIRES: x86 +# 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 +# CHECK: 00000000000006 *ABS* 00000000 mod +# CHECK: 00000000000007 *ABS* 00000000 mul +# CHECK: 00000000000005 *ABS* 00000000 nospace +# CHECK: 00000000000015 *ABS* 00000000 braces +# CHECK: 000000000000aa *ABS* 00000000 and +# CHECK: 00000000000001 *ABS* 00000000 ternary1 +# CHECK: 00000000000002 *ABS* 00000000 ternary2 +# CHECK: 00000000000002 *ABS* 00000000 less +# CHECK: 00000000000001 *ABS* 00000000 lesseq +# CHECK: 00000000000002 *ABS* 00000000 greater +# CHECK: 00000000000001 *ABS* 00000000 greatereq +# CHECK: 00000000000001 *ABS* 00000000 eq +# CHECK: 00000000000002 *ABS* 00000000 neq +# CHECK: 00000000000003 *ABS* 00000000 plusassign +# CHECK: 00000000000002 *ABS* 00000000 unary +# CHECK: 00000000000020 *ABS* 00000000 lshift +# CHECK: 0000000000001f *ABS* 00000000 rshift +# CHECK: 00000000001000 *ABS* 00000000 maxpagesize +# 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 +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=NUMERR %s +# NUMERR: malformed number: 0x12Q41 + +## Missing closing bracket. +# RUN: echo "SECTIONS { . = (1; }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=BRACKETERR %s +# BRACKETERR: ) expected, but got ; + +## Missing opening bracket. +# RUN: echo "SECTIONS { . = 1); }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=BRACKETERR2 %s +# BRACKETERR2: ; expected, but got ) + +## Empty expression. +# RUN: echo "SECTIONS { . = ; }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=ERREXPR %s +# ERREXPR: malformed number: ; + +## Div by zero error. +# RUN: echo "SECTIONS { . = 1 / 0; }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=DIVZERO %s +# DIVZERO: division by zero + +## Broken ternary operator expression. +# RUN: echo "SECTIONS { . = 1 ? 2; }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=TERNERR %s +# TERNERR: : expected, but got ;