126 lines · plain
1# REQUIRES: x862# RUN: rm -rf %t && split-file %s %t && cd %t3# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o4 5#--- empty.lds6SECTIONS {}7 8# RUN: ld.lld -o empty -T empty.lds a.o9# RUN: llvm-objdump --section-headers empty | \10# RUN: FileCheck -check-prefix=SEC-DEFAULT %s11 12#--- 1.lds13# 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.o19# RUN: llvm-objdump --section-headers 1 | \20# RUN: FileCheck -check-prefix=SEC-DEFAULT %s21 22# Idx Name Size23# SEC-DEFAULT: 1 .text 0000000e {{[0-9a-f]*}} TEXT24# SEC-DEFAULT: 2 .data 00000020 {{[0-9a-f]*}} DATA25# SEC-DEFAULT: 3 other 00000003 {{[0-9a-f]*}} DATA26# SEC-DEFAULT: 4 .bss 00000002 {{[0-9a-f]*}} BSS27# 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.lds36# RUN: ld.lld -o %t4 --script t.lds a.o37# RUN: llvm-objdump --section-headers %t4 | \38# RUN: FileCheck -check-prefix=SEC-SWAP-NAMES %s39 40# Idx Name Size41# SEC-SWAP-NAMES: 1 .data 0000000e {{[0-9a-f]*}} TEXT42# SEC-SWAP-NAMES: 2 .text 00000020 {{[0-9a-f]*}} DATA43# SEC-SWAP-NAMES: 3 other 00000003 {{[0-9a-f]*}} DATA44# SEC-SWAP-NAMES: 4 .bss 00000002 {{[0-9a-f]*}} BSS45# 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 descriptions51# for the same output section description - input sections are merged into52# one output section.53# RUN: echo "SECTIONS { \54# RUN: .text : { *(.text) } \55# RUN: .data : { *(.data) } } \56# RUN: SECTIONS { \57# RUN: .data : { *(other) } }" > t.lds58# RUN: ld.lld -o %t6 --script t.lds a.o59# RUN: llvm-objdump --section-headers %t6 | \60# RUN: FileCheck -check-prefix=SEC-MULTI %s61 62# Idx Name Size63# SEC-MULTI: 1 .text 0000000e {{[0-9a-f]*}} TEXT64# SEC-MULTI-NEXT: .data 00000020 {{[0-9a-f]*}} DATA65# SEC-MULTI-NEXT: .data 00000003 {{[0-9a-f]*}} DATA66# SEC-MULTI-NEXT: .bss 00000002 {{[0-9a-f]*}} BSS67# 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.lds79# RUN: ld.lld -o %t5 -T %t5.lds a.o80# RUN: llvm-readelf -S -l %t5 | FileCheck --check-prefix=SEP-BY-NONALLOC %s81 82# SEP-BY-NONALLOC: [Nr] Name Type Address Off Size ES Flg83# SEP-BY-NONALLOC: [ 1] .text PROGBITS 0000000000000000 001000 00000e 00 AX84# SEP-BY-NONALLOC-NEXT: [ 2] .data PROGBITS 000000000000000e 00100e 000020 00 WA85# SEP-BY-NONALLOC-NEXT: [ 3] .comment PROGBITS 0000000000000000 001031 000008 01 MS86# SEP-BY-NONALLOC: [ 4] other PROGBITS 000000000000002e 00102e 000003 00 WA87# SEP-BY-NONALLOC-NEXT: [ 5] .bss NOBITS 0000000000000031 001031 000002 00 WA88 89# SEP-BY-NONALLOC: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align90# SEP-BY-NONALLOC-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x00000e 0x00000e R E 0x100091# SEP-BY-NONALLOC-NEXT: LOAD 0x00100e 0x000000000000000e 0x000000000000000e 0x000023 0x000025 RW 0x100092# SEP-BY-NONALLOC-NEXT: GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 093 94#--- semi.lds95# 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.o100 101#--- unclosed.lds102SECTIONS {103 .text : { *(.text) }104 105# RUN: not ld.lld -T unclosed.lds a.o 2>&1 | FileCheck --check-prefix=UNCLOSED %s106# UNCLOSED:error: unclosed.lds:2: unexpected EOF107# UNCLOSED-NOT:{{.}}108 109#--- unclosed-out.lds110SECTIONS {111 .text : { *(.text)112 113#--- a.s114.globl _start115_start:116 mov $60, %rax117 mov $42, %rdi118 119.section .data,"aw"120.quad 10, 10, 20, 20121.section other,"aw"122.short 10123.byte 20124.section .bss,"",@nobits125.short 0126