1# REQUIRES: ppc
2
3# RUN: rm -rf %t.dir
4# RUN: split-file %s %t.dir
5# RUN: cd %t.dir
6
7## Object files.
8# RUN: llvm-mc -triple=powerpc64le -filetype=obj ref.s -o %t1.o
9# RUN: llvm-mc -triple=powerpc64le -filetype=obj refanddef.s -o %t2.o
10# RUN: llvm-mc -triple=powerpc64le -filetype=obj def.s -o %tstrong_data_only.o
11# RUN: llvm-mc -triple=powerpc64le -filetype=obj weak.s -o %tweak_data_only.o
12
13# RUN: llvm-mc -triple=powerpc64le -filetype=obj main.s -o %tmain.o
14
15## Object file archives.
16# RUN: llvm-ar crs %t1.a %t1.o %tstrong_data_only.o
17# RUN: llvm-ar crs %t2.a %t1.o %tweak_data_only.o
18# RUN: llvm-ar crs %t3.a %t2.o %tstrong_data_only.o
19
20## Bitcode files.
21# RUN: llvm-as -o %t1.bc commonblock.ll
22# RUN: llvm-as -o %t2.bc blockdata.ll
23
24## Bitcode archive.
25# RUN: llvm-ar crs %t4.a %t1.bc %t2.bc
26
27# RUN: ld.lld -o %t1 %tmain.o %t1.a
28# RUN: llvm-objdump -D -j .data %t1 | FileCheck --check-prefix=TEST1 %s
29
30# RUN: ld.lld -o %t2 %tmain.o --start-lib %t1.o %tstrong_data_only.o --end-lib
31# RUN: llvm-objdump -D -j .data %t2 | FileCheck --check-prefix=TEST1 %s
32
33# RUN: ld.lld -o %t3 %tmain.o %t2.a
34# RUN: llvm-objdump -D -j .data %t3 | FileCheck --check-prefix=TEST1 %s
35
36# RUN: ld.lld -o %t4 %tmain.o --start-lib %t1.o %tweak_data_only.o --end-lib
37# RUN: llvm-objdump -D -j .data %t4 | FileCheck --check-prefix=TEST1 %s
38
39# RUN: ld.lld -o %t5 %tmain.o %t3.a --print-map | FileCheck --check-prefix=MAP %s
40
41# RUN: ld.lld -o %t6 %tmain.o %t2.o %t1.a
42# RUN: llvm-objdump -D -j .data %t6 | FileCheck --check-prefix=TEST2 %s
43
44# RUN: ld.lld -o %t7 %tmain.o %t2.o --start-lib %t1.o %tstrong_data_only.o --end-lib
45# RUN: llvm-objdump -D -j .data %t7 | FileCheck --check-prefix=TEST2 %s
46
47# RUN: not ld.lld -o %t8 %tmain.o %t1.a %tstrong_data_only.o 2>&1 | \
48# RUN:   FileCheck --check-prefix=ERR %s
49
50# RUN: not ld.lld -o %t9 %tmain.o --start-lib %t1.o %t2.o --end-lib  %tstrong_data_only.o 2>&1 | \
51# RUN:   FileCheck --check-prefix=ERR %s
52
53# ERR: ld.lld: error: duplicate symbol: block
54
55# RUN: ld.lld --no-fortran-common -o %t10 %tmain.o %t1.a
56# RUN: llvm-readobj --syms %t10 | FileCheck --check-prefix=NFC %s
57
58# RUN: ld.lld --no-fortran-common -o %t11 %tmain.o --start-lib %t1.o %tstrong_data_only.o --end-lib
59# RUN: llvm-readobj --syms %t11 | FileCheck --check-prefix=NFC %s
60
61# RUN: ld.lld -o - %tmain.o %t4.a --lto-emit-asm | FileCheck --check-prefix=ASM %s
62
63# RUN: ld.lld -o - %tmain.o  --start-lib %t1.bc %t2.bc --end-lib --lto-emit-asm | \
64# RUN:   FileCheck --check-prefix=ASM %s
65
66## Old FORTRAN that mixes use of COMMON blocks and BLOCK DATA requires that we
67## search through archives for non-tentative definitions (from the BLOCK DATA)
68## to replace the tentative definitions (from the COMMON block(s)).
69
70## Ensure we have used the initialized definition of 'block' instead of a
71## common definition.
72# TEST1-LABEL:  Disassembly of section .data:
73# TEST1:          <block>:
74# TEST1-NEXT:       ea 2e 44 54
75# TEST1-NEXT:       fb 21 09 40
76# TEST1-NEXT:       ...
77
78
79# NFC:       Name: block
80# NFC-NEXT:  Value:
81# NFC-NEXT:  Size: 40
82# NFC-NEXT:  Binding: Global (0x1)
83# NFC-NEXT:  Type: Object (0x1)
84# NFC-NEXT:  Other: 0
85# NFC-NEXT:  Section: .bss
86
87## Expecting the strong definition from the object file, and the defintions from
88## the archive do not interfere.
89# TEST2-LABEL: Disassembly of section .data:
90# TEST2:         <block>:
91# TEST2-NEXT:     03 57 14 8b
92# TEST2-NEXT:     0a bf 05 40
93# TEST2-NEXT:     ...
94
95# MAP:       28 8 {{.*}}tmp3.a(common-archive-lookup.s.tmp2.o):(.data)
96# MAP-NEXT:  28 1 block
97
98# ASM:         .type   block,@object
99# ASM:       block:
100# ASM-NEXT:    .long 5
101# ASM:         .size   block, 20
102
103#--- ref.s
104  .text
105  .abiversion 2
106  .global bar
107  .type bar,@function
108bar:
109  addis 4, 2, block@toc@ha
110  addi  4, 4, block@toc@l
111
112## Tentative definition of 'block'.
113  .comm block,40,8
114
115#--- refanddef.s
116## An alternate strong definition of block, in the same file as
117## a different referenced symbol.
118  .text
119  .abiversion 2
120  .global bar
121  .type bar,@function
122bar:
123  addis 4, 2, block@toc@ha
124  addi  4, 4, block@toc@l
125
126  .data
127  .type block,@object
128  .global block
129  .p2align 3
130block:
131  .quad   0x4005bf0a8b145703              # double 2.7182818284589998
132  .space  32
133  .size   block, 40
134
135#--- def.s
136## Strong definition of 'block'.
137  .data
138  .type block,@object
139  .global block
140  .p2align 3
141block:
142  .quad   0x400921fb54442eea              # double 3.1415926535900001
143  .space  32
144  .size   block, 40
145
146#--- weak.s
147## Weak definition of `block`.
148  .data
149  .type block,@object
150  .weak block
151  .p2align 3
152block:
153  .quad   0x400921fb54442eea              # double 3.1415926535900001
154  .space  32
155  .size   block, 40
156
157#--- main.s
158  .global _start
159_start:
160  bl bar
161  blr
162
163
164#--- blockdata.ll
165target datalayout = "e-m:e-i64:64-n32:64-v256:256:256-v512:512:512"
166target triple = "powerpc64le-unknown-linux-gnu"
167
168@block = dso_local local_unnamed_addr global [5 x i32] [i32 5, i32 0, i32 0, i32 0, i32 0], align 4
169
170#--- commonblock.ll
171target datalayout = "e-m:e-i64:64-n32:64-v256:256:256-v512:512:512"
172target triple = "powerpc64le-unknown-linux-gnu"
173
174@block =  common dso_local local_unnamed_addr global [5 x i32] zeroinitializer, align 4
175
176define dso_local i32 @bar(i32 signext %i) local_unnamed_addr {
177entry:
178  %idxprom = sext i32 %i to i64
179  %arrayidx = getelementptr inbounds [5 x i32], [5 x i32]* @block, i64 0, i64 %idxprom
180  %0 = load i32, i32* %arrayidx, align 8
181  ret i32 %0
182}
183