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