1# REQUIRES: x86 2 3# RUN: rm -rf %t; split-file %s %t 4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t/main.o 5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/calls-foo.s -o %t/calls-foo.o 6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/1.s -o %t/1.o 7# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/2.s -o %t/2.o 8# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/common.s -o %t/common.o 9 10# RUN: echo "%t/1.o" > %t/filelist 11# RUN: echo "%t/2.o" >> %t/filelist 12 13# RUN: llvm-as %t/1.ll -o %t/1.bc 14# RUN: llvm-as %t/2.ll -o %t/2.bc 15 16## Neither 1.o nor 2.o is loaded. 17# RUN: %lld %t/main.o -o %t/out --start-lib %t/1.o %t/2.o --end-lib -why_load | count 0 18# RUN: %lld %t/main.o -o %t/out --start-lib -filelist %t/filelist --end-lib -why_load | count 0 19# RUN: llvm-readobj -s %t/out | FileCheck %s 20# CHECK-NOT: Name: _foo 21# CHECK-NOT: Name: _bar 22 23## _bar loads 2.o. The last --end-lib can be omitted. 24# RUN: %lld %t/main.o -o %t/out -u _bar --start-lib %t/1.o %t/2.o -t -why_load | FileCheck %s --check-prefix=CHECK2WHY 25# RUN: %lld %t/main.o -o %t/out -u _bar --start-lib -filelist %t/filelist -t -why_load | FileCheck %s --check-prefix=CHECK2WHY 26# RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=CHECK2 %s 27# CHECK2WHY: {{.*}}main.o 28# CHECK2WHY-NEXT: {{.*}}2.o 29# CHECK2WHY-NEXT: _bar forced load of {{.*}}2.o 30# CHECK2WHY-EMPTY: 31# CHECK2-NOT: Name: _foo 32# CHECK2: Name: _bar 33# CHECK2-NOT: Name: _foo 34 35## _foo loads 1.o. 1.o loads 2.o. 36# RUN: %lld %t/main.o -o %t/out -u _foo --start-lib %t/1.o %t/2.o -why_load | FileCheck %s --check-prefix=CHECK3WHY 37# RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=CHECK3 %s 38# RUN: %lld %t/main.o -o %t/out -u _foo --start-lib %t/2.o --end-lib --start-lib %t/1.o -why_load | FileCheck %s --check-prefix=CHECK3WHY 39# RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=CHECK3 %s 40# CHECK3WHY: _foo forced load of {{.*}}1.o 41# CHECK3WHY-NEXT: _bar forced load of {{.*}}2.o 42# CHECK3WHY-EMPTY: 43# CHECK3-DAG: Name: _foo 44# CHECK3-DAG: Name: _bar 45 46## Don't treat undefined _bar in 1.o as a lazy definition. 47# RUN: not %lld %t/main.o -u _bar --start-lib %t/1.o 2>&1 | FileCheck %s --check-prefix=CHECK4 48# CHECK4: error: undefined symbol: _bar 49 50# RUN: %lld %t/main.o -o %t/out -u _common --start-lib %t/common.o 51# RUN: llvm-readobj -s %t/out | FileCheck %s --check-prefix=COMMON1 52# COMMON1: Name: _common 53 54# RUN: %lld %t/main.o -o %t/out --start-lib %t/common.o 55# RUN: llvm-readobj -s %t/out | FileCheck %s --check-prefix=COMMON2 56# COMMON2-NOT: Name: _common 57 58## Neither 1.bc nor 2.bc is loaded. 59# RUN: %lld %t/main.o -o %t/out --start-lib %t/1.bc %t/2.bc -why_load | count 0 60# RUN: llvm-readobj -s %t/out | FileCheck %s --check-prefix=BITCODE 61# BITCODE-NOT: Name: _foo 62# BITCODE-NOT: Name: _bar 63 64## _bar loads 2.bc. 65# RUN: %lld %t/main.o -o %t/out -u _bar --start-lib %t/1.bc %t/2.bc -why_load | FileCheck %s --check-prefix=BITCODE2WHY 66# RUN: llvm-readobj -s %t/out | FileCheck %s --check-prefix=BITCODE2 67# BITCODE2WHY: _bar forced load of {{.*}}2.bc 68# BITCODE2WHY-EMPTY: 69# BITCODE2-NOT: Name: _foo 70# BITCODE2: Name: _bar 71# BITCODE2-NOT: Name: _foo 72 73## calls-foo.o loads 1.bc. 1.bc loads 2.bc. 74# RUN: %lld %t/calls-foo.o -o %t/out --start-lib %t/1.bc %t/2.bc -why_load | FileCheck %s --check-prefix=BITCODE3WHY 75# RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=BITCODE3 %s 76# RUN: %lld %t/calls-foo.o -o %t/out --start-lib %t/2.bc --end-lib --start-lib %t/1.bc -why_load | FileCheck %s --check-prefix=BITCODE3WHY 77# RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=BITCODE3 %s 78# BITCODE3WHY: _foo forced load of {{.*}}1.bc 79# BITCODE3WHY-NEXT: _bar forced load of {{.*}}2.bc 80# BITCODE3WHY-EMPTY: 81# BITCODE3-DAG: Name: _foo 82 83# RUN: not %lld %t/main.o --start-lib --start-lib 2>&1 | FileCheck -check-prefix=NESTED-LIB %s 84# NESTED-LIB: error: nested --start-lib 85 86# RUN: not %lld --end-lib 2>&1 | FileCheck %s --check-prefix=STRAY 87# STRAY: error: stray --end-lib 88 89# RUN: %lld -dylib --start-lib %t/1.bc %t/2.o --end-lib -all_load -o %t/out 90# RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=ALL-LOAD %s 91# ALL-LOAD-DAG: _foo 92# ALL-LOAD-DAG: _bar 93 94#--- main.s 95.globl _main 96_main: 97 98#--- calls-foo.s 99.globl _main 100_main: 101 call _foo 102 103#--- 1.s 104.globl _foo 105_foo: 106 call _bar 107 108#--- 2.s 109.globl _bar 110_bar: 111 ret 112 113#--- common.s 114.comm _common, 1 115 116#--- 1.ll 117target triple = "x86_64-apple-macosx10.15.0" 118target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 119 120define void @foo() { 121 tail call void () @bar() 122 ret void 123} 124 125declare void @bar() 126 127#--- 2.ll 128target triple = "x86_64-apple-macosx10.15.0" 129target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 130 131define void @bar() { 132 ret void 133} 134