[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / symbol-ordering-file-warnings.s
blobe4611e4031aab3147597db72794f3e22913b8b10
1 # REQUIRES: x86
2 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/symbol-ordering-file-warnings1.s -o %t2.o
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/symbol-ordering-file-warnings2.s -o %t3.o
5 # RUN: ld.lld -shared %t2.o -o %t.so
7 # Check that a warning is emitted for entries in the file that are not present in any used input.
8 # RUN: echo "missing" > %t-order-missing.txt
9 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-missing.txt \
10 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,MISSING
12 # Check that the warning can be disabled.
13 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-missing.txt \
14 # RUN: --unresolved-symbols=ignore-all --no-warn-symbol-ordering 2>&1 | \
15 # RUN: FileCheck %s --check-prefixes=WARN --allow-empty
17 # Check that the warning can be re-enabled
18 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-missing.txt \
19 # RUN: --unresolved-symbols=ignore-all --no-warn-symbol-ordering --warn-symbol-ordering 2>&1 | \
20 # RUN: FileCheck %s --check-prefixes=WARN,MISSING
22 # Check that a warning is emitted for imported shared symbols.
23 # RUN: echo "shared" > %t-order-shared.txt
24 # RUN: ld.lld %t1.o %t.so -o %t --symbol-ordering-file %t-order-shared.txt \
25 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,SHARED
27 # Check that a warning is emitted for absolute symbols.
28 # RUN: echo "absolute" > %t-order-absolute.txt
29 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-absolute.txt \
30 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,ABSOLUTE
32 # Check that a warning is emitted for symbols discarded due to --gc-sections.
33 # RUN: echo "gc" > %t-order-gc.txt
34 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-gc.txt --gc-sections \
35 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,GC
37 # Check that a warning is not emitted for the symbol removed due to --icf.
38 # RUN: echo "icf1" > %t-order-icf.txt
39 # RUN: echo "icf2" >> %t-order-icf.txt
40 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-icf.txt --icf=all \
41 # RUN: --unresolved-symbols=ignore-all --fatal-warnings
43 # RUN: echo "_GLOBAL_OFFSET_TABLE_" > %t-order-synthetic.txt
44 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-synthetic.txt --icf=all \
45 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,SYNTHETIC
47 # Check that a warning is emitted for symbols discarded due to a linker script /DISCARD/ section.
48 # RUN: echo "discard" > %t-order-discard.txt
49 # RUN: echo "SECTIONS { /DISCARD/ : { *(.text.discard) } }" > %t.script
50 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-discard.txt -T %t.script \
51 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,DISCARD
53 # Check that LLD does not warn for discarded COMDAT symbols, if they are present in the kept instance.
54 # RUN: echo "comdat" > %t-order-comdat.txt
55 # RUN: ld.lld %t1.o %t2.o -o %t --symbol-ordering-file %t-order-comdat.txt \
56 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN --allow-empty
58 # Check that if a COMDAT was unused and discarded via --gc-sections, warn for each instance.
59 # RUN: ld.lld %t1.o %t2.o -o %t --symbol-ordering-file %t-order-comdat.txt --gc-sections \
60 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,COMDAT
62 # Check that if a weak symbol is not kept, because of an equivalent global symbol, no warning is emitted.
63 # RUN: echo "glob_or_wk" > %t-order-weak.txt
64 # RUN: ld.lld %t1.o %t2.o -o %t --symbol-ordering-file %t-order-weak.txt \
65 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN --allow-empty
67 # Check that symbols only in unused archive members does not result in a warning.
68 # RUN: rm -f %t.a
69 # RUN: llvm-ar rc %t.a %t3.o
70 # RUN: ld.lld %t1.o %t.a -o %t --symbol-ordering-file %t-order-missing.txt \
71 # RUN: --unresolved-symbols=ignore-all 2>&1 | count 0
73 # Check that a warning for each same-named symbol with an issue.
74 # RUN: echo "multi" > %t-order-same-name.txt
75 # RUN: ld.lld %t1.o %t2.o %t3.o -o %t --symbol-ordering-file %t-order-same-name.txt \
76 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,MULTI
78 # Check that a warning is emitted if the same symbol is mentioned multiple times in the ordering file.
79 # RUN: echo "_start" > %t-order-multiple-same.txt
80 # RUN: echo "_start" >> %t-order-multiple-same.txt
81 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-multiple-same.txt \
82 # RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,SAMESYM
84 # Check that all warnings can be emitted from the same input.
85 # RUN: echo "missing_sym" > %t-order-multi.txt
86 # RUN: echo "undefined" >> %t-order-multi.txt
87 # RUN: echo "_start" >> %t-order-multi.txt
88 # RUN: echo "shared" >> %t-order-multi.txt
89 # RUN: echo "absolute" >> %t-order-multi.txt
90 # RUN: echo "gc" >> %t-order-multi.txt
91 # RUN: echo "discard" >> %t-order-multi.txt
92 # RUN: echo "_GLOBAL_OFFSET_TABLE_" >> %t-order-multi.txt
93 # RUN: echo "_start" >> %t-order-multi.txt
94 # RUN: ld.lld %t1.o %t3.o %t.so -o %t --symbol-ordering-file %t-order-multi.txt --gc-sections -T %t.script \
95 # RUN: 2>&1 | FileCheck %s --check-prefixes=WARN,SAMESYM,ABSOLUTE,SHARED,UNDEFINED,GC,DISCARD,MISSING2,SYNTHETIC
97 # WARN-NOT: warning:
98 # SAMESYM: warning: {{.*}}.txt: duplicate ordered symbol: _start
99 # WARN-NOT: warning:
100 # SHARED: warning: {{.*}}.so: unable to order shared symbol: shared
101 # WARN-NOT: warning:
102 # DISCARD: warning: {{.*}}1.o: unable to order discarded symbol: discard
103 # WARN-NOT: warning:
104 # GC: warning: {{.*}}1.o: unable to order discarded symbol: gc
105 # WARN-NOT: warning:
106 # SYNTHETIC: warning: <internal>: unable to order synthetic symbol: _GLOBAL_OFFSET_TABLE_
107 # WARN-NOT: warning:
108 # UNDEFINED: warning: {{.*}}3.o: unable to order undefined symbol: undefined
109 # WARN-NOT: warning:
110 # ABSOLUTE: warning: {{.*}}1.o: unable to order absolute symbol: absolute
111 # WARN-NOT: warning:
112 # MISSING: warning: symbol ordering file: no such symbol: missing
113 # WARN-NOT: warning:
114 # MISSING2: warning: symbol ordering file: no such symbol: missing_sym
115 # WARN-NOT: warning:
116 # COMDAT: warning: {{.*}}1.o: unable to order discarded symbol: comdat
117 # WARN-NOT: warning:
118 # MULTI: warning: {{.*}}2.o: unable to order absolute symbol: multi
119 # WARN-NOT: warning:
121 .section .text._start,"ax",@progbits
122 .global _start
123 _start:
124 movq %rax, absolute
125 callq shared
127 absolute = 0x1234
129 .section .text.comdat,"axG",@progbits,comdat,comdat
130 .weak comdat
131 comdat:
134 .section .text.discard,"ax",@progbits
135 .global discard
136 discard:
139 .section .text.gc,"ax",@progbits
140 .global gc
144 .section .text.glob_or_wk,"ax",@progbits
145 .weak glob_or_wk
146 glob_or_wk:
149 .section .text.icf1,"ax",@progbits
150 .global icf1
151 icf1:
154 .section .text.icf2,"ax",@progbits
155 .global icf2
156 icf2:
159 # This is a "good" instance of the symbol
160 .section .text.multi,"ax",@progbits
161 multi:
162 .quad _GLOBAL_OFFSET_TABLE_