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