1; REQUIRES: x86
2
3; First ensure that the ThinLTO handling in lld handles
4; bitcode without summary sections gracefully and generates index file.
5; RUN: llvm-as %s -o %t1.o
6; RUN: llvm-as %p/Inputs/thinlto.ll -o %t2.o
7; RUN: rm -f %t3
8; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t1.o %t2.o -o %t3
9; RUN: ls %t2.o.thinlto.bc
10; RUN: not test -e %t3
11; RUN: ld.lld -shared %t1.o %t2.o -o %t3
12; RUN: llvm-nm %t3 | FileCheck %s --check-prefix=NM
13
14; Basic ThinLTO tests.
15; RUN: opt -module-summary %s -o %t1.o
16; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o
17; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o %t3.o
18
19; Ensure lld generates an index and not a binary if requested.
20; RUN: rm -f %t4
21; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t1.o %t2.o -o %t4
22; RUN: llvm-bcanalyzer -dump %t1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
23; RUN: llvm-bcanalyzer -dump %t2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2
24; RUN: not test -e %t4
25
26; Ensure lld generates an index even if the file is wrapped in --start-lib/--end-lib
27; RUN: rm -f %t2.o.thinlto.bc %t4
28; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t1.o %t3.o --start-lib %t2.o --end-lib -o %t4
29; RUN: llvm-dis < %t2.o.thinlto.bc | grep -q '\^0 = module:'
30; RUN: not test -e %t4
31
32; Test that LLD generates an empty index even for lazy object file that is not added to link.
33; Test LLD generates empty imports file either because of thinlto-emit-imports-files option.
34; RUN: rm -f %t1.o.thinlto.bc
35; RUN: rm -f %t1.o.imports
36; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t2.o --start-lib %t1.o --end-lib \
37; RUN: --plugin-opt=thinlto-emit-imports-files -o %t3
38; RUN: ls %t1.o.thinlto.bc
39; RUN: ls %t1.o.imports
40
41; Ensure LLD generates an empty index for each bitcode file even if all bitcode files are lazy.
42; RUN: rm -f %t1.o.thinlto.bc
43; RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux-gnu /dev/null -o %tdummy.o
44; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %tdummy.o --start-lib %t1.o --end-lib -o /dev/null
45; RUN: ls %t1.o.thinlto.bc
46
47; NM: T f
48
49; The backend index for this module contains summaries from itself and
50; Inputs/thinlto.ll, as it imports from the latter.
51; BACKEND1: <MODULE_STRTAB_BLOCK
52; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto-index-only.ll.tmp{{.*}}.o'
53; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto-index-only.ll.tmp{{.*}}.o'
54; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
55; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
56; BACKEND1: <VERSION
57; BACKEND1: <FLAGS
58; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
59; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
60; BACKEND1: <COMBINED
61; BACKEND1: <COMBINED
62; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
63
64; The backend index for Input/thinlto.ll contains summaries from itself only,
65; as it does not import anything.
66; BACKEND2: <MODULE_STRTAB_BLOCK
67; BACKEND2-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto-index-only.ll.tmp2.o'
68; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
69; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
70; BACKEND2-NEXT: <VERSION
71; BACKEND2-NEXT: <FLAGS
72; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
73; BACKEND2-NEXT: <COMBINED
74; BACKEND2-NEXT: <BLOCK_COUNT op0=2/>
75; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
76
77target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
78target triple = "x86_64-unknown-linux-gnu"
79
80declare void @g(...)
81
82define void @f() {
83entry:
84  call void (...) @g()
85  ret void
86}
87