1# REQUIRES: x86 2# RUN: rm -rf %t && split-file %s %t && cd %t 3# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o 4 5#--- empty.lds 6SECTIONS {} 7 8# RUN: ld.lld -o empty -T empty.lds a.o 9# RUN: llvm-objdump --section-headers empty | \ 10# RUN: FileCheck -check-prefix=SEC-DEFAULT %s 11 12#--- 1.lds 13# SECTIONS command with the same order as default. 14SECTIONS { 15 .text : { *(.text) } 16 .data : { *(.data) } } 17 18# RUN: ld.lld -o 1 -T 1.lds a.o 19# RUN: llvm-objdump --section-headers 1 | \ 20# RUN: FileCheck -check-prefix=SEC-DEFAULT %s 21 22# Idx Name Size 23# SEC-DEFAULT: 1 .text 0000000e {{[0-9a-f]*}} TEXT 24# SEC-DEFAULT: 2 .data 00000020 {{[0-9a-f]*}} DATA 25# SEC-DEFAULT: 3 other 00000003 {{[0-9a-f]*}} DATA 26# SEC-DEFAULT: 4 .bss 00000002 {{[0-9a-f]*}} BSS 27# SEC-DEFAULT: 5 .comment 00000008 {{[0-9a-f]*}} 28# SEC-DEFAULT: 6 .symtab 00000030 {{[0-9a-f]*}} 29# SEC-DEFAULT: 7 .shstrtab 0000003b {{[0-9a-f]*}} 30# SEC-DEFAULT: 8 .strtab 00000008 {{[0-9a-f]*}} 31 32# .text and .data have swapped names but proper sizes and types. 33# RUN: echo "SECTIONS { \ 34# RUN: .data : { *(.text) } \ 35# RUN: .text : { *(.data) } }" > t.lds 36# RUN: ld.lld -o %t4 --script t.lds a.o 37# RUN: llvm-objdump --section-headers %t4 | \ 38# RUN: FileCheck -check-prefix=SEC-SWAP-NAMES %s 39 40# Idx Name Size 41# SEC-SWAP-NAMES: 1 .data 0000000e {{[0-9a-f]*}} TEXT 42# SEC-SWAP-NAMES: 2 .text 00000020 {{[0-9a-f]*}} DATA 43# SEC-SWAP-NAMES: 3 other 00000003 {{[0-9a-f]*}} DATA 44# SEC-SWAP-NAMES: 4 .bss 00000002 {{[0-9a-f]*}} BSS 45# SEC-SWAP-NAMES: 5 .comment 00000008 {{[0-9a-f]*}} 46# SEC-SWAP-NAMES: 6 .symtab 00000030 {{[0-9a-f]*}} 47# SEC-SWAP-NAMES: 7 .shstrtab 0000003b {{[0-9a-f]*}} 48# SEC-SWAP-NAMES: 8 .strtab 00000008 {{[0-9a-f]*}} 49 50# Multiple SECTIONS command specifying additional input section descriptions 51# for the same output section description - input sections are merged into 52# one output section. 53# RUN: echo "SECTIONS { \ 54# RUN: .text : { *(.text) } \ 55# RUN: .data : { *(.data) } } \ 56# RUN: SECTIONS { \ 57# RUN: .data : { *(other) } }" > t.lds 58# RUN: ld.lld -o %t6 --script t.lds a.o 59# RUN: llvm-objdump --section-headers %t6 | \ 60# RUN: FileCheck -check-prefix=SEC-MULTI %s 61 62# Idx Name Size 63# SEC-MULTI: 1 .text 0000000e {{[0-9a-f]*}} TEXT 64# SEC-MULTI-NEXT: .data 00000020 {{[0-9a-f]*}} DATA 65# SEC-MULTI-NEXT: .data 00000003 {{[0-9a-f]*}} DATA 66# SEC-MULTI-NEXT: .bss 00000002 {{[0-9a-f]*}} BSS 67# SEC-MULTI-NEXT: .comment 00000008 {{[0-9a-f]*}} 68# SEC-MULTI-NEXT: .symtab 00000030 {{[0-9a-f]*}} 69# SEC-MULTI-NEXT: .shstrtab 00000035 {{[0-9a-f]*}} 70# SEC-MULTI-NEXT: .strtab 00000008 {{[0-9a-f]*}} 71 72## other is placed in a PT_LOAD segment even if it is preceded by a non-alloc section. 73## The current implementation places .data, .bss, .comment and other in the same PT_LOAD. 74# RUN: echo 'SECTIONS { \ 75# RUN: .text : { *(.text) } \ 76# RUN: .data : { *(.data) } \ 77# RUN: .comment : { *(.comment) } \ 78# RUN: other : { *(other) } }' > %t5.lds 79# RUN: ld.lld -o %t5 -T %t5.lds a.o 80# RUN: llvm-readelf -S -l %t5 | FileCheck --check-prefix=SEP-BY-NONALLOC %s 81 82# SEP-BY-NONALLOC: [Nr] Name Type Address Off Size ES Flg 83# SEP-BY-NONALLOC: [ 1] .text PROGBITS 0000000000000000 001000 00000e 00 AX 84# SEP-BY-NONALLOC-NEXT: [ 2] .data PROGBITS 000000000000000e 00100e 000020 00 WA 85# SEP-BY-NONALLOC-NEXT: [ 3] .comment PROGBITS 0000000000000000 001031 000008 01 MS 86# SEP-BY-NONALLOC: [ 4] other PROGBITS 000000000000002e 00102e 000003 00 WA 87# SEP-BY-NONALLOC-NEXT: [ 5] .bss NOBITS 0000000000000031 001031 000002 00 WA 88 89# SEP-BY-NONALLOC: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align 90# SEP-BY-NONALLOC-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x00000e 0x00000e R E 0x1000 91# SEP-BY-NONALLOC-NEXT: LOAD 0x00100e 0x000000000000000e 0x000000000000000e 0x000023 0x000025 RW 0x1000 92# SEP-BY-NONALLOC-NEXT: GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0 93 94#--- semi.lds 95# Input section pattern contains additional semicolon. 96# Case found in linux kernel script. Check we are able to parse it. 97SECTIONS { .text : { ;;*(.text);;S = 0;; } } 98 99# RUN: ld.lld -T semi.lds a.o 100 101#--- unclosed.lds 102SECTIONS { 103 .text : { *(.text) } 104 105# RUN: not ld.lld -T unclosed.lds a.o 2>&1 | FileCheck --check-prefix=UNCLOSED %s 106# UNCLOSED:error: unclosed.lds:2: unexpected EOF 107# UNCLOSED-NOT:{{.}} 108 109#--- unclosed-out.lds 110SECTIONS { 111 .text : { *(.text) 112 113#--- a.s 114.globl _start 115_start: 116 mov $60, %rax 117 mov $42, %rdi 118 119.section .data,"aw" 120.quad 10, 10, 20, 20 121.section other,"aw" 122.short 10 123.byte 20 124.section .bss,"",@nobits 125.short 0 126