202 lines · plain
1# REQUIRES: ppc2 3# RUN: rm -rf %t.dir4# RUN: split-file %s %t.dir5# RUN: cd %t.dir6 7## Object files.8# RUN: llvm-mc -triple=powerpc64le -filetype=obj ref.s -o 1.o9# RUN: llvm-mc -triple=powerpc64le -filetype=obj refanddef.s -o 2.o10# RUN: llvm-mc -triple=powerpc64le -filetype=obj def.s -o strong_data_only.o11# RUN: llvm-mc -triple=powerpc64le -filetype=obj weak.s -o weak_data_only.o12 13# RUN: llvm-mc -triple=powerpc64le -filetype=obj main.s -o main.o14 15## Object file archives.16# RUN: llvm-ar crs 1.a 1.o strong_data_only.o17# RUN: llvm-ar crs 2.a 1.o weak_data_only.o18# RUN: llvm-ar crs 3.a 2.o strong_data_only.o19 20## Bitcode files.21# RUN: llvm-as -o 1.bc commonblock.ll22# RUN: llvm-as -o 2.bc blockdata.ll23# RUN: llvm-as -o 3.bc weak.ll24 25## Bitcode archive.26# RUN: llvm-ar crs 4.a 1.bc 2.bc27 28# RUN: ld.lld -o 1 main.o 1.a --fortran-common29# RUN: llvm-objdump -D -j .data 1 | FileCheck --check-prefix=TEST1 %s30 31# RUN: ld.lld -o 2 main.o --start-lib 1.o strong_data_only.o --end-lib --fortran-common32# RUN: llvm-objdump -D -j .data 2 | FileCheck --check-prefix=TEST1 %s33 34# RUN: ld.lld -o 3 main.o 2.a35# RUN: llvm-objdump -t 3 | FileCheck --check-prefix=BSS %s36 37# RUN: ld.lld -o 4 main.o --start-lib 1.o weak_data_only.o --end-lib38# RUN: llvm-objdump -t 4 | FileCheck --check-prefix=BSS %s39 40# RUN: ld.lld -o 5 main.o 3.a --print-map | FileCheck --check-prefix=MAP %s41 42# RUN: ld.lld -o 6 main.o 2.o 1.a43# RUN: llvm-objdump -D -j .data 6 | FileCheck --check-prefix=TEST2 %s44 45# RUN: ld.lld -o 7 main.o 2.o --start-lib 1.o strong_data_only.o --end-lib46# RUN: llvm-objdump -D -j .data 7 | FileCheck --check-prefix=TEST2 %s47 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 %s50 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 %s53 54# ERR: ld.lld: error: duplicate symbol: block55 56# RUN: ld.lld --no-fortran-common -o 10 main.o 1.a57# RUN: llvm-readobj --syms 10 | FileCheck --check-prefix=NFC %s58# RUN: ld.lld -o 10 main.o 1.a59# RUN: llvm-readobj --syms 10 | FileCheck --check-prefix=NFC %s60 61# RUN: ld.lld --no-fortran-common -o 11 main.o --start-lib 1.o strong_data_only.o --end-lib62# RUN: llvm-readobj --syms 11 | FileCheck --check-prefix=NFC %s63 64# RUN: ld.lld -o out main.o 4.a --fortran-common --lto-emit-asm65# RUN: FileCheck --check-prefix=ASM %s < out.lto.s66 67# RUN: rm out.lto.s68# RUN: ld.lld -o out main.o --start-lib 1.bc 2.bc --end-lib --fortran-common --lto-emit-asm69# RUN: FileCheck --check-prefix=ASM %s < out.lto.s70 71## COMMON overrides weak. Don't extract 3.bc which provides a weak definition.72# RUN: ld.lld main.o --start-lib 1.bc 3.bc --end-lib -y block | FileCheck --check-prefix=LTO_WEAK %s73 74## Old FORTRAN that mixes use of COMMON blocks and BLOCK DATA requires that we75## search through archives for non-tentative definitions (from the BLOCK DATA)76## to replace the tentative definitions (from the COMMON block(s)).77 78## Ensure we have used the initialized definition of 'block' instead of a79## common definition.80# TEST1-LABEL: Disassembly of section .data:81# TEST1: <block>:82# TEST1-NEXT: ea 2e 44 5483# TEST1-NEXT: fb 21 09 4084# TEST1-NEXT: ...85 86# BSS: [[#%x,]] g O .bss 0000000000000028 block87 88# NFC: Name: block89# NFC-NEXT: Value:90# NFC-NEXT: Size: 4091# NFC-NEXT: Binding: Global (0x1)92# NFC-NEXT: Type: Object (0x1)93# NFC-NEXT: Other: 094# NFC-NEXT: Section: .bss95 96## Expecting the strong definition from the object file, and the definitions from97## the archive do not interfere.98# TEST2-LABEL: Disassembly of section .data:99# TEST2: <block>:100# TEST2-NEXT: 03 57 14 8b101# TEST2-NEXT: 0a bf 05 40102# TEST2-NEXT: ...103 104# MAP: 28 8 3.a(2.o):(.data)105# MAP-NEXT: 28 1 block106 107# ASM: .type block,@object108# ASM: block:109# ASM-NEXT: .long 5110# ASM: .size block, 20111 112# LTO_WEAK: 1.bc: common definition of block113# LTO_WEAK: <internal>: reference to block114# LTO_WEAK-NOT: {{.}}115 116#--- ref.s117 .text118 .abiversion 2119 .global bar120 .type bar,@function121bar:122 addis 4, 2, block@toc@ha123 addi 4, 4, block@toc@l124 125## Tentative definition of 'block'.126 .comm block,40,8127 128#--- refanddef.s129## An alternate strong definition of block, in the same file as130## a different referenced symbol.131 .text132 .abiversion 2133 .global bar134 .type bar,@function135bar:136 addis 4, 2, block@toc@ha137 addi 4, 4, block@toc@l138 139 .data140 .type block,@object141 .global block142 .p2align 3143block:144 .quad 0x4005bf0a8b145703 # double 2.7182818284589998145 .space 32146 .size block, 40147 148#--- def.s149## Strong definition of 'block'.150 .data151 .type block,@object152 .global block153 .p2align 3154block:155 .quad 0x400921fb54442eea # double 3.1415926535900001156 .space 32157 .size block, 40158 159#--- weak.s160## Weak definition of `block`.161 .data162 .type block,@object163 .weak block164 .p2align 3165block:166 .quad 0x400921fb54442eea # double 3.1415926535900001167 .space 32168 .size block, 40169 170#--- main.s171 .global _start172_start:173 bl bar174 blr175 176 177#--- blockdata.ll178target datalayout = "e-m:e-Fn32-i64:64-n32:64-S128-v256:256:256-v512:512:512"179target triple = "powerpc64le-unknown-linux-gnu"180 181@block = dso_local local_unnamed_addr global [5 x i32] [i32 5, i32 0, i32 0, i32 0, i32 0], align 4182 183#--- weak.ll184target datalayout = "e-m:e-Fn32-i64:64-n32:64-S128-v256:256:256-v512:512:512"185target triple = "powerpc64le-unknown-linux-gnu"186 187@block = weak dso_local global [5 x i32] [i32 5, i32 0, i32 0, i32 0, i32 0], align 4188 189#--- commonblock.ll190target datalayout = "e-m:e-Fn32-i64:64-n32:64-S128-v256:256:256-v512:512:512"191target triple = "powerpc64le-unknown-linux-gnu"192 193@block = common dso_local local_unnamed_addr global [5 x i32] zeroinitializer, align 4194 195define dso_local i32 @bar(i32 signext %i) local_unnamed_addr {196entry:197 %idxprom = sext i32 %i to i64198 %arrayidx = getelementptr inbounds [5 x i32], ptr @block, i64 0, i64 %idxprom199 %0 = load i32, ptr %arrayidx, align 8200 ret i32 %0201}202