Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / common-archive-lookup.s
blob297d3d9b6f36ec9b66e6cf02e1aff3f6aeba2410
1 # REQUIRES: ppc
3 # RUN: rm -rf %t.dir
4 # RUN: split-file %s %t.dir
5 # RUN: cd %t.dir
7 ## Object files.
8 # RUN: llvm-mc -triple=powerpc64le -filetype=obj ref.s -o 1.o
9 # RUN: llvm-mc -triple=powerpc64le -filetype=obj refanddef.s -o 2.o
10 # RUN: llvm-mc -triple=powerpc64le -filetype=obj def.s -o strong_data_only.o
11 # RUN: llvm-mc -triple=powerpc64le -filetype=obj weak.s -o weak_data_only.o
13 # RUN: llvm-mc -triple=powerpc64le -filetype=obj main.s -o main.o
15 ## Object file archives.
16 # RUN: llvm-ar crs 1.a 1.o strong_data_only.o
17 # RUN: llvm-ar crs 2.a 1.o weak_data_only.o
18 # RUN: llvm-ar crs 3.a 2.o strong_data_only.o
20 ## Bitcode files.
21 # RUN: llvm-as -o 1.bc commonblock.ll
22 # RUN: llvm-as -o 2.bc blockdata.ll
23 # RUN: llvm-as -o 3.bc weak.ll
25 ## Bitcode archive.
26 # RUN: llvm-ar crs 4.a 1.bc 2.bc
28 # RUN: ld.lld -o 1 main.o 1.a --fortran-common
29 # RUN: llvm-objdump -D -j .data 1 | FileCheck --check-prefix=TEST1 %s
31 # RUN: ld.lld -o 2 main.o --start-lib 1.o strong_data_only.o --end-lib --fortran-common
32 # RUN: llvm-objdump -D -j .data 2 | FileCheck --check-prefix=TEST1 %s
34 # RUN: ld.lld -o 3 main.o 2.a
35 # RUN: llvm-objdump -t 3 | FileCheck --check-prefix=BSS %s
37 # RUN: ld.lld -o 4 main.o --start-lib 1.o weak_data_only.o --end-lib
38 # RUN: llvm-objdump -t 4 | FileCheck --check-prefix=BSS %s
40 # RUN: ld.lld -o 5 main.o 3.a --print-map | FileCheck --check-prefix=MAP %s
42 # RUN: ld.lld -o 6 main.o 2.o 1.a
43 # RUN: llvm-objdump -D -j .data 6 | FileCheck --check-prefix=TEST2 %s
45 # RUN: ld.lld -o 7 main.o 2.o --start-lib 1.o strong_data_only.o --end-lib
46 # RUN: llvm-objdump -D -j .data 7 | FileCheck --check-prefix=TEST2 %s
48 # RUN: not ld.lld -o 8 main.o 1.a strong_data_only.o --fortran-common 2>&1 | \
49 # RUN: FileCheck --check-prefix=ERR %s
51 # RUN: not ld.lld -o 9 main.o --start-lib 1.o 2.o --end-lib strong_data_only.o --fortran-common 2>&1 | \
52 # RUN: FileCheck --check-prefix=ERR %s
54 # ERR: ld.lld: error: duplicate symbol: block
56 # RUN: ld.lld --no-fortran-common -o 10 main.o 1.a
57 # RUN: llvm-readobj --syms 10 | FileCheck --check-prefix=NFC %s
58 # RUN: ld.lld -o 10 main.o 1.a
59 # RUN: llvm-readobj --syms 10 | FileCheck --check-prefix=NFC %s
61 # RUN: ld.lld --no-fortran-common -o 11 main.o --start-lib 1.o strong_data_only.o --end-lib
62 # RUN: llvm-readobj --syms 11 | FileCheck --check-prefix=NFC %s
64 # RUN: ld.lld -o - main.o 4.a --fortran-common --lto-emit-asm | FileCheck --check-prefix=ASM %s
66 # RUN: ld.lld -o - main.o --start-lib 1.bc 2.bc --end-lib --fortran-common --lto-emit-asm | \
67 # RUN: FileCheck --check-prefix=ASM %s
69 ## COMMON overrides weak. Don't extract 3.bc which provides a weak definition.
70 # RUN: ld.lld -o /dev/null main.o --start-lib 1.bc 3.bc --end-lib -y block | FileCheck --check-prefix=LTO_WEAK %s
72 ## Old FORTRAN that mixes use of COMMON blocks and BLOCK DATA requires that we
73 ## search through archives for non-tentative definitions (from the BLOCK DATA)
74 ## to replace the tentative definitions (from the COMMON block(s)).
76 ## Ensure we have used the initialized definition of 'block' instead of a
77 ## common definition.
78 # TEST1-LABEL: Disassembly of section .data:
79 # TEST1: <block>:
80 # TEST1-NEXT: ea 2e 44 54
81 # TEST1-NEXT: fb 21 09 40
82 # TEST1-NEXT: ...
84 # BSS: [[#%x,]] g O .bss 0000000000000028 block
86 # NFC: Name: block
87 # NFC-NEXT: Value:
88 # NFC-NEXT: Size: 40
89 # NFC-NEXT: Binding: Global (0x1)
90 # NFC-NEXT: Type: Object (0x1)
91 # NFC-NEXT: Other: 0
92 # NFC-NEXT: Section: .bss
94 ## Expecting the strong definition from the object file, and the definitions from
95 ## the archive do not interfere.
96 # TEST2-LABEL: Disassembly of section .data:
97 # TEST2: <block>:
98 # TEST2-NEXT: 03 57 14 8b
99 # TEST2-NEXT: 0a bf 05 40
100 # TEST2-NEXT: ...
102 # MAP: 28 8 3.a(2.o):(.data)
103 # MAP-NEXT: 28 1 block
105 # ASM: .type block,@object
106 # ASM: block:
107 # ASM-NEXT: .long 5
108 # ASM: .size block, 20
110 # LTO_WEAK: 1.bc: common definition of block
111 # LTO_WEAK: <internal>: reference to block
112 # LTO_WEAK-NOT: {{.}}
114 #--- ref.s
115 .text
116 .abiversion 2
117 .global bar
118 .type bar,@function
119 bar:
120 addis 4, 2, block@toc@ha
121 addi 4, 4, block@toc@l
123 ## Tentative definition of 'block'.
124 .comm block,40,8
126 #--- refanddef.s
127 ## An alternate strong definition of block, in the same file as
128 ## a different referenced symbol.
129 .text
130 .abiversion 2
131 .global bar
132 .type bar,@function
133 bar:
134 addis 4, 2, block@toc@ha
135 addi 4, 4, block@toc@l
137 .data
138 .type block,@object
139 .global block
140 .p2align 3
141 block:
142 .quad 0x4005bf0a8b145703 # double 2.7182818284589998
143 .space 32
144 .size block, 40
146 #--- def.s
147 ## Strong definition of 'block'.
148 .data
149 .type block,@object
150 .global block
151 .p2align 3
152 block:
153 .quad 0x400921fb54442eea # double 3.1415926535900001
154 .space 32
155 .size block, 40
157 #--- weak.s
158 ## Weak definition of `block`.
159 .data
160 .type block,@object
161 .weak block
162 .p2align 3
163 block:
164 .quad 0x400921fb54442eea # double 3.1415926535900001
165 .space 32
166 .size block, 40
168 #--- main.s
169 .global _start
170 _start:
171 bl bar
175 #--- blockdata.ll
176 target datalayout = "e-m:e-Fn32-i64:64-n32:64-S128-v256:256:256-v512:512:512"
177 target triple = "powerpc64le-unknown-linux-gnu"
179 @block = dso_local local_unnamed_addr global [5 x i32] [i32 5, i32 0, i32 0, i32 0, i32 0], align 4
181 #--- weak.ll
182 target datalayout = "e-m:e-Fn32-i64:64-n32:64-S128-v256:256:256-v512:512:512"
183 target triple = "powerpc64le-unknown-linux-gnu"
185 @block = weak dso_local global [5 x i32] [i32 5, i32 0, i32 0, i32 0, i32 0], align 4
187 #--- commonblock.ll
188 target datalayout = "e-m:e-Fn32-i64:64-n32:64-S128-v256:256:256-v512:512:512"
189 target triple = "powerpc64le-unknown-linux-gnu"
191 @block = common dso_local local_unnamed_addr global [5 x i32] zeroinitializer, align 4
193 define dso_local i32 @bar(i32 signext %i) local_unnamed_addr {
194 entry:
195 %idxprom = sext i32 %i to i64
196 %arrayidx = getelementptr inbounds [5 x i32], ptr @block, i64 0, i64 %idxprom
197 %0 = load i32, ptr %arrayidx, align 8
198 ret i32 %0