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# Sections are put in order specified in linker script, other than alloc 29# sections going first. 30# RUN: echo "SECTIONS { \ 31# RUN: .bss : { *(.bss) } \ 32# RUN: other : { *(other) } \ 33# RUN: .shstrtab : { *(.shstrtab) } \ 34# RUN: .symtab : { *(.symtab) } \ 35# RUN: .strtab : { *(.strtab) } \ 36# RUN: .data : { *(.data) } \ 37# RUN: .text : { *(.text) } }" > %t.script 38# RUN: ld.lld -o %t3 --script %t.script %t 39# RUN: llvm-objdump --section-headers %t3 | \ 40# RUN: FileCheck -check-prefix=SEC-ORDER %s 41 42# Idx Name Size 43# SEC-ORDER: 1 .bss 00000002 {{[0-9a-f]*}} BSS 44# SEC-ORDER: 2 other 00000003 {{[0-9a-f]*}} DATA 45# SEC-ORDER: 3 .shstrtab 0000003b {{[0-9a-f]*}} 46# SEC-ORDER: 4 .symtab 00000030 {{[0-9a-f]*}} 47# SEC-ORDER: 5 .strtab 00000008 {{[0-9a-f]*}} 48# SEC-ORDER: 6 .comment 00000008 {{[0-9a-f]*}} 49# SEC-ORDER: 7 .data 00000020 {{[0-9a-f]*}} DATA 50# SEC-ORDER: 8 .text 0000000e {{[0-9a-f]*}} TEXT 51 52# .text and .data have swapped names but proper sizes and types. 53# RUN: echo "SECTIONS { \ 54# RUN: .data : { *(.text) } \ 55# RUN: .text : { *(.data) } }" > %t.script 56# RUN: ld.lld -o %t4 --script %t.script %t 57# RUN: llvm-objdump --section-headers %t4 | \ 58# RUN: FileCheck -check-prefix=SEC-SWAP-NAMES %s 59 60# Idx Name Size 61# SEC-SWAP-NAMES: 1 .data 0000000e {{[0-9a-f]*}} TEXT 62# SEC-SWAP-NAMES: 2 .text 00000020 {{[0-9a-f]*}} DATA 63# SEC-SWAP-NAMES: 3 other 00000003 {{[0-9a-f]*}} DATA 64# SEC-SWAP-NAMES: 4 .bss 00000002 {{[0-9a-f]*}} BSS 65# SEC-SWAP-NAMES: 5 .comment 00000008 {{[0-9a-f]*}} 66# SEC-SWAP-NAMES: 6 .symtab 00000030 {{[0-9a-f]*}} 67# SEC-SWAP-NAMES: 7 .shstrtab 0000003b {{[0-9a-f]*}} 68# SEC-SWAP-NAMES: 8 .strtab 00000008 {{[0-9a-f]*}} 69 70# Multiple SECTIONS command specifying additional input section descriptions 71# for the same output section description - input sections are merged into 72# one output section. 73# RUN: echo "SECTIONS { \ 74# RUN: .text : { *(.text) } \ 75# RUN: .data : { *(.data) } } \ 76# RUN: SECTIONS { \ 77# RUN: .data : { *(other) } }" > %t.script 78# RUN: ld.lld -o %t6 --script %t.script %t 79# RUN: llvm-objdump --section-headers %t6 | \ 80# RUN: FileCheck -check-prefix=SEC-MULTI %s 81 82# Idx Name Size 83# SEC-MULTI: 1 .text 0000000e {{[0-9a-f]*}} TEXT 84# SEC-MULTI-NEXT: .data 00000020 {{[0-9a-f]*}} DATA 85# SEC-MULTI-NEXT: .data 00000003 {{[0-9a-f]*}} DATA 86# SEC-MULTI-NEXT: .bss 00000002 {{[0-9a-f]*}} BSS 87# SEC-MULTI-NEXT: .comment 00000008 {{[0-9a-f]*}} 88# SEC-MULTI-NEXT: .symtab 00000030 {{[0-9a-f]*}} 89# SEC-MULTI-NEXT: .shstrtab 00000035 {{[0-9a-f]*}} 90# SEC-MULTI-NEXT: .strtab 00000008 {{[0-9a-f]*}} 91 92# Input section pattern contains additional semicolon. 93# Case found in linux kernel script. Check we are able to parse it. 94# RUN: echo "SECTIONS { .text : { ;;*(.text);;S = 0;; } }" > %t.script 95# RUN: ld.lld -o /dev/null --script %t.script %t 96 97.globl _start 98_start: 99 mov $60, %rax 100 mov $42, %rdi 101 102.section .data,"aw" 103.quad 10, 10, 20, 20 104.section other,"aw" 105.short 10 106.byte 20 107.section .bss,"",@nobits 108.short 0 109