2 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
4 ## Test the INPUT_SECTION_FLAGS feature. It prefixes an input section list and
5 ## restricts matches to sections that have the required flags and do not have
6 ## any of the must not have flags.
8 ## Uniquely identify each .sec section by flag alone, with .text going into
9 ## to the SHF_EXECINSTR requiring .outsec2
10 # RUN: echo "SECTIONS { \
11 # RUN: .outsec1 : { INPUT_SECTION_FLAGS(SHF_ALLOC & !SHF_EXECINSTR & \
12 # RUN: !SHF_WRITE & !SHF_MERGE) *(.sec.*) } \
13 # RUN: .outsec2 : { INPUT_SECTION_FLAGS(SHF_ALLOC & SHF_EXECINSTR & !SHF_WRITE\
14 # RUN: & !SHF_MERGE) *(.sec.* .text) } \
15 # RUN: .outsec3 : { INPUT_SECTION_FLAGS(SHF_WRITE) *(.sec.*) } \
16 # RUN: .outsec4 : { INPUT_SECTION_FLAGS(SHF_MERGE & !SHF_STRINGS) *(.sec.*) } \
17 # RUN: .outsec5 : { INPUT_SECTION_FLAGS(SHF_STRINGS) *(.sec.*) } \
18 # RUN: } " > %t.script
19 # RUN: ld.lld -o %t1 --script %t.script %t.o
20 # RUN: llvm-readobj --symbols %t1 | FileCheck %s
22 # CHECK: Section: .outsec2
24 # CHECK: Section: .outsec1
26 # CHECK: Section: .outsec2
28 # CHECK: Section: .outsec3
30 # CHECK: Section: .outsec4
32 # CHECK: Section: .outsec5
34 ## Same test but using OVERLAY.
35 # RUN: echo "SECTIONS { \
36 # RUN: OVERLAY 0x1000 : AT ( 0x4000 ) { \
37 # RUN: .outsec1 { INPUT_SECTION_FLAGS(SHF_ALLOC & !SHF_EXECINSTR & \
38 # RUN: !SHF_WRITE & !SHF_MERGE) *(.sec.*) }\
39 # RUN: .outsec2 { INPUT_SECTION_FLAGS(SHF_ALLOC & SHF_EXECINSTR & !SHF_WRITE \
40 # RUN: & !SHF_MERGE) *(.sec.* .text) } \
41 # RUN: .outsec3 { INPUT_SECTION_FLAGS(SHF_WRITE) *(.sec.*) } \
42 # RUN: .outsec4 { INPUT_SECTION_FLAGS(SHF_MERGE & !SHF_STRINGS) *(.sec.*) } \
43 # RUN: .outsec5 { INPUT_SECTION_FLAGS(SHF_STRINGS) *(.sec.*) } \
44 # RUN: } } " > %t2.script
46 # RUN: ld.lld -o %t2 --script %t2.script %t.o
47 # RUN: llvm-readobj --symbols %t2 | FileCheck %s
49 ## Same test but using hex representations of the flags.
50 # RUN: echo "SECTIONS { \
51 # RUN: .outsec1 : { INPUT_SECTION_FLAGS(0x2 & !0x4 & !0x1 & !0x10) *(.sec.*) }\
52 # RUN: .outsec2 : { INPUT_SECTION_FLAGS(0x2 & 0x4 & !0x1 & !0x10) \
53 # RUN: *(.sec.* .text) } \
54 # RUN: .outsec3 : { INPUT_SECTION_FLAGS(0x1) *(.sec.*) } \
55 # RUN: .outsec4 : { INPUT_SECTION_FLAGS(0x10 & !0x20) *(.sec.*) } \
56 # RUN: .outsec5 : { INPUT_SECTION_FLAGS(0x20) *(.sec.*) } \
57 # RUN: } " > %t3.script
59 # RUN: ld.lld -o %t3 --script %t3.script %t.o
60 # RUN: llvm-readobj --symbols %t3 | FileCheck %s
62 ## Check that we can handle multiple InputSectionDescriptions in a single
64 # RUN: echo "SECTIONS { \
65 # RUN: .outsec1 : { INPUT_SECTION_FLAGS(SHF_ALLOC & !SHF_EXECINSTR & \
66 # RUN: !SHF_WRITE & !SHF_MERGE) *(.sec.*) ; \
67 # RUN: INPUT_SECTION_FLAGS(SHF_ALLOC & SHF_EXECINSTR & !SHF_WRITE\
68 # RUN: & !SHF_MERGE) *(.sec.* *.text) }\
69 # RUN: } " > %t4.script
71 # RUN: ld.lld -o %t4 --script %t4.script %t.o
72 # RUN: llvm-readobj --symbols %t4 | FileCheck --check-prefix MULTIPLE %s
74 # MULTIPLE: Name: _start
75 # MULTIPLE: Section: .outsec1
77 # MULTIPLE: Section: .outsec1
79 # MULTIPLE: Section: .outsec1
81 # MULTIPLE: Section: .sec.aw
83 # MULTIPLE: Section: .sec.aM
85 # MULTIPLE: Section: .sec.aMS
92 .section .sec.a, "a", @progbits
97 .section .sec.ax, "ax", @progbits
102 .section .sec.aw, "aw", @progbits
107 .section .sec.aM, "aM", @progbits, 4
112 .section .sec.aMS, "aMS", @progbits, 1