3 ; RUN: rm -rf %t; mkdir %t
5 ; RUN: llc -filetype=obj %s -O3 -o %t/icf-obj.o -enable-machine-outliner=never -mtriple arm64-apple-macos -addrsig
6 ; RUN: %lld -arch arm64 -lSystem --icf=safe -dylib -o %t/icf-safe.dylib %t/icf-obj.o
7 ; RUN: %lld -arch arm64 -lSystem --icf=all -dylib -o %t/icf-all.dylib %t/icf-obj.o
8 ; RUN: llvm-objdump %t/icf-safe.dylib -d -h --macho | FileCheck %s --check-prefixes=ICFSAFE,CHECK
9 ; RUN: llvm-objdump %t/icf-all.dylib -d -h --macho | FileCheck %s --check-prefixes=ICFALL,CHECK
11 ; RUN: llvm-as %s -o %t/icf-bitcode.o
12 ; RUN: %lld -arch arm64 -lSystem --icf=safe -dylib -o %t/icf-safe-bitcode.dylib %t/icf-bitcode.o
13 ; RUN: %lld -arch arm64 -lSystem --icf=all -dylib -o %t/icf-all-bitcode.dylib %t/icf-bitcode.o
14 ; RUN: llvm-objdump %t/icf-safe-bitcode.dylib -d -h --macho | FileCheck %s --check-prefixes=ICFSAFE,CHECK
15 ; RUN: llvm-objdump %t/icf-all-bitcode.dylib -d -h --macho | FileCheck %s --check-prefixes=ICFALL,CHECK
17 ;; Regression test: if we tried writing __llvm_addrsig to the output, -fixup_chains would fail with a "fixups overlap"
18 ;; error, as the relocations (which reference the address-taken functions) are all at offset 0.
19 ; RUN: %lld -arch arm64 -lSystem --icf=safe -fixup_chains -dylib -o %t/icf-safe-chained.dylib %t/icf-obj.o
20 ; RUN: llvm-objdump %t/icf-safe-chained.dylib -d -h --macho | FileCheck %s --check-prefixes=ICFSAFE,CHECK
22 ; ICFSAFE-LABEL: _callAllFunctions
24 ; ICFSAFE-NEXT: bl _func02
25 ; ICFSAFE-NEXT: bl _func03_takeaddr
27 ; ICFALL-LABEL: _callAllFunctions
28 ; ICFALL: bl _func03_takeaddr
29 ; ICFALL-NEXT: bl _func03_takeaddr
30 ; ICFALL-NEXT: bl _func03_takeaddr
32 ; CHECK-LABEL: Sections:
33 ; CHECK-NOT: __llvm_addrsig
35 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
36 target triple = "arm64-apple-macos11.0"
38 @result = global i32 0, align 4
40 define void @func01() local_unnamed_addr noinline {
42 %0 = load volatile i32, ptr @result, align 4
43 %add = add nsw i32 %0, 1
44 store volatile i32 %add, ptr @result, align 4
48 define void @func02() local_unnamed_addr noinline {
50 %0 = load volatile i32, ptr @result, align 4
51 %add = add nsw i32 %0, 1
52 store volatile i32 %add, ptr @result, align 4
56 define void @func03_takeaddr() noinline {
58 %0 = load volatile i32, ptr @result, align 4
59 %add = add nsw i32 %0, 1
60 store volatile i32 %add, ptr @result, align 4
64 define void @callAllFunctions() local_unnamed_addr {
66 tail call void @func01()
67 tail call void @func02()
68 tail call void @func03_takeaddr()
69 %0 = load volatile i32, ptr @result, align 4
70 %add = add nsw i32 %0, ptrtoint (ptr @func03_takeaddr to i32)
71 store volatile i32 %add, ptr @result, align 4