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.
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
98 # SAMESYM: warning: {{.*}}.txt: duplicate ordered symbol: _start
100 # SHARED: warning: {{.*}}.so: unable to order shared symbol: shared
102 # DISCARD: warning: {{.*}}1.o: unable to order discarded symbol: discard
104 # GC: warning: {{.*}}1.o: unable to order discarded symbol: gc
106 # SYNTHETIC: warning: <internal>: unable to order synthetic symbol: _GLOBAL_OFFSET_TABLE_
108 # UNDEFINED: warning: {{.*}}3.o: unable to order undefined symbol: undefined
110 # ABSOLUTE: warning: {{.*}}1.o: unable to order absolute symbol: absolute
112 # MISSING: warning: symbol ordering file: no such symbol: missing
114 # MISSING2: warning: symbol ordering file: no such symbol: missing_sym
116 # COMDAT: warning: {{.*}}1.o: unable to order discarded symbol: comdat
118 # MULTI: warning: {{.*}}2.o: unable to order absolute symbol: multi
121 .section .text._start,"ax",@progbits
129 .section .text.comdat,"axG",@progbits,comdat,comdat
134 .section .text.discard,"ax",@progbits
139 .section .text.gc,"ax",@progbits
144 .section .text.glob_or_wk,"ax",@progbits
149 .section .text.icf1,"ax",@progbits
154 .section .text.icf2,"ax",@progbits
159 # This is a "good" instance of the symbol
160 .section .text.multi,"ax",@progbits
162 .quad _GLOBAL_OFFSET_TABLE_