xref: /llvm-project/clang/test/CodeGen/fat-lto-objects.c (revision 446f66d685c2470bc7744b1d1538c4728e838e43)
1 // REQUIRES: x86-registered-target
2 
3 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -emit-llvm < %s  | FileCheck %s --check-prefixes=FULL,SPLIT
4 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -emit-llvm < %s  | FileCheck %s --check-prefixes=FULL,SPLIT
5 
6 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -fsplit-lto-unit -ffat-lto-objects -emit-llvm < %s  | FileCheck %s --check-prefixes=THIN,SPLIT
7 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -ffat-lto-objects -emit-llvm < %s  | FileCheck %s --check-prefixes=THIN,NOSPLIT
8 
9 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -emit-obj < %s -o %t.full.split.o
10 // RUN: llvm-readelf -S %t.full.split.o | FileCheck %s --check-prefixes=ELF
11 // RUN: llvm-objcopy --dump-section=.llvm.lto=%t.full.split.bc %t.full.split.o
12 // RUN: llvm-dis %t.full.split.bc -o - | FileCheck %s --check-prefixes=FULL,SPLIT,NOUNIFIED
13 
14 /// Full LTO always sets EnableSplitLTOUnit when the summary is used.
15 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -emit-obj < %s -o %t.full.nosplit.o
16 // RUN: llvm-readelf -S %t.full.nosplit.o | FileCheck %s --check-prefixes=ELF
17 // RUN: llvm-objcopy --dump-section=.llvm.lto=%t.full.nosplit.bc %t.full.nosplit.o
18 // RUN: llvm-dis %t.full.nosplit.bc -o - | FileCheck %s --check-prefixes=FULL,SPLIT,NOUNIFIED
19 
20 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -fsplit-lto-unit -ffat-lto-objects -emit-obj < %s -o %t.thin.split.o
21 // RUN: llvm-readelf -S %t.thin.split.o | FileCheck %s --check-prefixes=ELF
22 // RUN: llvm-objcopy --dump-section=.llvm.lto=%t.thin.split.bc %t.thin.split.o
23 // RUN: llvm-dis %t.thin.split.bc -o - | FileCheck %s --check-prefixes=THIN,SPLIT,NOUNIFIED
24 
25 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -ffat-lto-objects -emit-obj < %s -o %t.thin.nosplit.o
26 // RUN: llvm-readelf -S %t.thin.nosplit.o | FileCheck %s --check-prefixes=ELF
27 // RUN: llvm-objcopy --dump-section=.llvm.lto=%t.thin.nosplit.bc %t.thin.nosplit.o
28 // RUN: llvm-dis %t.thin.nosplit.bc -o -  | FileCheck %s --check-prefixes=THIN,NOSPLIT,NOUNIFIED
29 
30 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -funified-lto -ffat-lto-objects -emit-obj < %s -o %t.unified.o
31 // RUN: llvm-readelf -S %t.unified.o | FileCheck %s --check-prefixes=ELF
32 // RUN: llvm-objcopy --dump-section=.llvm.lto=%t.unified.bc %t.unified.o
33 // RUN: llvm-dis %t.unified.bc -o - | FileCheck %s --check-prefixes=THIN,NOSPLIT,UNIFIED
34 
35 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -S < %s -o - \
36 // RUN: | FileCheck %s --check-prefixes=ASM
37 
38 /// Make sure that FatLTO generates .llvm.lto sections that are the same as the output from normal LTO compilations
39 // RUN: %clang -O2 --target=x86_64-unknown-linux-gnu -fPIE -flto=full -ffat-lto-objects -c %s -o %t.fatlto.full.o
40 // RUN: llvm-objcopy --dump-section=.llvm.lto=%t.fatlto.full.bc %t.fatlto.full.o
41 // RUN: llvm-dis < %t.fatlto.full.bc -o %t.fatlto.full.ll
42 // RUN: %clang -O2 --target=x86_64-unknown-linux-gnu -fPIE -flto=full -c %s -o %t.nofat.full.bc
43 // RUN: llvm-dis < %t.nofat.full.bc -o %t.nofat.full.ll
44 // RUN: diff %t.fatlto.full.ll %t.nofat.full.ll
45 
46 // RUN: %clang -O2 --target=x86_64-unknown-linux-gnu -fPIE -flto=thin -ffat-lto-objects -c %s -o %t.fatlto.thin.o
47 // RUN: llvm-objcopy --dump-section=.llvm.lto=%t.fatlto.thin.bc %t.fatlto.thin.o
48 // RUN: llvm-dis < %t.fatlto.thin.bc -o %t.fatlto.thin.ll
49 // RUN: %clang -O2 --target=x86_64-unknown-linux-gnu -fPIE -flto=thin -c %s -o %t.nofat.thin.bc
50 // RUN: llvm-dis < %t.nofat.thin.bc -o %t.nofat.thin.ll
51 // RUN: diff %t.fatlto.thin.ll %t.nofat.thin.ll
52 
53 /// Be sure we enable split LTO units correctly under -ffat-lto-objects.
54 //   SPLIT: ![[#]] = !{i32 1, !"EnableSplitLTOUnit", i32 1}
55 // NOSPLIT: ![[#]] = !{i32 1, !"EnableSplitLTOUnit", i32 0}
56 
57 // FULL-NOT: ![[#]] = !{i32 1, !"ThinLTO", i32 0}
58 // THIN-NOT: ![[#]] = !{i32 1, !"ThinLTO", i32 0}
59 
60 // UNIFIED: ![[#]] = !{i32 1, !"UnifiedLTO", i32 1}
61 // NOUNIFIED-NOT: ![[#]] = !{i32 1, !"UnifiedLTO", i32 1}
62 
63 // ELF: .llvm.lto
64 
65 //      ASM: .section        .llvm.lto,"e",@llvm_lto
66 // ASM-NEXT: .Lllvm.embedded.object:
67 // ASM-NEXT:        .asciz  "BC
68 // ASM-NEXT: .size   .Lllvm.embedded.object
69 
70 const char* foo = "foo";
71 
test(void)72 int test(void) {
73   const char* bar = "bar";
74   return 0xabcd;
75 }
76