1; REQUIRES: x86
2
3;; Mostly copied/updated from thinlto-index-only.ll
4;; First ensure that the ThinLTO handling in lld handles
5;; bitcode without summary sections gracefully and generates index file.
6; RUN: rm -rf %t.dir && mkdir %t.dir && cd %t.dir
7; RUN: llvm-as %s -o 1.o
8; RUN: llvm-as %p/Inputs/thinlto.ll -o 2.o
9; RUN: ld.lld --thinlto-emit-index-files -shared 1.o 2.o -o 3
10; RUN: ls 2.o.thinlto.bc
11; RUN: ls 3
12; RUN: ld.lld -shared 1.o 2.o -o 3
13; RUN: llvm-nm 3 | FileCheck %s --check-prefix=NM
14
15;; Basic ThinLTO tests.
16; RUN: opt -module-summary %s -o 1.o
17; RUN: opt -module-summary %p/Inputs/thinlto.ll -o 2.o
18; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o 3.o
19
20;; Ensure lld generates an index and also a binary if requested.
21; RUN: ld.lld --thinlto-emit-index-files -shared 1.o 2.o -o 4
22; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
23; RUN: llvm-bcanalyzer -dump 2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2
24; RUN: ls 4
25
26;; Ensure lld generates an index and not a binary if both emit-index and index-only are present.
27; RUN: ld.lld --thinlto-emit-index-files --thinlto-index-only -shared 1.o 2.o -o 5
28; RUN: not ls 5
29
30;; Ensure lld generates an index even if the file is wrapped in --start-lib/--end-lib
31; RUN: rm -f 2.o.thinlto.bc
32; RUN: ld.lld --thinlto-emit-index-files -shared 1.o 3.o --start-lib 2.o --end-lib -o 6
33; RUN: llvm-dis < 2.o.thinlto.bc | grep -q '\^0 = module:'
34; RUN: ls 6
35
36;; Test that LLD generates an empty index even for lazy object file that is not added to link.
37;; Test that LLD also generates empty imports file with the --thinlto-emit-imports-files option.
38; RUN: rm -f 1.o.thinlto.bc 1.o.imports
39; RUN: ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \
40; RUN: --thinlto-emit-imports-files -o 7
41; RUN: ls 7
42; RUN: ls 1.o.thinlto.bc
43; RUN: ls 1.o.imports
44
45;; Ensure LLD generates an empty index for each bitcode file even if all bitcode files are lazy.
46; RUN: rm -f 1.o.thinlto.bc
47; RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux-gnu /dev/null -o dummy.o
48; RUN: ld.lld --thinlto-emit-index-files -shared dummy.o --start-lib 1.o --end-lib -o 8
49; RUN: ls 8
50; RUN: ls 1.o.thinlto.bc
51
52;; Test that LLD errors out when run with suffix replacement, or prefix replacement
53; RUN: not ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \
54; RUN: --thinlto-prefix-replace="abc;xyz" 2>&1 | FileCheck %s --check-prefix=ERR1
55; ERR1: --thinlto-prefix-replace is not supported with --thinlto-emit-index-files
56
57; RUN: not ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \
58; RUN: --thinlto-object-suffix-replace="abc;xyz" 2>&1 | FileCheck %s --check-prefix=ERR2
59; ERR2: --thinlto-object-suffix-replace is not supported with --thinlto-emit-index-files
60
61;; But not when passed with index only as well
62; RUN: ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \
63; RUN: --thinlto-prefix-replace="abc;xyz" --thinlto-index-only
64
65; RUN: ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \
66; RUN: --thinlto-object-suffix-replace="abc;xyz" --thinlto-index-only
67
68; NM: T f
69
70;; The backend index for this module contains summaries from itself and
71;; Inputs/thinlto.ll, as it imports from the latter.
72; BACKEND1: <MODULE_STRTAB_BLOCK
73; BACKEND1-NEXT: <ENTRY {{.*}} record string = '1.o'
74; BACKEND1-NEXT: <ENTRY {{.*}} record string = '2.o'
75; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
76; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
77; BACKEND1: <VERSION
78; BACKEND1: <FLAGS
79; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
80; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
81; BACKEND1: <COMBINED
82; BACKEND1: <COMBINED
83; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
84
85;; The backend index for Input/thinlto.ll contains summaries from itself only,
86;; as it does not import anything.
87; BACKEND2: <MODULE_STRTAB_BLOCK
88; BACKEND2-NEXT: <ENTRY {{.*}} record string = '2.o'
89; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
90; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
91; BACKEND2-NEXT: <VERSION
92; BACKEND2-NEXT: <FLAGS
93; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
94; BACKEND2-NEXT: <COMBINED
95; BACKEND2-NEXT: <BLOCK_COUNT op0=2/>
96; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
97
98target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
99target triple = "x86_64-unknown-linux-gnu"
100
101declare void @g(...)
102
103define void @f() {
104entry:
105  call void (...) @g()
106  ret void
107}
108