xref: /llvm-project/lld/test/MachO/lto-weak-ref.ll (revision c4b45eeb44fdc49d1b6199f242082268f8c017d0)
1; REQUIRES: x86
2
3; RUN: rm -rf %t; split-file %s %t
4
5; RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/dylib.s -o %t/dylib.o
6; RUN: %lld -dylib -lSystem %t/dylib.o -o %t/dylib.dylib
7
8;; As baseline, compile the .ll file to a real .o file and check behavior.
9; RUN: llc -filetype=obj %t/weak-ref.ll -o %t/obj.o
10; RUN: %lld -dylib -lSystem %t/obj.o %t/dylib.dylib -o %t/test.obj
11; RUN: llvm-objdump --macho --syms %t/test.obj | FileCheck %s --check-prefixes=WEAK-REF
12
13;; Check that we get the same behavior compiling the .ll file to a bitcode .o
14;; file and linking that.
15; RUN: opt -module-summary %t/weak-ref.ll -o %t/bitcode.o
16; RUN: %lld -dylib -lSystem %t/bitcode.o %t/dylib.dylib -o %t/test.lto
17; RUN: llvm-objdump --macho --syms %t/test.lto | FileCheck %s --check-prefixes=WEAK-REF
18
19; WEAK-REF: SYMBOL TABLE:
20; WEAK-REF: w      *UND* _my_weak_extern_function
21
22;--- dylib.s
23
24.globl	_my_weak_extern_function
25_my_weak_extern_function:
26  ret
27
28;--- weak-ref.ll
29target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
30target triple = "x86_64-apple-macosx10.15.0"
31
32declare extern_weak void @my_weak_extern_function()
33
34; Function Attrs: noinline nounwind optnone ssp uwtable
35define i32 @bar(i1 zeroext %0) {
36entry:
37  br i1 %0, label %if.then, label %if.end
38
39if.then:                                          ; preds = %entry
40  call void @my_weak_extern_function()
41  br label %if.end
42
43if.end:                                           ; preds = %if.then, %entry
44  ret i32 0
45}
46