[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / input-section-flags.s
blob0c8e31c77b0dc61cbc52b4a55b92147fb0451512
1 # REQUIRES: x86
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
21 # CHECK: Name: _start
22 # CHECK: Section: .outsec2
23 # CHECK: Name: s1
24 # CHECK: Section: .outsec1
25 # CHECK: Name: s2
26 # CHECK: Section: .outsec2
27 # CHECK: Name: s3
28 # CHECK: Section: .outsec3
29 # CHECK: Name: s4
30 # CHECK: Section: .outsec4
31 # CHECK: Name: s5
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
63 ## OutputSection
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
76 # MULTIPLE: Name: s1
77 # MULTIPLE: Section: .outsec1
78 # MULTIPLE: Name: s2
79 # MULTIPLE: Section: .outsec1
80 # MULTIPLE: Name: s3
81 # MULTIPLE: Section: .sec.aw
82 # MULTIPLE: Name: s4
83 # MULTIPLE: Section: .sec.aM
84 # MULTIPLE: Name: s5
85 # MULTIPLE: Section: .sec.aMS
87 .text
88 .global _start
89 _start:
90 nop
92 .section .sec.a, "a", @progbits
93 .globl s1
94 s1:
95 .long 1
97 .section .sec.ax, "ax", @progbits
98 .globl s2
99 s2:
100 .long 2
102 .section .sec.aw, "aw", @progbits
103 .globl s3
105 .long 3
107 .section .sec.aM, "aM", @progbits, 4
108 .globl s4
110 .long 4
112 .section .sec.aMS, "aMS", @progbits, 1
113 .globl s5
115 .asciz "a"