Index: lld/trunk/test/ELF/linkerscript/Inputs/addr.s =================================================================== --- lld/trunk/test/ELF/linkerscript/Inputs/addr.s +++ lld/trunk/test/ELF/linkerscript/Inputs/addr.s @@ -0,0 +1,12 @@ +.text +.globl _start +_start: + +.section .foo.1,"a" +.quad 1 + +.section .foo.2,"a" +.quad 2 + +.section .foo.3,"a" +.quad 3 Index: lld/trunk/test/ELF/linkerscript/Inputs/align.s =================================================================== --- lld/trunk/test/ELF/linkerscript/Inputs/align.s +++ lld/trunk/test/ELF/linkerscript/Inputs/align.s @@ -0,0 +1,13 @@ +.global _start +_start: + nop + +.section .aaa, "a" +.quad 0 + +.section .bbb, "a" +.quad 0 + +.section .ccc, "a" +.quad 0 + Index: lld/trunk/test/ELF/linkerscript/Inputs/alignof.s =================================================================== --- lld/trunk/test/ELF/linkerscript/Inputs/alignof.s +++ lld/trunk/test/ELF/linkerscript/Inputs/alignof.s @@ -0,0 +1,15 @@ +.global _start +_start: + nop + +.section .aaa,"a" + .align 8 + .quad 0 + +.section .bbb,"a" + .align 16 + .quad 0 + +.section .ccc,"a" + .align 32 + .quad 0 Index: lld/trunk/test/ELF/linkerscript/Inputs/at2.s =================================================================== --- lld/trunk/test/ELF/linkerscript/Inputs/at2.s +++ lld/trunk/test/ELF/linkerscript/Inputs/at2.s @@ -0,0 +1,14 @@ +.section .foo1, "ax" +.quad 0 + +.section .foo2, "ax" +.quad 0 + +.section .bar1, "aw" +.quad 0 + +.section .bar2, "aw" +.quad 0 + +.section .bar3, "aw" +.quad 0 Index: lld/trunk/test/ELF/linkerscript/Inputs/at3.s =================================================================== --- lld/trunk/test/ELF/linkerscript/Inputs/at3.s +++ lld/trunk/test/ELF/linkerscript/Inputs/at3.s @@ -0,0 +1,8 @@ +.section .foo1, "a" +.quad 0 + +.section .foo2, "ax" +.quad 0 + +.section .foo3, "ax" +.quad 0 Index: lld/trunk/test/ELF/linkerscript/Inputs/synthetic-symbols.s =================================================================== --- lld/trunk/test/ELF/linkerscript/Inputs/synthetic-symbols.s +++ lld/trunk/test/ELF/linkerscript/Inputs/synthetic-symbols.s @@ -0,0 +1,16 @@ +.global _start +_start: + nop + +.section .foo,"a" + .quad 0 + +.section .bar,"a" + .long 0 + +.section .dah,"ax",@progbits + .cfi_startproc + nop + .cfi_endproc + +.global _begin_sec, _end_sec, _end_sec_abs Index: lld/trunk/test/ELF/linkerscript/addr-zero.s =================================================================== --- lld/trunk/test/ELF/linkerscript/addr-zero.s +++ lld/trunk/test/ELF/linkerscript/addr-zero.s @@ -1,18 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS { foo = ADDR(.text) - ABSOLUTE(ADDR(.text)); };" > %t.script -# RUN: ld.lld -o %t.so --script %t.script %t.o -shared -# RUN: llvm-readobj --symbols %t.so | FileCheck %s - -# Test that the script creates a non absolute symbol with value -# 0 I.E., a symbol that refers to the load address. - -# CHECK: Symbol { -# CHECK: Name: foo -# CHECK-NEXT: Value: 0x0 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: .text -# CHECK-NEXT: } Index: lld/trunk/test/ELF/linkerscript/addr-zero.test =================================================================== --- lld/trunk/test/ELF/linkerscript/addr-zero.test +++ lld/trunk/test/ELF/linkerscript/addr-zero.test @@ -0,0 +1,21 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: ld.lld -o %t.so --script %s %t.o -shared +# RUN: llvm-readobj --symbols %t.so | FileCheck %s + +# Test that the script creates a non absolute symbol with value +# 0 I.E., a symbol that refers to the load address. + +# CHECK: Symbol { +# CHECK: Name: foo +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } + +SECTIONS { + foo = ADDR(.text) - ABSOLUTE(ADDR(.text)); +}; Index: lld/trunk/test/ELF/linkerscript/addr.s =================================================================== --- lld/trunk/test/ELF/linkerscript/addr.s +++ lld/trunk/test/ELF/linkerscript/addr.s @@ -1,32 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS { \ -# RUN: . = 0x1000; \ -# RUN: .text : { *(.text*) } \ -# RUN: .foo.1 : { *(.foo.1) } \ -# RUN: .foo.2 ADDR(.foo.1) + 0x100 : { *(.foo.2) } \ -# RUN: .foo.3 : { *(.foo.3) } \ -# RUN: }" > %t.script -# RUN: ld.lld %t --script %t.script -o %t1 -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s - -# CHECK: Sections: -# CHECK-NEXT: Idx Name Size Address Type -# CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .text 00000000 0000000000001000 TEXT DATA -# CHECK-NEXT: 2 .foo.1 00000008 0000000000001000 DATA -# CHECK-NEXT: 3 .foo.2 00000008 0000000000001100 DATA -# CHECK-NEXT: 4 .foo.3 00000008 0000000000001108 DATA - -.text -.globl _start -_start: - -.section .foo.1,"a" - .quad 1 - -.section .foo.2,"a" - .quad 2 - -.section .foo.3,"a" - .quad 3 Index: lld/trunk/test/ELF/linkerscript/addr.test =================================================================== --- lld/trunk/test/ELF/linkerscript/addr.test +++ lld/trunk/test/ELF/linkerscript/addr.test @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/addr.s -o %t +# RUN: ld.lld %t --script %s -o %t1 +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .text 00000000 0000000000001000 TEXT DATA +# CHECK-NEXT: 2 .foo.1 00000008 0000000000001000 DATA +# CHECK-NEXT: 3 .foo.2 00000008 0000000000001100 DATA +# CHECK-NEXT: 4 .foo.3 00000008 0000000000001108 DATA + +SECTIONS { + . = 0x1000; + .text : { *(.text*) } + .foo.1 : { *(.foo.1) } + .foo.2 ADDR(.foo.1) + 0x100 : { *(.foo.2) } + .foo.3 : { *(.foo.3) } +} Index: lld/trunk/test/ELF/linkerscript/align-section-offset.s =================================================================== --- lld/trunk/test/ELF/linkerscript/align-section-offset.s +++ lld/trunk/test/ELF/linkerscript/align-section-offset.s @@ -1,11 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { .foo : ALIGN(2M) { *(.foo) } }" > %t.script -# RUN: ld.lld -o %t --script %t.script %t.o -shared -# RUN: llvm-readelf -S -l %t | FileCheck %s - -# CHECK: .foo PROGBITS 0000000000200000 200000 000008 00 WA 0 0 2097152 -# CHECK: LOAD 0x200000 0x0000000000200000 0x0000000000200000 {{.*}} RW 0x200000 - - .section .foo, "aw" - .quad 42 Index: lld/trunk/test/ELF/linkerscript/align-section-offset.test =================================================================== --- lld/trunk/test/ELF/linkerscript/align-section-offset.test +++ lld/trunk/test/ELF/linkerscript/align-section-offset.test @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: echo '.section .foo, "aw"; .quad 42' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o +# RUN: ld.lld -o %t --script %s %t.o -shared +# RUN: llvm-readelf -S -l %t | FileCheck %s + +SECTIONS { + .foo : ALIGN(2M) { *(.foo) } +} + +# CHECK: .foo PROGBITS 0000000000200000 200000 000008 00 WA 0 0 2097152 +# CHECK: LOAD 0x200000 0x0000000000200000 0x0000000000200000 {{.*}} RW 0x200000 Index: lld/trunk/test/ELF/linkerscript/align-section.s =================================================================== --- lld/trunk/test/ELF/linkerscript/align-section.s +++ lld/trunk/test/ELF/linkerscript/align-section.s @@ -1,6 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { .foo : ALIGN(2M) { } }" > %t.script -# RUN: ld.lld -o %t --script %t.script %t.o -shared - -# We would crash if an empty section had an ALIGN. Index: lld/trunk/test/ELF/linkerscript/align-section.test =================================================================== --- lld/trunk/test/ELF/linkerscript/align-section.test +++ lld/trunk/test/ELF/linkerscript/align-section.test @@ -0,0 +1,7 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t.o +# RUN: ld.lld -o %t --script %s %t.o -shared + +# lld shouldn't crash. + +SECTIONS { .foo : ALIGN(2M) {} } Index: lld/trunk/test/ELF/linkerscript/align.s =================================================================== --- lld/trunk/test/ELF/linkerscript/align.s +++ lld/trunk/test/ELF/linkerscript/align.s @@ -1,125 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -## Check that ALIGN command workable using location counter -# RUN: echo "SECTIONS { \ -# RUN: . = 0x10000; \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: . = ALIGN(4096); \ -# RUN: .bbb : { *(.bbb) } \ -# RUN: . = ALIGN(4096 * 4); \ -# RUN: .ccc : { *(.ccc) } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s - -## Check that the two argument version of ALIGN command works -# RUN: echo "SECTIONS { \ -# RUN: . = ALIGN(0x1234, 0x10000); \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: . = ALIGN(., 4096); \ -# RUN: .bbb : { *(.bbb) } \ -# RUN: . = ALIGN(., 4096 * 4); \ -# RUN: .ccc : { *(.ccc) } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s - -# CHECK: Sections: -# CHECK-NEXT: Idx Name Size Address Type -# CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .aaa 00000008 0000000000010000 DATA -# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA -# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA - -## Check output sections ALIGN modificator -# RUN: echo "SECTIONS { \ -# RUN: . = 0x10000; \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: .bbb : ALIGN(4096) { *(.bbb) } \ -# RUN: .ccc : ALIGN(4096 * 4) { *(.ccc) } \ -# RUN: }" > %t2.script -# RUN: ld.lld -o %t2 --script %t2.script %t -# RUN: llvm-objdump -section-headers %t2 | FileCheck %s - -## Check use of variables in align expressions: -# RUN: echo "VAR = 0x1000; \ -# RUN: __code_base__ = 0x10000; \ -# RUN: SECTIONS { \ -# RUN: . = __code_base__; \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: .bbb : ALIGN(VAR) { *(.bbb) } \ -# RUN: . = ALIGN(., VAR * 4); \ -# RUN: .ccc : { *(.ccc) } \ -# RUN: __start_bbb = ADDR(.bbb); \ -# RUN: __end_bbb = ALIGN(__start_bbb + SIZEOF(.bbb), VAR); \ -# RUN: }" > %t3.script -# RUN: ld.lld -o %t3 --script %t3.script %t -# RUN: llvm-objdump -section-headers %t3 | FileCheck %s -# RUN: llvm-objdump -t %t3 | FileCheck -check-prefix SYMBOLS %s - -# SYMBOLS-LABEL: SYMBOL TABLE: -# SYMBOLS-NEXT: 0000000000000000 *UND* 00000000 -# SYMBOLS-NEXT: 0000000000014008 .text 00000000 _start -# SYMBOLS-NEXT: 0000000000010000 *ABS* 00000000 __code_base__ -# SYMBOLS-NEXT: 0000000000001000 *ABS* 00000000 VAR -# SYMBOLS-NEXT: 0000000000011000 .bbb 00000000 __start_bbb -# SYMBOLS-NEXT: 0000000000012000 .bbb 00000000 __end_bbb - -## Check that ALIGN zero do nothing and does not crash #1. -# RUN: echo "SECTIONS { . = ALIGN(0x123, 0); .aaa : { *(.aaa) } }" > %t.script -# RUN: ld.lld -o %t4 --script %t.script %t -# RUN: llvm-objdump -section-headers %t4 | FileCheck %s -check-prefix=ZERO - -# ZERO: Sections: -# ZERO-NEXT: Idx Name Size Address Type -# ZERO-NEXT: 0 00000000 0000000000000000 -# ZERO-NEXT: 1 .aaa 00000008 0000000000000123 DATA - -## Check that ALIGN zero do nothing and does not crash #2. -# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0); .aaa : { *(.aaa) } }" > %t.script -# RUN: ld.lld -o %t5 --script %t.script %t -# RUN: llvm-objdump -section-headers %t5 | FileCheck %s -check-prefix=ZERO - -## Test we fail gracefuly when alignment value is not a power of 2 (#1). -# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0x123, 3); .aaa : { *(.aaa) } }" > %t.script -# RUN: not ld.lld -o %t6 --script %t.script %t 2>&1 | FileCheck -check-prefix=ERR %s -# ERR: {{.*}}.script:1: alignment must be power of 2 - -## Test we fail gracefuly when alignment value is not a power of 2 (#2). -# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(3); .aaa : { *(.aaa) } }" > %t.script -# RUN: not ld.lld -o %t7 --script %t.script %t 2>&1 | FileCheck -check-prefix=ERR %s - -# RUN: echo "SECTIONS { \ -# RUN: . = 0xff8; \ -# RUN: .aaa : { \ -# RUN: *(.aaa) \ -# RUN: foo = ALIGN(., 0x100); \ -# RUN: bar = .; \ -# RUN: zed1 = ALIGN(., 0x100) + 1; \ -# RUN: zed2 = ALIGN(., 0x100) - 1; \ -# RUN: } \ -# RUN: .bbb : { *(.bbb); } \ -# RUN: .ccc : { *(.ccc); } \ -# RUN: .text : { *(.text); } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=OFFSET %s - -# OFFSET: 0000000000001000 .aaa 00000000 foo -# OFFSET: 0000000000001000 .aaa 00000000 bar -# OFFSET: 0000000000001001 .aaa 00000000 zed1 -# OFFSET: 0000000000000fff .aaa 00000000 zed2 - -.global _start -_start: - nop - -.section .aaa, "a" -.quad 0 - -.section .bbb, "a" -.quad 0 - -.section .ccc, "a" -.quad 0 Index: lld/trunk/test/ELF/linkerscript/align1.test =================================================================== --- lld/trunk/test/ELF/linkerscript/align1.test +++ lld/trunk/test/ELF/linkerscript/align1.test @@ -0,0 +1,44 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +SECTIONS { + . = 0x10000; + .aaa : { *(.aaa) } + . = ALIGN(4096); + .bbb : { *(.bbb) } + . = ALIGN(4096 * 4); + .ccc : { *(.ccc) } +} + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .aaa 00000008 0000000000010000 DATA +# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA +# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA + +## Check that ALIGN zero do nothing and does not crash #1. +# RUN: echo "SECTIONS { . = ALIGN(0x123, 0); .aaa : { *(.aaa) } }" > %t.script +# RUN: ld.lld -o %t4 --script %t.script %t.o +# RUN: llvm-objdump -section-headers %t4 | FileCheck %s -check-prefix=ZERO + +# ZERO: Sections: +# ZERO-NEXT: Idx Name Size Address Type +# ZERO-NEXT: 0 00000000 0000000000000000 +# ZERO-NEXT: 1 .aaa 00000008 0000000000000123 DATA + +## Check that ALIGN zero do nothing and does not crash #2. +# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0); .aaa : { *(.aaa) } }" > %t.script +# RUN: ld.lld -o %t5 --script %t.script %t.o +# RUN: llvm-objdump -section-headers %t5 | FileCheck %s -check-prefix=ZERO + +## Test we fail gracefuly when alignment value is not a power of 2 (#1). +# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0x123, 3); .aaa : { *(.aaa) } }" > %t.script +# RUN: not ld.lld -o %t6 --script %t.script %t.o 2>&1 | FileCheck -check-prefix=ERR %s + +# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(3); .aaa : { *(.aaa) } }" > %t.script +# RUN: not ld.lld -o %t7 --script %t.script %t.o 2>&1 | FileCheck -check-prefix=ERR %s + +# ERR: {{.*}}.script:1: alignment must be power of 2 Index: lld/trunk/test/ELF/linkerscript/align2.test =================================================================== --- lld/trunk/test/ELF/linkerscript/align2.test +++ lld/trunk/test/ELF/linkerscript/align2.test @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +SECTIONS { + . = ALIGN(0x1234, 0x10000); + .aaa : { *(.aaa) } + . = ALIGN(., 4096); + .bbb : { *(.bbb) } + . = ALIGN(., 4096 * 4); + .ccc : { *(.ccc) } +} + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .aaa 00000008 0000000000010000 DATA +# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA +# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA Index: lld/trunk/test/ELF/linkerscript/align3.test =================================================================== --- lld/trunk/test/ELF/linkerscript/align3.test +++ lld/trunk/test/ELF/linkerscript/align3.test @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +SECTIONS { + . = 0x10000; + .aaa : { *(.aaa) } + .bbb : ALIGN(4096) { *(.bbb) } + .ccc : ALIGN(4096 * 4) { *(.ccc) } +} + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .aaa 00000008 0000000000010000 DATA +# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA +# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA Index: lld/trunk/test/ELF/linkerscript/align4.test =================================================================== --- lld/trunk/test/ELF/linkerscript/align4.test +++ lld/trunk/test/ELF/linkerscript/align4.test @@ -0,0 +1,25 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# 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 +# CHECK-NEXT: 0000000000011000 .bbb 00000000 __start_bbb +# CHECK-NEXT: 0000000000012000 .bbb 00000000 __end_bbb + +VAR = 0x1000; +__code_base__ = 0x10000; + +SECTIONS { + . = __code_base__; + .aaa : { *(.aaa) } + .bbb : ALIGN(VAR) { *(.bbb) } + . = ALIGN(., VAR * 4); + .ccc : { *(.ccc) } + __start_bbb = ADDR(.bbb); + __end_bbb = ALIGN(__start_bbb + SIZEOF(.bbb), VAR); +} Index: lld/trunk/test/ELF/linkerscript/align5.test =================================================================== --- lld/trunk/test/ELF/linkerscript/align5.test +++ lld/trunk/test/ELF/linkerscript/align5.test @@ -0,0 +1,23 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -t %t | FileCheck %s + +SECTIONS { + . = 0xff8; + .aaa : { + *(.aaa) + foo = ALIGN(., 0x100); + bar = .; + zed1 = ALIGN(., 0x100) + 1; + zed2 = ALIGN(., 0x100) - 1; + } + .bbb : { *(.bbb); } + .ccc : { *(.ccc); } + .text : { *(.text); } +} + +# CHECK: 0000000000001000 .aaa 00000000 foo +# CHECK: 0000000000001000 .aaa 00000000 bar +# CHECK: 0000000000001001 .aaa 00000000 zed1 +# CHECK: 0000000000000fff .aaa 00000000 zed2 Index: lld/trunk/test/ELF/linkerscript/alignof.s =================================================================== --- lld/trunk/test/ELF/linkerscript/alignof.s +++ lld/trunk/test/ELF/linkerscript/alignof.s @@ -1,41 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -# RUN: echo "SECTIONS { \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: .bbb : { *(.bbb) } \ -# RUN: .ccc : { *(.ccc) } \ -# RUN: _aaa = ALIGNOF(.aaa); \ -# RUN: _bbb = ALIGNOF(.bbb); \ -# RUN: _ccc = ALIGNOF(.ccc); \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck %s -# CHECK: SYMBOL TABLE: -# CHECK: 0000000000000008 *ABS* 00000000 _aaa -# CHECK-NEXT: 0000000000000010 *ABS* 00000000 _bbb -# CHECK-NEXT: 0000000000000020 *ABS* 00000000 _ccc - -## Check that we error out if trying to get alignment of -## section that does not exist. -# RUN: echo "SECTIONS { \ -# RUN: _aaa = ALIGNOF(.foo); \ -# RUN: }" > %t.script -# RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 \ -# RUN: | FileCheck -check-prefix=ERR %s -# ERR: {{.*}}.script:1: undefined section .foo -.global _start -_start: - nop - -.section .aaa,"a" - .align 8 - .quad 0 - -.section .bbb,"a" - .align 16 - .quad 0 - -.section .ccc,"a" - .align 32 - .quad 0 Index: lld/trunk/test/ELF/linkerscript/alignof.test =================================================================== --- lld/trunk/test/ELF/linkerscript/alignof.test +++ lld/trunk/test/ELF/linkerscript/alignof.test @@ -0,0 +1,24 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/alignof.s -o %t +# RUN: ld.lld -o %t1 --script %s %t +# RUN: llvm-objdump -t %t1 | FileCheck %s +# CHECK: SYMBOL TABLE: +# CHECK: 0000000000000008 *ABS* 00000000 _aaa +# CHECK-NEXT: 0000000000000010 *ABS* 00000000 _bbb +# CHECK-NEXT: 0000000000000020 *ABS* 00000000 _ccc + +SECTIONS { + .aaa : { *(.aaa) } + .bbb : { *(.bbb) } + .ccc : { *(.ccc) } + _aaa = ALIGNOF(.aaa); + _bbb = ALIGNOF(.bbb); + _ccc = ALIGNOF(.ccc); +} + +## Check that we error out if trying to get alignment of +## section that does not exist. +# RUN: echo "SECTIONS { _aaa = ALIGNOF(.foo); }" > %t.script +# RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR %s +# ERR: {{.*}}.script:1: undefined section .foo Index: lld/trunk/test/ELF/linkerscript/arm-exidx-order.s =================================================================== --- lld/trunk/test/ELF/linkerscript/arm-exidx-order.s +++ lld/trunk/test/ELF/linkerscript/arm-exidx-order.s @@ -1,19 +0,0 @@ -# REQUIRES: arm -# RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; \ -# RUN: .ARM.exidx : { *(.ARM.exidx*) } \ -# RUN: .foo : { _foo = 0; } }" > %t.script -# RUN: ld.lld -T %t.script %t.o -shared -o %t.so -# RUN: llvm-readobj -s %t.so | FileCheck %s - -# CHECK: Section { -# CHECK: Index: -# CHECK: Name: .foo -# CHECK-NEXT: Type: SHT_NOBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] - -.fnstart -.cantunwind -.fnend Index: lld/trunk/test/ELF/linkerscript/arm-exidx-order.test =================================================================== --- lld/trunk/test/ELF/linkerscript/arm-exidx-order.test +++ lld/trunk/test/ELF/linkerscript/arm-exidx-order.test @@ -0,0 +1,19 @@ +# REQUIRES: arm +# RUN: echo ".fnstart; .cantunwind; .fnend" \ +# RUN: | llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi - -o %t.o +# RUN: ld.lld -T %s %t.o -shared -o %t.so +# RUN: llvm-readobj -s %t.so | FileCheck %s + +SECTIONS { + . = SIZEOF_HEADERS; + .ARM.exidx : { *(.ARM.exidx*) } + .foo : { _foo = 0; } +} + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .foo +# CHECK-NEXT: Type: SHT_NOBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] Index: lld/trunk/test/ELF/linkerscript/arm-exidx-phdrs.s =================================================================== --- lld/trunk/test/ELF/linkerscript/arm-exidx-phdrs.s +++ lld/trunk/test/ELF/linkerscript/arm-exidx-phdrs.s @@ -1,16 +0,0 @@ -// REQUIRES: arm -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -// RUN: echo "PHDRS { ph_text PT_LOAD; } \ -// RUN: SECTIONS { \ -// RUN: . = SIZEOF_HEADERS; \ -// RUN: .text : { *(.text) } : ph_text \ -// RUN: }" > %t.script -// RUN: ld.lld -T %t.script %t.o -shared -o %t.so -// RUN: llvm-readobj --program-headers %t.so | FileCheck %s - -// CHECK: Type: PT_ARM_EXIDX - -.fnstart -bx lr -.cantunwind -.fnend Index: lld/trunk/test/ELF/linkerscript/arm-exidx-phdrs.test =================================================================== --- lld/trunk/test/ELF/linkerscript/arm-exidx-phdrs.test +++ lld/trunk/test/ELF/linkerscript/arm-exidx-phdrs.test @@ -0,0 +1,13 @@ +# REQUIRES: arm +# RUN: echo ".fnstart; bx lr; .cantunwind; .fnend" \ +# RUN: | llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi - -o %t.o +# RUN: ld.lld -T %s %t.o -shared -o %t.so +# RUN: llvm-readobj --program-headers %t.so | FileCheck %s + +# CHECK: Type: PT_ARM_EXIDX + +PHDRS { ph_text PT_LOAD; } +SECTIONS { + . = SIZEOF_HEADERS; + .text : { *(.text) } : ph_text +} Index: lld/trunk/test/ELF/linkerscript/arm-lscript.s =================================================================== --- lld/trunk/test/ELF/linkerscript/arm-lscript.s +++ lld/trunk/test/ELF/linkerscript/arm-lscript.s @@ -1,9 +0,0 @@ -// REQUIRES: arm -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -// RUN: echo "SECTIONS { \ -// RUN: .rel.dyn : { } \ -// RUN: .zed : { PROVIDE_HIDDEN (foobar = .); } \ -// RUN: }" > %t.script -// This is a test case for PR33029. Making sure that linker can digest -// the above script without dumping core. -// RUN: ld.lld -emit-relocs -T %t.script %t.o -shared -o %t.so Index: lld/trunk/test/ELF/linkerscript/arm-lscript.test =================================================================== --- lld/trunk/test/ELF/linkerscript/arm-lscript.test +++ lld/trunk/test/ELF/linkerscript/arm-lscript.test @@ -0,0 +1,11 @@ +# REQUIRES: arm +# RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi /dev/null -o %t.o + +# This is a test case for PR33029. Making sure that linker can digest +# the above script without dumping core. +# RUN: ld.lld -emit-relocs -T %s %t.o -shared -o %t.so + +SECTIONS { + .rel.dyn : {} + .zed : { PROVIDE_HIDDEN (foobar = .); } +} Index: lld/trunk/test/ELF/linkerscript/at2.s =================================================================== --- lld/trunk/test/ELF/linkerscript/at2.s +++ lld/trunk/test/ELF/linkerscript/at2.s @@ -1,81 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "MEMORY { \ -# RUN: AX (ax) : ORIGIN = 0x2000, LENGTH = 0x100 \ -# RUN: AW (aw) : ORIGIN = 0x3000, LENGTH = 0x100 \ -# RUN: FLASH (ax) : ORIGIN = 0x6000, LENGTH = 0x100 \ -# RUN: RAM (aw) : ORIGIN = 0x7000, LENGTH = 0x100 } \ -# RUN: SECTIONS { \ -# RUN: .foo1 : { *(.foo1) } > AX AT>FLASH \ -# RUN: .foo2 : { *(.foo2) } > AX \ -# RUN: .bar1 : { *(.bar1) } > AW AT> RAM \ -# RUN: .bar2 : { *(.bar2) } > AW AT > RAM \ -# RUN: .bar3 : { *(.bar3) } > AW AT >RAM \ -# RUN: }" > %t.script -# RUN: ld.lld %t --script %t.script -o %t2 -# RUN: llvm-readobj -program-headers %t2 | FileCheck %s -# RUN: llvm-objdump -section-headers %t2 | FileCheck %s --check-prefix=SECTIONS - -# CHECK: ProgramHeaders [ -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_LOAD -# CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: VirtualAddress: 0x2000 -# CHECK-NEXT: PhysicalAddress: 0x6000 -# CHECK-NEXT: FileSize: 16 -# CHECK-NEXT: MemSize: 16 -# CHECK-NEXT: Flags [ -# CHECK-NEXT: PF_R -# CHECK-NEXT: PF_X -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: -# CHECK-NEXT: } -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_LOAD -# CHECK-NEXT: Offset: 0x2000 -# CHECK-NEXT: VirtualAddress: 0x3000 -# CHECK-NEXT: PhysicalAddress: 0x7000 -# CHECK-NEXT: FileSize: 24 -# CHECK-NEXT: MemSize: 24 -# CHECK-NEXT: Flags [ -# CHECK-NEXT: PF_R -# CHECK-NEXT: PF_W -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 4096 -# CHECK-NEXT: } - -# SECTIONS: Sections: -# SECTIONS-NEXT: Idx Name Size Address -# SECTIONS-NEXT: 0 00000000 0000000000000000 -# SECTIONS-NEXT: 1 .foo1 00000008 0000000000002000 -# SECTIONS-NEXT: 2 .foo2 00000008 0000000000002008 -# SECTIONS-NEXT: 3 .text 00000000 0000000000002010 -# SECTIONS-NEXT: 4 .bar1 00000008 0000000000003000 -# SECTIONS-NEXT: 5 .bar2 00000008 0000000000003008 -# SECTIONS-NEXT: 6 .bar3 00000008 0000000000003010 - -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "MEMORY { \ -# RUN: FLASH (ax) : ORIGIN = 0x2000, LENGTH = 0x100 \ -# RUN: RAM (aw) : ORIGIN = 0x5000, LENGTH = 0x100 } \ -# RUN: SECTIONS { \ -# RUN: .foo1 : AT(0x500) { *(.foo1) } > FLASH AT>FLASH \ -# RUN: }" > %t2.script -# RUN: not ld.lld %t --script %t2.script -o %t2 2>&1 | \ -# RUN: FileCheck %s --check-prefix=ERR -# ERR: error: section can't have both LMA and a load region - -.section .foo1, "ax" -.quad 0 - -.section .foo2, "ax" -.quad 0 - -.section .bar1, "aw" -.quad 0 - -.section .bar2, "aw" -.quad 0 - -.section .bar3, "aw" -.quad 0 Index: lld/trunk/test/ELF/linkerscript/at2.test =================================================================== --- lld/trunk/test/ELF/linkerscript/at2.test +++ lld/trunk/test/ELF/linkerscript/at2.test @@ -0,0 +1,58 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/at2.s -o %t.o +# RUN: ld.lld -o %t.exe %t.o --script %s +# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s +# RUN: llvm-objdump -section-headers %t.exe | FileCheck %s --check-prefix=SECTIONS + +MEMORY { + AX (ax) : ORIGIN = 0x2000, LENGTH = 0x100 + AW (aw) : ORIGIN = 0x3000, LENGTH = 0x100 + FLASH (ax) : ORIGIN = 0x6000, LENGTH = 0x100 + RAM (aw) : ORIGIN = 0x7000, LENGTH = 0x100 +} + +SECTIONS { + .foo1 : { *(.foo1) } > AX AT>FLASH + .foo2 : { *(.foo2) } > AX + .bar1 : { *(.bar1) } > AW AT> RAM + .bar2 : { *(.bar2) } > AW AT > RAM + .bar3 : { *(.bar3) } > AW AT >RAM +} + +# CHECK: ProgramHeaders [ +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: VirtualAddress: 0x2000 +# CHECK-NEXT: PhysicalAddress: 0x6000 +# CHECK-NEXT: FileSize: 16 +# CHECK-NEXT: MemSize: 16 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_X +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x2000 +# CHECK-NEXT: VirtualAddress: 0x3000 +# CHECK-NEXT: PhysicalAddress: 0x7000 +# CHECK-NEXT: FileSize: 24 +# CHECK-NEXT: MemSize: 24 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_W +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: } + +# SECTIONS: Sections: +# SECTIONS-NEXT: Idx Name Size Address +# SECTIONS-NEXT: 0 00000000 0000000000000000 +# SECTIONS-NEXT: 1 .foo1 00000008 0000000000002000 +# SECTIONS-NEXT: 2 .foo2 00000008 0000000000002008 +# SECTIONS-NEXT: 3 .text 00000000 0000000000002010 +# SECTIONS-NEXT: 4 .bar1 00000008 0000000000003000 +# SECTIONS-NEXT: 5 .bar2 00000008 0000000000003008 +# SECTIONS-NEXT: 6 .bar3 00000008 0000000000003010 Index: lld/trunk/test/ELF/linkerscript/at3.s =================================================================== --- lld/trunk/test/ELF/linkerscript/at3.s +++ lld/trunk/test/ELF/linkerscript/at3.s @@ -1,38 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "MEMORY { \ -# RUN: FOO (ax) : ORIGIN = 0x1000, LENGTH = 0x100 \ -# RUN: BAR (ax) : ORIGIN = 0x2000, LENGTH = 0x100 \ -# RUN: ZED (ax) : ORIGIN = 0x3000, LENGTH = 0x100 \ -# RUN: FLASH (ax) : ORIGIN = 0x6000, LENGTH = 0x200 \ -# RUN: } \ -# RUN: SECTIONS { \ -# RUN: .foo1 : { *(.foo1) } > FOO AT>FLASH \ -# RUN: .foo2 : { *(.foo2) BYTE(0x42) } > BAR AT>FLASH \ -# RUN: .foo3 : { *(.foo3) } > ZED AT>FLASH \ -# RUN: }" > %t.script -# RUN: ld.lld %t.o --script %t.script -o %t -# RUN: llvm-readelf -sections -program-headers %t | FileCheck %s - -# CHECK: .foo1 PROGBITS 0000000000001000 001000 -# CHECK: .foo2 PROGBITS 0000000000002000 002000 -# CHECK: .foo3 PROGBITS 0000000000003000 003000 - -# CHECK: Program Headers: -# CHECK-NOT: LOAD - -# CHECK: Type Offset VirtAddr PhysAddr -# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000006000 -# CHECK-NEXT: LOAD 0x002000 0x0000000000002000 0x0000000000006008 -# CHECK-NEXT: LOAD 0x003000 0x0000000000003000 0x0000000000006011 - -# CHECK-NOT: LOAD - -.section .foo1, "a" -.quad 0 - -.section .foo2, "ax" -.quad 0 - -.section .foo3, "ax" -.quad 0 Index: lld/trunk/test/ELF/linkerscript/at3.test =================================================================== --- lld/trunk/test/ELF/linkerscript/at3.test +++ lld/trunk/test/ELF/linkerscript/at3.test @@ -0,0 +1,31 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/at3.s -o %t.o +# RUN: ld.lld %t.o --script %s -o %t +# RUN: llvm-readelf -sections -program-headers %t | FileCheck %s + +MEMORY { + FOO (ax) : ORIGIN = 0x1000, LENGTH = 0x100 + BAR (ax) : ORIGIN = 0x2000, LENGTH = 0x100 + ZED (ax) : ORIGIN = 0x3000, LENGTH = 0x100 + FLASH (ax) : ORIGIN = 0x6000, LENGTH = 0x200 +} + +SECTIONS { + .foo1 : { *(.foo1) } > FOO AT>FLASH + .foo2 : { *(.foo2) BYTE(0x42) } > BAR AT>FLASH + .foo3 : { *(.foo3) } > ZED AT>FLASH +} + +# CHECK: .foo1 PROGBITS 0000000000001000 001000 +# CHECK: .foo2 PROGBITS 0000000000002000 002000 +# CHECK: .foo3 PROGBITS 0000000000003000 003000 + +# CHECK: Program Headers: +# CHECK-NOT: LOAD + +# CHECK: Type Offset VirtAddr PhysAddr +# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000006000 +# CHECK-NEXT: LOAD 0x002000 0x0000000000002000 0x0000000000006008 +# CHECK-NEXT: LOAD 0x003000 0x0000000000003000 0x0000000000006011 + +# CHECK-NOT: LOAD Index: lld/trunk/test/ELF/linkerscript/at5.test =================================================================== --- lld/trunk/test/ELF/linkerscript/at5.test +++ lld/trunk/test/ELF/linkerscript/at5.test @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: not ld.lld -o %t.exe %t.o --script %s 2>&1 | FileCheck %s + +MEMORY { + FLASH (ax) : ORIGIN = 0x2000, LENGTH = 0x100 + RAM (aw) : ORIGIN = 0x5000, LENGTH = 0x100 +} + +SECTIONS { + .foo1 : AT(0x500) { *(.foo1) } > FLASH AT>FLASH +} + +# CHECK: error: section can't have both LMA and a load region Index: lld/trunk/test/ELF/linkerscript/symbols-synthetic.s =================================================================== --- lld/trunk/test/ELF/linkerscript/symbols-synthetic.s +++ lld/trunk/test/ELF/linkerscript/symbols-synthetic.s @@ -1,98 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# Simple symbol assignment within input section list. The '.' symbol -# is not location counter but offset from the beginning of output -# section .foo -# RUN: echo "SECTIONS { \ -# RUN: . = SIZEOF_HEADERS; \ -# RUN: .foo : { \ -# RUN: begin_foo = .; \ -# RUN: PROVIDE(_begin_sec = .); \ -# RUN: *(.foo) \ -# RUN: end_foo = .; \ -# RUN: PROVIDE_HIDDEN(_end_sec = .); \ -# RUN: PROVIDE(_end_sec_abs = ABSOLUTE(.)); \ -# RUN: size_foo_1 = SIZEOF(.foo); \ -# RUN: size_foo_1_abs = ABSOLUTE(SIZEOF(.foo)); \ -# RUN: . = ALIGN(0x1000); \ -# RUN: begin_bar = .; \ -# RUN: *(.bar) \ -# RUN: end_bar = .; \ -# RUN: size_foo_2 = SIZEOF(.foo); } \ -# RUN: size_foo_3 = SIZEOF(.foo); \ -# RUN: .eh_frame_hdr : { \ -# RUN: __eh_frame_hdr_start = .; \ -# RUN: __eh_frame_hdr_start2 = ABSOLUTE(ALIGN(0x10)); \ -# RUN: *(.eh_frame_hdr) \ -# RUN: __eh_frame_hdr_end = .; \ -# RUN: __eh_frame_hdr_end2 = ABSOLUTE(ALIGN(0x10)); } \ -# RUN: .eh_frame : { } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=SIMPLE %s - -# Check that the following script is processed without errors -# RUN: echo "SECTIONS { \ -# RUN: .eh_frame_hdr : { \ -# RUN: PROVIDE_HIDDEN(_begin_sec = .); \ -# RUN: *(.eh_frame_hdr) \ -# RUN: *(.eh_frame_hdr) \ -# RUN: PROVIDE_HIDDEN(_end_sec_abs = ABSOLUTE(.)); \ -# RUN: PROVIDE_HIDDEN(_end_sec = .); } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t - -# Check that we can specify synthetic symbols without defining SECTIONS. -# RUN: echo "PROVIDE_HIDDEN(_begin_sec = _start); \ -# RUN: PROVIDE_HIDDEN(_end_sec = ADDR(.text) + SIZEOF(.text));" > %t.script -# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=NO-SEC %s - -# Check that we can do the same as above inside SECTIONS block. -# RUN: echo "SECTIONS { \ -# RUN: . = 0x201000; \ -# RUN: .text : { *(.text) } \ -# RUN: PROVIDE_HIDDEN(_begin_sec = ADDR(.text)); \ -# RUN: PROVIDE_HIDDEN(_end_sec = ADDR(.text) + SIZEOF(.text)); }" > %t.script -# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=IN-SEC %s - -# SIMPLE: 0000000000000128 .foo 00000000 .hidden _end_sec -# SIMPLE-NEXT: 0000000000000120 .foo 00000000 _begin_sec -# SIMPLE-NEXT: 0000000000000128 *ABS* 00000000 _end_sec_abs -# SIMPLE-NEXT: 0000000000001048 .text 00000000 _start -# SIMPLE-NEXT: 0000000000000120 .foo 00000000 begin_foo -# SIMPLE-NEXT: 0000000000000128 .foo 00000000 end_foo -# SIMPLE-NEXT: 0000000000000008 *ABS* 00000000 size_foo_1 -# SIMPLE-NEXT: 0000000000000008 *ABS* 00000000 size_foo_1_abs -# SIMPLE-NEXT: 0000000000001000 .foo 00000000 begin_bar -# SIMPLE-NEXT: 0000000000001004 .foo 00000000 end_bar -# SIMPLE-NEXT: 0000000000000ee4 *ABS* 00000000 size_foo_2 -# SIMPLE-NEXT: 0000000000000ee4 *ABS* 00000000 size_foo_3 -# SIMPLE-NEXT: 0000000000001004 .eh_frame_hdr 00000000 __eh_frame_hdr_start -# SIMPLE-NEXT: 0000000000001010 *ABS* 00000000 __eh_frame_hdr_start2 -# SIMPLE-NEXT: 0000000000001018 .eh_frame_hdr 00000000 __eh_frame_hdr_end -# SIMPLE-NEXT: 0000000000001020 *ABS* 00000000 __eh_frame_hdr_end2 - -# NO-SEC: 0000000000201000 .text 00000000 .hidden _begin_sec -# NO-SEC-NEXT: 0000000000201001 .text 00000000 .hidden _end_sec - -# IN-SEC: 0000000000201000 .text 00000000 .hidden _begin_sec -# IN-SEC-NEXT: 0000000000201001 .text 00000000 .hidden _end_sec - -.global _start -_start: - nop - -.section .foo,"a" - .quad 0 - -.section .bar,"a" - .long 0 - -.section .dah,"ax",@progbits - .cfi_startproc - nop - .cfi_endproc - -.global _begin_sec, _end_sec, _end_sec_abs Index: lld/trunk/test/ELF/linkerscript/synthetic-symbols1.test =================================================================== --- lld/trunk/test/ELF/linkerscript/synthetic-symbols1.test +++ lld/trunk/test/ELF/linkerscript/synthetic-symbols1.test @@ -0,0 +1,56 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/synthetic-symbols.s -o %t +# RUN: ld.lld -o %t.exe --eh-frame-hdr --script %s %t +# RUN: llvm-objdump -t %t.exe | FileCheck %s + +# Simple symbol assignment within input section list. The '.' symbol +# is not location counter but offset from the beginning of output +# section .foo + +SECTIONS { + . = SIZEOF_HEADERS; + .foo : { + begin_foo = .; + PROVIDE(_begin_sec = .); + *(.foo) + end_foo = .; + PROVIDE_HIDDEN(_end_sec = .); + PROVIDE(_end_sec_abs = ABSOLUTE(.)); + size_foo_1 = SIZEOF(.foo); + size_foo_1_abs = ABSOLUTE(SIZEOF(.foo)); + . = ALIGN(0x1000); + begin_bar = .; + *(.bar) + end_bar = .; + size_foo_2 = SIZEOF(.foo); + } + + size_foo_3 = SIZEOF(.foo); + + .eh_frame_hdr : { + __eh_frame_hdr_start = .; + __eh_frame_hdr_start2 = ABSOLUTE(ALIGN(0x10)); + *(.eh_frame_hdr) + __eh_frame_hdr_end = .; + __eh_frame_hdr_end2 = ABSOLUTE(ALIGN(0x10)); + } + + .eh_frame : {} +} + +# CHECK: 0000000000000128 .foo 00000000 .hidden _end_sec +# CHECK-NEXT: 0000000000000120 .foo 00000000 _begin_sec +# CHECK-NEXT: 0000000000000128 *ABS* 00000000 _end_sec_abs +# CHECK-NEXT: 0000000000001048 .text 00000000 _start +# CHECK-NEXT: 0000000000000120 .foo 00000000 begin_foo +# CHECK-NEXT: 0000000000000128 .foo 00000000 end_foo +# CHECK-NEXT: 0000000000000008 *ABS* 00000000 size_foo_1 +# CHECK-NEXT: 0000000000000008 *ABS* 00000000 size_foo_1_abs +# CHECK-NEXT: 0000000000001000 .foo 00000000 begin_bar +# CHECK-NEXT: 0000000000001004 .foo 00000000 end_bar +# CHECK-NEXT: 0000000000000ee4 *ABS* 00000000 size_foo_2 +# CHECK-NEXT: 0000000000000ee4 *ABS* 00000000 size_foo_3 +# CHECK-NEXT: 0000000000001004 .eh_frame_hdr 00000000 __eh_frame_hdr_start +# CHECK-NEXT: 0000000000001010 *ABS* 00000000 __eh_frame_hdr_start2 +# CHECK-NEXT: 0000000000001018 .eh_frame_hdr 00000000 __eh_frame_hdr_end +# CHECK-NEXT: 0000000000001020 *ABS* 00000000 __eh_frame_hdr_end2 Index: lld/trunk/test/ELF/linkerscript/synthetic-symbols2.test =================================================================== --- lld/trunk/test/ELF/linkerscript/synthetic-symbols2.test +++ lld/trunk/test/ELF/linkerscript/synthetic-symbols2.test @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/synthetic-symbols.s -o %t +# RUN: ld.lld -o %t.exe --eh-frame-hdr --script %s %t + +SECTIONS { + .eh_frame_hdr : { + PROVIDE_HIDDEN(_begin_sec = .); + *(.eh_frame_hdr) + *(.eh_frame_hdr) + PROVIDE_HIDDEN(_end_sec_abs = ABSOLUTE(.)); + PROVIDE_HIDDEN(_end_sec = .); + } +} Index: lld/trunk/test/ELF/linkerscript/synthetic-symbols3.test =================================================================== --- lld/trunk/test/ELF/linkerscript/synthetic-symbols3.test +++ lld/trunk/test/ELF/linkerscript/synthetic-symbols3.test @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/synthetic-symbols.s -o %t +# RUN: ld.lld -o %t.exe --eh-frame-hdr --script %s %t +# RUN: llvm-objdump -t %t.exe | FileCheck %s + +# Check that we can specify synthetic symbols without defining SECTIONS. +PROVIDE_HIDDEN(_begin_sec = _start); +PROVIDE_HIDDEN(_end_sec = ADDR(.text) + SIZEOF(.text)); + +# CHECK: 0000000000201000 .text 00000000 .hidden _begin_sec +# CHECK-NEXT: 0000000000201001 .text 00000000 .hidden _end_sec Index: lld/trunk/test/ELF/linkerscript/synthetic-symbols4.test =================================================================== --- lld/trunk/test/ELF/linkerscript/synthetic-symbols4.test +++ lld/trunk/test/ELF/linkerscript/synthetic-symbols4.test @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/synthetic-symbols.s -o %t +# RUN: ld.lld -o %t.exe --eh-frame-hdr --script %s %t +# RUN: llvm-objdump -t %t.exe | FileCheck %s + +SECTIONS { + . = 0x201000; + .text : { *(.text) } + PROVIDE_HIDDEN(_begin_sec = ADDR(.text)); + PROVIDE_HIDDEN(_end_sec = ADDR(.text) + SIZEOF(.text)); +} + +# CHECK: 0000000000201000 .text 00000000 .hidden _begin_sec +# CHECK-NEXT: 0000000000201001 .text 00000000 .hidden _end_sec