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