aboutsummaryrefslogtreecommitdiff
path: root/test/ELF/linkerscript
diff options
context:
space:
mode:
Diffstat (limited to 'test/ELF/linkerscript')
-rw-r--r--test/ELF/linkerscript/Inputs/at6.s11
-rw-r--r--test/ELF/linkerscript/Inputs/at7.s7
-rw-r--r--test/ELF/linkerscript/Inputs/at8.s8
-rw-r--r--test/ELF/linkerscript/align-r.test2
-rw-r--r--test/ELF/linkerscript/align4.test1
-rw-r--r--test/ELF/linkerscript/at6.test30
-rw-r--r--test/ELF/linkerscript/at7.test28
-rw-r--r--test/ELF/linkerscript/at8.test31
-rw-r--r--test/ELF/linkerscript/discard-section-err.s20
-rw-r--r--test/ELF/linkerscript/filename-spec.s1
-rw-r--r--test/ELF/linkerscript/icf.s11
-rw-r--r--test/ELF/linkerscript/info-section-type.s9
-rw-r--r--test/ELF/linkerscript/lazy-symbols.test1
-rw-r--r--test/ELF/linkerscript/map-file.test8
-rw-r--r--test/ELF/linkerscript/map-file2.test22
-rw-r--r--test/ELF/linkerscript/memory-include.test23
-rw-r--r--test/ELF/linkerscript/merge-nonalloc.s14
-rw-r--r--test/ELF/linkerscript/no-filename-spec.s17
-rw-r--r--test/ELF/linkerscript/non-alloc-segment.s2
-rw-r--r--test/ELF/linkerscript/non-alloc.s2
-rw-r--r--test/ELF/linkerscript/orphan-discard.s2
-rw-r--r--test/ELF/linkerscript/orphan-phdrs.s2
-rw-r--r--test/ELF/linkerscript/ouputformat.s9
-rw-r--r--test/ELF/linkerscript/output-section-include.test30
-rw-r--r--test/ELF/linkerscript/output-too-large.s6
-rw-r--r--test/ELF/linkerscript/phdrs.s8
-rw-r--r--test/ELF/linkerscript/provide-shared2.s2
-rw-r--r--test/ELF/linkerscript/relocatable-discard.s21
-rw-r--r--test/ELF/linkerscript/section-include.test32
-rw-r--r--test/ELF/linkerscript/sections-va-overflow.test4
-rw-r--r--test/ELF/linkerscript/segment-none.s4
-rw-r--r--test/ELF/linkerscript/sizeof.s1
-rw-r--r--test/ELF/linkerscript/sizeofheaders.s1
-rw-r--r--test/ELF/linkerscript/sort-init.s6
-rw-r--r--test/ELF/linkerscript/sort-non-script.s2
-rw-r--r--test/ELF/linkerscript/symbol-assignexpr.s1
-rw-r--r--test/ELF/linkerscript/symbol-location.s15
-rw-r--r--test/ELF/linkerscript/symbol-memoryexpr.s1
-rw-r--r--test/ELF/linkerscript/target.s18
-rw-r--r--test/ELF/linkerscript/unused-synthetic.s2
-rw-r--r--test/ELF/linkerscript/version-script.s6
41 files changed, 362 insertions, 59 deletions
diff --git a/test/ELF/linkerscript/Inputs/at6.s b/test/ELF/linkerscript/Inputs/at6.s
new file mode 100644
index 000000000000..2d22d4d342dd
--- /dev/null
+++ b/test/ELF/linkerscript/Inputs/at6.s
@@ -0,0 +1,11 @@
+.global _start
+.text
+_start:
+nop
+
+.section .sec1,"aw",@progbits
+.long 1
+
+.section .sec2,"aw",@progbits
+.long 2
+
diff --git a/test/ELF/linkerscript/Inputs/at7.s b/test/ELF/linkerscript/Inputs/at7.s
new file mode 100644
index 000000000000..29d29635963b
--- /dev/null
+++ b/test/ELF/linkerscript/Inputs/at7.s
@@ -0,0 +1,7 @@
+.global _start
+.text
+_start:
+nop
+
+.section .sec, "aw"
+.word 4
diff --git a/test/ELF/linkerscript/Inputs/at8.s b/test/ELF/linkerscript/Inputs/at8.s
new file mode 100644
index 000000000000..e15e4cd3b77f
--- /dev/null
+++ b/test/ELF/linkerscript/Inputs/at8.s
@@ -0,0 +1,8 @@
+.section .sec1,"aw",@progbits
+.quad 1
+
+.section .sec2,"aw",@progbits
+.quad 2
+
+.section .sec3,"aw",@progbits
+.quad 3
diff --git a/test/ELF/linkerscript/align-r.test b/test/ELF/linkerscript/align-r.test
index 684ac1e92328..5bde8950974f 100644
--- a/test/ELF/linkerscript/align-r.test
+++ b/test/ELF/linkerscript/align-r.test
@@ -4,7 +4,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t1.o
# RUN: ld.lld -r -o %t2.o --script %s %t1.o
-# RUN: llvm-readelf -s %t2.o | FileCheck %s
+# RUN: llvm-readelf -S %t2.o | FileCheck %s
# CHECK: Section Headers:
# CHECK-NEXT: Name Type Address Off Size ES Flg Lk Inf Al
diff --git a/test/ELF/linkerscript/align4.test b/test/ELF/linkerscript/align4.test
index 9440d60f6385..834e843da82b 100644
--- a/test/ELF/linkerscript/align4.test
+++ b/test/ELF/linkerscript/align4.test
@@ -4,7 +4,6 @@
# RUN: llvm-objdump -t %t | FileCheck %s
# CHECK-LABEL: SYMBOL TABLE:
-# CHECK-NEXT: 0000000000000000 *UND* 00000000
# CHECK-NEXT: 0000000000014008 .text 00000000 _start
# CHECK-NEXT: 0000000000010000 *ABS* 00000000 __code_base__
# CHECK-NEXT: 0000000000001000 *ABS* 00000000 VAR
diff --git a/test/ELF/linkerscript/at6.test b/test/ELF/linkerscript/at6.test
new file mode 100644
index 000000000000..498c0ef14f34
--- /dev/null
+++ b/test/ELF/linkerscript/at6.test
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/at6.s -o %t.o
+# RUN: ld.lld %t.o --script %s -o %t
+# RUN: llvm-readelf -sections -program-headers %t | FileCheck %s
+
+MEMORY {
+ FLASH : ORIGIN = 0x08000000, LENGTH = 0x100
+ RAM : ORIGIN = 0x20000000, LENGTH = 0x200
+}
+
+SECTIONS {
+ .text : { *(.text) } > FLASH
+ .sec1 : { *(.sec1) } > RAM
+ .sec2 : { *(.sec2) } > RAM AT > FLASH
+}
+
+# Make sure we create a separate PT_LOAD entry for .sec2. Previously,
+# it was added to the PT_LOAD entry of .sec1
+
+# CHECK: Name Type Address Off
+# CHECK: .text PROGBITS 0000000008000000 001000
+# CHECK: .sec1 PROGBITS 0000000020000000 002000
+# CHECK: .sec2 PROGBITS 0000000020000004 002004
+
+# CHECK: Program Headers:
+# CHECK: Type Offset VirtAddr PhysAddr
+# CHECK-NEXT: LOAD 0x001000 0x0000000008000000 0x0000000008000000
+# CHECK-NEXT: LOAD 0x002000 0x0000000020000000 0x0000000020000000
+# CHECK-NEXT: LOAD 0x002004 0x0000000020000004 0x0000000008000001
+# CHECK-NOT: LOAD
diff --git a/test/ELF/linkerscript/at7.test b/test/ELF/linkerscript/at7.test
new file mode 100644
index 000000000000..1f67df29fdcd
--- /dev/null
+++ b/test/ELF/linkerscript/at7.test
@@ -0,0 +1,28 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/at7.s -o %t.o
+# RUN: ld.lld %t.o --script %s -o %t
+# RUN: llvm-readelf -sections -program-headers %t | FileCheck %s
+
+MEMORY {
+ RAM : ORIGIN = 0x20000000, LENGTH = 0x200
+}
+
+SECTIONS {
+ .text : { *(.text) } > RAM AT> RAM
+ .sec : { *(.sec) } > RAM
+}
+
+# Make sure the memory for the .text section is only reserved once.
+# Previously, the location counter for both MemRegion and LMARegion
+# was increased unconditionally.
+
+
+# CHECK: Name Type Address Off
+# CHECK: .text PROGBITS 0000000020000000 001000
+# CHECK: .sec PROGBITS 0000000020000001 001001
+
+# CHECK: Program Headers:
+# CHECK: Type Offset VirtAddr PhysAddr
+# CHECK-NEXT: LOAD 0x001000 0x0000000020000000 0x0000000020000000
+# CHECK-NEXT: LOAD 0x001001 0x0000000020000001 0x0000000020000001
+# CHECK-NOT: LOAD
diff --git a/test/ELF/linkerscript/at8.test b/test/ELF/linkerscript/at8.test
new file mode 100644
index 000000000000..48c0d4581422
--- /dev/null
+++ b/test/ELF/linkerscript/at8.test
@@ -0,0 +1,31 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/at8.s -o %t.o
+# RUN: ld.lld %t.o --script %s -o %t
+# RUN: llvm-readelf -sections -program-headers %t | FileCheck %s
+
+MEMORY {
+ FLASH : ORIGIN = 0x08000000, LENGTH = 0x100
+ RAM : ORIGIN = 0x20000000, LENGTH = 0x200
+}
+
+SECTIONS {
+ .text : { *(.text) } > FLASH
+ .sec1 : { *(.sec1) } > RAM AT > FLASH
+ .sec2 : { *(.sec2) } > RAM
+ .sec3 : { *(.sec3) } > RAM AT > FLASH
+}
+
+# Make sure we do not issue a load-address overlap error
+# Previously, .sec3 would overwrite the LMAOffset in the
+# PT_LOAD header.
+
+# CHECK: Name Type Address Off
+# CHECK: .text PROGBITS 0000000008000000 001000
+# CHECK: .sec1 PROGBITS 0000000020000000 001000
+# CHECK: .sec2 PROGBITS 0000000020000008 001008
+# CHECK: .sec3 PROGBITS 0000000020000010 001010
+
+# CHECK: Program Headers:
+# CHECK: Type Offset VirtAddr PhysAddr
+# CHECK-NEXT: LOAD 0x001000 0x0000000020000000 0x0000000008000000
+# CHECK-NOT: LOAD
diff --git a/test/ELF/linkerscript/discard-section-err.s b/test/ELF/linkerscript/discard-section-err.s
index f1d3b96691ba..bb77dbb087da 100644
--- a/test/ELF/linkerscript/discard-section-err.s
+++ b/test/ELF/linkerscript/discard-section-err.s
@@ -7,25 +7,17 @@
# RUN: FileCheck -check-prefix=SHSTRTAB %s
# SHSTRTAB: discarding .shstrtab section is not allowed
+## We allow discarding .dynamic, check we don't crash.
# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynamic) } }" > %t.script
-# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
-# RUN: FileCheck -check-prefix=DYNAMIC %s
-# DYNAMIC: discarding .dynamic section is not allowed
+# RUN: ld.lld -pie -o %t --script %t.script %t.o
+## We allow discarding .dynsym, check we don't crash.
# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynsym) } }" > %t.script
-# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
-# RUN: FileCheck -check-prefix=DYNSYM %s
-# DYNSYM: discarding .dynsym section is not allowed
+# RUN: ld.lld -pie -o %t --script %t.script %t.o
+## We allow discarding .dynstr, check we don't crash.
# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynstr) } }" > %t.script
-# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
-# RUN: FileCheck -check-prefix=DYNSTR %s
-# DYNSTR: discarding .dynstr section is not allowed
-
-# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.plt) } }" > %t.script
-# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
-# RUN: FileCheck -check-prefix=RELAPLT %s
-# RELAPLT: discarding .rela.plt section is not allowed
+# RUN: ld.lld -pie -o %t --script %t.script %t.o
# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.dyn) } }" > %t.script
# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
diff --git a/test/ELF/linkerscript/filename-spec.s b/test/ELF/linkerscript/filename-spec.s
index 66fd4178387c..8a1f6605e2a9 100644
--- a/test/ELF/linkerscript/filename-spec.s
+++ b/test/ELF/linkerscript/filename-spec.s
@@ -43,6 +43,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.testdir1/filename-spec1.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
# RUN: %p/Inputs/filename-spec.s -o %t.testdir2/filename-spec2.o
+# RUN: rm -f %t.testdir1/lib1.a %t.testdir2/lib2.a
# RUN: llvm-ar rsc %t.testdir1/lib1.a %t.testdir1/filename-spec1.o
# RUN: llvm-ar rsc %t.testdir2/lib2.a %t.testdir2/filename-spec2.o
diff --git a/test/ELF/linkerscript/icf.s b/test/ELF/linkerscript/icf.s
new file mode 100644
index 000000000000..7c74458232aa
--- /dev/null
+++ b/test/ELF/linkerscript/icf.s
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+
+# RUN: echo "foo = 1; bar = 2;" > %t.script
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o %t.script -o %t --icf=all --print-icf-sections | count 0
+
+.section .text.foo,"ax",@progbits
+jmp foo
+
+.section .text.bar,"ax",@progbits
+jmp bar
diff --git a/test/ELF/linkerscript/info-section-type.s b/test/ELF/linkerscript/info-section-type.s
index b718e828ab7d..16e663fc5d0f 100644
--- a/test/ELF/linkerscript/info-section-type.s
+++ b/test/ELF/linkerscript/info-section-type.s
@@ -29,5 +29,14 @@
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
+# RUN: echo "SECTIONS { .bar 0x20000 (INFO) : { *(.foo) } };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
+
+# RUN: echo "SECTIONS { .bar 0x20000 (BAR) : { *(.foo) } };" > %t.script
+# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 |\
+# RUN: FileCheck %s --check-prefix=UNKNOWN
+# UNKNOWN: unknown section directive: BAR
+
.section .foo,"a",@progbits
.zero 1
diff --git a/test/ELF/linkerscript/lazy-symbols.test b/test/ELF/linkerscript/lazy-symbols.test
index 579df9323865..f409b839c4dd 100644
--- a/test/ELF/linkerscript/lazy-symbols.test
+++ b/test/ELF/linkerscript/lazy-symbols.test
@@ -1,5 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/lazy-symbols.s -o %t1
+# RUN: rm -f %tar
# RUN: llvm-ar rcs %tar %t1
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t2
# RUN: ld.lld %t2 %tar --script %s -o %tout
diff --git a/test/ELF/linkerscript/map-file.test b/test/ELF/linkerscript/map-file.test
index 540b8d494887..6ec8bafc42b1 100644
--- a/test/ELF/linkerscript/map-file.test
+++ b/test/ELF/linkerscript/map-file.test
@@ -44,10 +44,10 @@ SECTIONS {
# CHECK-NEXT: 2017 2017 246 1 . += 0x123 * ( 1 + 1 )
# CHECK-NEXT: 225d 225d 0 1 foo = .
# CHECK-NEXT: 225d 225d 0 1 bar = 0x42 - 0x26
-# CHECK-NEXT: 225d 0 0 1 sym1 = .
-# CHECK-NEXT: 225d 0 500 1 . += 0x500
-# CHECK-NEXT: 275d 0 0 1 sym2 = .
-# CHECK-NEXT: 275d 0 0 1 PROVIDE ( sym3 = 42 )
+# CHECK-NEXT: 225d 225d 0 1 sym1 = .
+# CHECK-NEXT: 225d 225d 500 1 . += 0x500
+# CHECK-NEXT: 275d 275d 0 1 sym2 = .
+# CHECK-NEXT: 275d 275d 0 1 PROVIDE ( sym3 = 42 )
# CHECK-NEXT: 2760 2760 10 4 .text
# CHECK-NEXT: 2760 2760 10 4 {{.*}}{{/|\\}}map-file.test.tmp.o:(.text)
# CHECK-NEXT: 0 0 8 1 .comment
diff --git a/test/ELF/linkerscript/map-file2.test b/test/ELF/linkerscript/map-file2.test
index d9ed339e228d..535043282249 100644
--- a/test/ELF/linkerscript/map-file2.test
+++ b/test/ELF/linkerscript/map-file2.test
@@ -8,6 +8,7 @@ SECTIONS {
.aaa : { *(.aaa.*) }
.bbb : AT(0x2000) { *(.bbb.*) }
.ccc : AT(0x3000) { *(.ccc.*) }
+ . += 0x100;
.ddd : {
BYTE(0x11)
. += 0x100;
@@ -24,16 +25,17 @@ SECTIONS {
# CHECK-NEXT: 1008 2000 8 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.bbb)
# CHECK-NEXT: 1010 3000 8 1 .ccc
# CHECK-NEXT: 1010 3000 8 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.ccc)
-# CHECK-NEXT: 1018 3008 109 1 .ddd
-# CHECK-NEXT: 1018 3008 1 1 BYTE ( 0x11 )
-# CHECK-NEXT: 1019 3009 100 1 . += 0x100
-# CHECK-NEXT: 1119 3109 8 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.ddd)
-# CHECK-NEXT: 1128 3118 34 8 .eh_frame
-# CHECK-NEXT: 1128 3118 30 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.eh_frame+0x0)
-# CHECK-NEXT: 115c 314c 1 4 .text
-# CHECK-NEXT: 115c 314c 1 4 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.text)
-# CHECK-NEXT: 115c 314c 0 1 f(int)
-# CHECK-NEXT: 115c 314c 0 1 _start
+# CHECK-NEXT: 1018 3008 100 1 . += 0x100
+# CHECK-NEXT: 1118 3108 109 1 .ddd
+# CHECK-NEXT: 1118 3108 1 1 BYTE ( 0x11 )
+# CHECK-NEXT: 1119 3109 100 1 . += 0x100
+# CHECK-NEXT: 1219 3209 8 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.ddd)
+# CHECK-NEXT: 1228 3218 34 8 .eh_frame
+# CHECK-NEXT: 1228 3218 30 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.eh_frame+0x0)
+# CHECK-NEXT: 125c 324c 1 4 .text
+# CHECK-NEXT: 125c 324c 1 4 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.text)
+# CHECK-NEXT: 125c 324c 0 1 f(int)
+# CHECK-NEXT: 125c 324c 0 1 _start
# CHECK-NEXT: 0 0 8 1 .comment
# CHECK-NEXT: 0 0 8 1 <internal>:(.comment)
# CHECK-NEXT: 0 0 48 8 .symtab
diff --git a/test/ELF/linkerscript/memory-include.test b/test/ELF/linkerscript/memory-include.test
new file mode 100644
index 000000000000..340328225bde
--- /dev/null
+++ b/test/ELF/linkerscript/memory-include.test
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+
+# RUN: echo '.section .text,"ax"; .global _start; nop' > %t.s
+# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+# RUN: echo "RAM2 (rwx): ORIGIN = 0x3000, LENGTH = 0x100" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s
+# CHECK: .data 00000008 0000000000002000 DATA
+# CHECK: .data2 00000008 0000000000003000 DATA
+
+MEMORY {
+ ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100
+ RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100
+ INCLUDE "memory-include.test.tmp.inc"
+}
+
+SECTIONS {
+ .text : { *(.text*) } > ROM
+ .data : { *(.data*) } > RAM
+ .data2 : { QUAD(0) } > RAM2
+}
diff --git a/test/ELF/linkerscript/merge-nonalloc.s b/test/ELF/linkerscript/merge-nonalloc.s
new file mode 100644
index 000000000000..7c48d3bc6cd0
--- /dev/null
+++ b/test/ELF/linkerscript/merge-nonalloc.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { .text : { *(.text) *(.nonalloc) } }" > %t.script
+# RUN: ld.lld -shared -o %t.exe %t.script %t.o
+# RUN: llvm-objdump -syms %t.exe | FileCheck %s
+
+# CHECK: .text 00000000 nonalloc_start
+
+_start:
+ nop
+
+.section .nonalloc,"",@progbits
+nonalloc_start:
+ .long 0xcafe
diff --git a/test/ELF/linkerscript/no-filename-spec.s b/test/ELF/linkerscript/no-filename-spec.s
new file mode 100644
index 000000000000..aec03958da7d
--- /dev/null
+++ b/test/ELF/linkerscript/no-filename-spec.s
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+# RUN: echo '.section .bar, "a"; .quad 1;' | \
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %tfile1.o
+# RUN: echo '.section .zed, "a"; .quad 2;' | \
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %tfile2.o
+
+## We have a file name and no input sections description. In that case, all
+## sections from the file specified should be included. Check that.
+# RUN: ld.lld -o %t --script %s %tfile1.o %tfile2.o
+# RUN: llvm-objdump -s %t | FileCheck %s
+
+# CHECK: Contents of section .foo:
+# CHECK-NEXT: 01000000 00000000 02000000 00000000
+
+SECTIONS {
+ .foo : { *file1.o *file2.o }
+}
diff --git a/test/ELF/linkerscript/non-alloc-segment.s b/test/ELF/linkerscript/non-alloc-segment.s
index d9984b3867d4..143cac1e2b12 100644
--- a/test/ELF/linkerscript/non-alloc-segment.s
+++ b/test/ELF/linkerscript/non-alloc-segment.s
@@ -16,7 +16,7 @@
# RUN: .foo : {*(.foo)} :foo \
# RUN: }" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
-# RUN: llvm-readelf -s -l %t | FileCheck %s
+# RUN: llvm-readelf -S -l %t | FileCheck %s
# RUN: llvm-readobj -l %t | FileCheck --check-prefix=PHDR %s
# CHECK: Program Headers:
diff --git a/test/ELF/linkerscript/non-alloc.s b/test/ELF/linkerscript/non-alloc.s
index 87f9afff8091..e6fb84d17d41 100644
--- a/test/ELF/linkerscript/non-alloc.s
+++ b/test/ELF/linkerscript/non-alloc.s
@@ -3,7 +3,7 @@
# RUN: echo "SECTIONS { .foo 0 : {*(foo)} }" > %t.script
# RUN: ld.lld --hash-style=sysv -o %t --script %t.script %t.o -shared
-# RUN: llvm-readelf -s -l %t | FileCheck %s
+# RUN: llvm-readelf -S -l %t | FileCheck %s
# Test that we create all necessary PT_LOAD. We use to stop at the first
# non-alloc, causing us to not create PT_LOAD for linker generated sections.
diff --git a/test/ELF/linkerscript/orphan-discard.s b/test/ELF/linkerscript/orphan-discard.s
index 6fd6fafcd7f4..4549c3bc2b9e 100644
--- a/test/ELF/linkerscript/orphan-discard.s
+++ b/test/ELF/linkerscript/orphan-discard.s
@@ -10,7 +10,7 @@
# RUN: /DISCARD/ : { *(.comment) } \
# RUN: }" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
-# RUN: llvm-readelf -s -symbols %t | FileCheck %s
+# RUN: llvm-readelf -S -symbols %t | FileCheck %s
# CHECK: .bss NOBITS ffffffff80002000 002008 000002 00 WA 0 0 4096
# CHECK: ffffffff80003000 0 NOTYPE GLOBAL DEFAULT 3 _end
diff --git a/test/ELF/linkerscript/orphan-phdrs.s b/test/ELF/linkerscript/orphan-phdrs.s
index f9d1467b532a..c889562d0fcc 100644
--- a/test/ELF/linkerscript/orphan-phdrs.s
+++ b/test/ELF/linkerscript/orphan-phdrs.s
@@ -10,7 +10,7 @@
# RUN: .rw : { *(.rw) } \
# RUN: }" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
-# RUN: llvm-readelf -s -l %t | FileCheck %s
+# RUN: llvm-readelf -S -l %t | FileCheck %s
## Check that the orphan section is placed correctly and belongs to
## the correct segment.
diff --git a/test/ELF/linkerscript/ouputformat.s b/test/ELF/linkerscript/ouputformat.s
deleted file mode 100644
index 7d4402a557a0..000000000000
--- a/test/ELF/linkerscript/ouputformat.s
+++ /dev/null
@@ -1,9 +0,0 @@
-# REQUIRES: x86
-# RUN: echo "OUTPUT_FORMAT(x, y, z)" > %t.script
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t1
-# RUN: ld.lld -shared -o %t2 %t1 %t.script
-# RUN: llvm-readobj %t2 > /dev/null
-
-# RUN: echo "OUTPUT_FORMAT(x, y)" > %t.script
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t1
-# RUN: not ld.lld -shared -o %t2 %t1 %t.script
diff --git a/test/ELF/linkerscript/output-section-include.test b/test/ELF/linkerscript/output-section-include.test
new file mode 100644
index 000000000000..b18a7ee037a3
--- /dev/null
+++ b/test/ELF/linkerscript/output-section-include.test
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+
+# RUN: echo '.section .text,"ax"; .global _start; nop' > %t.s
+# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+## Empty include file.
+# RUN: echo "" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK1
+# CHECK1: .data 00000008 0000000000002000 DATA
+
+## Non-empty include file.
+# RUN: echo "QUAD(0)" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK2
+# CHECK2: .data 00000010 0000000000002000 DATA
+
+MEMORY {
+ ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100
+ RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100
+}
+
+SECTIONS {
+ .text : { *(.text*) } > ROM
+ .data : {
+ *(.data*)
+ INCLUDE "output-section-include.test.tmp.inc"
+ } > RAM
+}
diff --git a/test/ELF/linkerscript/output-too-large.s b/test/ELF/linkerscript/output-too-large.s
index ca85465036fe..a5130d27a070 100644
--- a/test/ELF/linkerscript/output-too-large.s
+++ b/test/ELF/linkerscript/output-too-large.s
@@ -1,7 +1,13 @@
# REQUIRES: x86
+
# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
# RUN: echo "SECTIONS { .text : { . = 0xffffffff; *(.text*); } }" > %t.script
# RUN: not ld.lld --no-check-sections --script %t.script %t.o -o /dev/null 2>&1 | FileCheck %s
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { .text : { . = 0x8fffffffffffffff; *(.text*); } }" > %t.script
+# RUN: not ld.lld --no-check-sections --script %t.script %t.o -o /dev/null 2>&1 | FileCheck %s
+
# CHECK: error: output file too large
.global _start
diff --git a/test/ELF/linkerscript/phdrs.s b/test/ELF/linkerscript/phdrs.s
index b65015994533..c688bef5282c 100644
--- a/test/ELF/linkerscript/phdrs.s
+++ b/test/ELF/linkerscript/phdrs.s
@@ -130,6 +130,14 @@
# BADHDR: {{.*}}.script:1: section header 'bar' is not listed in PHDRS
+# RUN: echo "PHDRS { text PT_LOAD FOOHDR; }" > %t1.script
+# RUN: not ld.lld -o /dev/null --script %t1.script %t 2>&1 | FileCheck --check-prefix=FOOHDR %s
+# FOOHDR: error: {{.*}}.script:1: unexpected header attribute: FOOHDR
+
+# RUN: echo "PHDRS { text PT_FOO FOOHDR; }" > %t1.script
+# RUN: not ld.lld -o /dev/null --script %t1.script %t 2>&1 | FileCheck --check-prefix=PTFOO %s
+# PTFOO: invalid program header type: PT_FOO
+
.global _start
_start:
nop
diff --git a/test/ELF/linkerscript/provide-shared2.s b/test/ELF/linkerscript/provide-shared2.s
index 8a3200b6f545..1a7b213d8e54 100644
--- a/test/ELF/linkerscript/provide-shared2.s
+++ b/test/ELF/linkerscript/provide-shared2.s
@@ -6,7 +6,7 @@
# RUN: ld.lld -o %t --script %t.script %t.o %t2.so
# RUN: llvm-readelf --dyn-symbols %t | FileCheck %s
-# CHECK: 1 1: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS foo@
+# CHECK: 1 1: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS foo
.global _start
_start:
diff --git a/test/ELF/linkerscript/relocatable-discard.s b/test/ELF/linkerscript/relocatable-discard.s
new file mode 100644
index 000000000000..d4f5826b72d9
--- /dev/null
+++ b/test/ELF/linkerscript/relocatable-discard.s
@@ -0,0 +1,21 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.discard.*) }}" > %t.script
+# RUN: ld.lld -o %t --script %t.script -r %t.o
+# RUN: llvm-readobj -sections %t | FileCheck %s
+
+## Test shows that we do not crash after discarding the .discard.foo with -r.
+## Previously it happened because of 2 reasons:
+## 1) .rela.discard.foo was not handled properly and was not discarded.
+## Remaining reference was invalid and caused the crash.
+## 2) Third-party section .debug_info referencing discarded section
+## did not handle this case properly and tried to apply the
+## relocation instead of ignoring it.
+
+# CHECK-NOT: .discard
+
+.section .discard.foo,"ax"
+callq fn@PLT
+
+.section .debug_info,"",@progbits
+.long .discard.foo
diff --git a/test/ELF/linkerscript/section-include.test b/test/ELF/linkerscript/section-include.test
new file mode 100644
index 000000000000..9b6dfa0dcc4e
--- /dev/null
+++ b/test/ELF/linkerscript/section-include.test
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+
+# RUN: echo '.section .text,"ax"; .global _start; nop' > %t.s
+# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+## Empty include file.
+# RUN: echo "" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK1
+# CHECK1: .data 00000008 0000000000002000 DATA
+# CHECK1-NEXT: .data3 00000008 0000000000002008 DATA
+
+## Non-empty include file.
+# RUN: echo ".data2 : { QUAD(0) } > RAM" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK2
+# CHECK2: .data 00000008 0000000000002000 DATA
+# CHECK2-NEXT: .data2 00000008 0000000000002008 DATA
+# CHECK2-NEXT: .data3 00000008 0000000000002010 DATA
+
+MEMORY {
+ ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100
+ RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100
+}
+
+SECTIONS {
+ .text : { *(.text*) } > ROM
+ .data : { *(.data*) } > RAM
+ INCLUDE "section-include.test.tmp.inc"
+ .data3 : { QUAD(0) } > RAM
+}
diff --git a/test/ELF/linkerscript/sections-va-overflow.test b/test/ELF/linkerscript/sections-va-overflow.test
index 7ede6ecc3de8..142d2e5ef2d7 100644
--- a/test/ELF/linkerscript/sections-va-overflow.test
+++ b/test/ELF/linkerscript/sections-va-overflow.test
@@ -7,7 +7,7 @@ PHDRS {
ph_text PT_LOAD FILEHDR PHDRS FLAGS (0x1 | 0x4);
}
-SECTIONS {
+SECTIONS {
. = 0xffffffff20000000;
.text : { *(.text*) } : ph_text
.test 0x1000 : { BYTE(0) }
@@ -18,5 +18,5 @@ SECTIONS {
## with VA 0xffffffff20000000. That might be technically correct, but most probably
## is a result of a broken script file and causes file offset calculation overflow.
## It seems we do not have to support it, so we don't and we report an error in this case.
-# ERR: error: unable to place section .text at file offset [0xFFFFFFFF20000000, 0xFFFFFFFE40000000]; check your linker script for overflows
+# ERR: error: unable to place section .text at file offset [0xFFFFFFFF20000000, 0xFFFFFFFF20000000]; check your linker script for overflows
# ERR-NOT: unable to place section .bss
diff --git a/test/ELF/linkerscript/segment-none.s b/test/ELF/linkerscript/segment-none.s
index 06566525caf7..36d09e776478 100644
--- a/test/ELF/linkerscript/segment-none.s
+++ b/test/ELF/linkerscript/segment-none.s
@@ -9,7 +9,7 @@
# RUN: .foo : {*(.foo)} :NONE \
# RUN: }" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
-# RUN: llvm-readelf -s -l %t | FileCheck %s
+# RUN: llvm-readelf -S -l %t | FileCheck %s
## Test that section .foo is placed in segment NONE when assigned to segment
## NONE in the linker script and segment NONE is defined.
@@ -19,7 +19,7 @@
# RUN: .foo : {*(.foo)} :NONE \
# RUN: }" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
-# RUN: llvm-readelf -s -l %t | FileCheck --check-prefix=DEFINED %s
+# RUN: llvm-readelf -S -l %t | FileCheck --check-prefix=DEFINED %s
# CHECK: Section to Segment mapping:
# CHECK-NEXT: Segment Sections...
diff --git a/test/ELF/linkerscript/sizeof.s b/test/ELF/linkerscript/sizeof.s
index 4618f79d3db6..0d7106fc8956 100644
--- a/test/ELF/linkerscript/sizeof.s
+++ b/test/ELF/linkerscript/sizeof.s
@@ -18,7 +18,6 @@
# CHECK-NEXT: 2 .bbb 00000010
# CHECK-NEXT: 3 .ccc 00000018
# CHECK: SYMBOL TABLE:
-# CHECK-NEXT: 0000000000000000 *UND* 00000000
# CHECK-NEXT: .text 00000000 _start
# CHECK-NEXT: 0000000000000008 *ABS* 00000000 _aaa
# CHECK-NEXT: 0000000000000010 *ABS* 00000000 _bbb
diff --git a/test/ELF/linkerscript/sizeofheaders.s b/test/ELF/linkerscript/sizeofheaders.s
index 3cc70747280c..6a82442bc938 100644
--- a/test/ELF/linkerscript/sizeofheaders.s
+++ b/test/ELF/linkerscript/sizeofheaders.s
@@ -9,7 +9,6 @@
# RUN: llvm-objdump -t %t1 | FileCheck %s
#CHECK: SYMBOL TABLE:
-#CHECK-NEXT: 0000000000000000 *UND* 00000000
#CHECK-NEXT: 00000000000000e8 .text 00000000 _start
#CHECK-NEXT: 00000000000000e8 *ABS* 00000000 _size
diff --git a/test/ELF/linkerscript/sort-init.s b/test/ELF/linkerscript/sort-init.s
index 894b8ae882b7..dd030ace2efb 100644
--- a/test/ELF/linkerscript/sort-init.s
+++ b/test/ELF/linkerscript/sort-init.s
@@ -1,16 +1,18 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
-# RUN: echo "SECTIONS { .init_array : { *(SORT_BY_INIT_PRIORITY(.init_array.*)) } }" > %t1.script
+# RUN: echo "SECTIONS { .init_array : { *(SORT_BY_INIT_PRIORITY(.init_array.* foo*)) } }" > %t1.script
# RUN: ld.lld --script %t1.script %t1.o -o %t2
# RUN: llvm-objdump -s %t2 | FileCheck %s
# CHECK: Contents of section .init_array:
-# CHECK-NEXT: 03020000 00000000 010405
+# CHECK-NEXT: 03020000 00060000 010405
.globl _start
_start:
nop
+.section foo, "aw", @init_array
+ .byte 6
.section .init_array, "aw", @init_array
.align 8
.byte 1
diff --git a/test/ELF/linkerscript/sort-non-script.s b/test/ELF/linkerscript/sort-non-script.s
index 2477c835e134..7207e90d4d76 100644
--- a/test/ELF/linkerscript/sort-non-script.s
+++ b/test/ELF/linkerscript/sort-non-script.s
@@ -3,7 +3,7 @@
# RUN: echo "SECTIONS { foo : {*(foo)} }" > %t.script
# RUN: ld.lld --hash-style=sysv -o %t --script %t.script %t.o -shared
-# RUN: llvm-readelf -s %t | FileCheck %s
+# RUN: llvm-readelf -S %t | FileCheck %s
# CHECK: .dynsym {{.*}} A
# CHECK-NEXT: .hash {{.*}} A
diff --git a/test/ELF/linkerscript/symbol-assignexpr.s b/test/ELF/linkerscript/symbol-assignexpr.s
index 3be7d05931fe..56e0827caf11 100644
--- a/test/ELF/linkerscript/symbol-assignexpr.s
+++ b/test/ELF/linkerscript/symbol-assignexpr.s
@@ -25,7 +25,6 @@
# RUN: llvm-objdump -t %t1 | FileCheck %s
# CHECK: SYMBOL TABLE:
-# CHECK-NEXT: 0000000000000000 *UND* 00000000
# CHECK-NEXT: 0000000000000000 .text 00000000 _start
# CHECK-NEXT: 0000000000005678 *ABS* 00000000 bar
# CHECK-NEXT: 0000000000009abc *ABS* 00000000 baz
diff --git a/test/ELF/linkerscript/symbol-location.s b/test/ELF/linkerscript/symbol-location.s
new file mode 100644
index 000000000000..323d237e1533
--- /dev/null
+++ b/test/ELF/linkerscript/symbol-location.s
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "foo = 1;" > %t.script
+# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | FileCheck %s
+
+## Here we check that symbol 'foo' location is reported properly.
+
+# CHECK: error: relocation R_X86_64_PLT32 cannot refer to absolute symbol: foo
+# CHECK: >>> defined in {{.*}}.script:1
+# CHECK: >>> referenced by {{.*}}.o:(.text+0x1)
+
+.text
+.globl _start
+_start:
+ call foo@PLT
diff --git a/test/ELF/linkerscript/symbol-memoryexpr.s b/test/ELF/linkerscript/symbol-memoryexpr.s
index cdd821dc585a..9214ba83ea51 100644
--- a/test/ELF/linkerscript/symbol-memoryexpr.s
+++ b/test/ELF/linkerscript/symbol-memoryexpr.s
@@ -13,7 +13,6 @@
# RUN: llvm-objdump -t %t1 | FileCheck %s
# CHECK: SYMBOL TABLE:
-# CHECK-NEXT: 0000000000000000 *UND* 00000000
# CHECK-NEXT: 0000000000008000 .text 00000000 _start
# CHECK-NEXT: 0000000000008000 *ABS* 00000000 origin
# CHECK-NEXT: 0000000000040000 *ABS* 00000000 length
diff --git a/test/ELF/linkerscript/target.s b/test/ELF/linkerscript/target.s
new file mode 100644
index 000000000000..32db5b7866c2
--- /dev/null
+++ b/test/ELF/linkerscript/target.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "TARGET(binary) INPUT(\"%t.o\") TARGET(elf64-x86-64) INPUT(\"%t.o\")" > %t.script
+# RUN: ld.lld --script %t.script -o %t.exe
+# RUN: llvm-readelf -symbols %t.exe | FileCheck %s
+
+# CHECK: _binary_
+# CHECK: foobar
+
+# RUN: echo "TARGET(foo)" > %t2.script
+# RUN: not ld.lld --script %t2.script -o /dev/null 2>&1 | FileCheck -check-prefix=ERR %s
+
+# ERR: unknown target: foo
+
+.global foobar
+foobar:
+ nop
diff --git a/test/ELF/linkerscript/unused-synthetic.s b/test/ELF/linkerscript/unused-synthetic.s
index 6ddbf505ccbb..de494fa4975f 100644
--- a/test/ELF/linkerscript/unused-synthetic.s
+++ b/test/ELF/linkerscript/unused-synthetic.s
@@ -7,7 +7,7 @@
# RUN: }" > %t.script
# RUN: ld.lld -shared -o %t.so --script %t.script %t.o
-# RUN: llvm-readelf -s %t.so | FileCheck %s
+# RUN: llvm-readelf -S %t.so | FileCheck %s
# CHECK-NOT: .got
# CHECK-NOT: .plt
# CHECK: .dynsym
diff --git a/test/ELF/linkerscript/version-script.s b/test/ELF/linkerscript/version-script.s
index df666e1b39ea..67a0fd68ca7c 100644
--- a/test/ELF/linkerscript/version-script.s
+++ b/test/ELF/linkerscript/version-script.s
@@ -14,11 +14,11 @@
# CHECK: Symbols [
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Version: 0
-# CHECK-NEXT: Name: @
+# CHECK-NEXT: Name:
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Version: 0
-# CHECK-NEXT: Name: und@
+# CHECK-NEXT: Name: und
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Version: 2
@@ -41,7 +41,7 @@
# UNDEF: Symbols [
# UNDEF-NEXT: Symbol {
# UNDEF-NEXT: Version: 0
-# UNDEF-NEXT: Name: @
+# UNDEF-NEXT: Name:
# UNDEF-NEXT: }
# UNDEF-NEXT: Symbol {
# UNDEF-NEXT: Version: 2