2 ; RUN: rm -rf %t && split-file %s %t && cd %t
5 ;; First ensure that the ThinLTO handling in lld handles
6 ;; bitcode without summary sections gracefully and generates index file.
7 ; RUN: llvm-as 1.ll -o 1.o
8 ; RUN: llvm-as %p/Inputs/thinlto.ll -o d/2.o
9 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o d/2.o -o 3
10 ; RUN: ls d/2.o.thinlto.bc
12 ; RUN: ld.lld -shared 1.o d/2.o -o 3
13 ; RUN: llvm-nm 3 | FileCheck %s --check-prefix=NM
15 ;; Basic ThinLTO tests.
16 ; RUN: llvm-as 0.ll -o 0.o
17 ; RUN: opt -module-summary 1.ll -o 1.o
18 ; RUN: opt -module-summary %p/Inputs/thinlto.ll -o d/2.o
19 ; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o 3.o
22 ;; Ensure lld doesn't generates index files when --thinlto-index-only is not enabled.
23 ; RUN: rm -f 1.o.thinlto.bc d/2.o.thinlto.bc
24 ; RUN: ld.lld -shared 1.o d/2.o -o /dev/null
25 ; RUN: not ls 1.o.thinlto.bc
26 ; RUN: not ls d/2.o.thinlto.bc
28 ;; Ensure lld generates an index and not a binary if requested.
29 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o --start-lib d/2.o 3.o --end-lib 4.o -o 4
31 ; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
32 ; RUN: llvm-bcanalyzer -dump d/2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2
33 ; RUN: llvm-dis < 3.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND3
34 ; RUN: llvm-dis < 4.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND4
36 ; RUN: rm -f 1.o.thinlto.bc d/2.o.thinlto.bc 3.o.thinlto.bc 4.o.thinlto.bc
37 ; RUN: ld.lld --plugin-opt=thinlto-index-only=4.txt --plugin-opt=thinlto-emit-imports-files -shared 1.o --start-lib d/2.o 3.o --end-lib 4.o -o 4
39 ; RUN: FileCheck %s --check-prefix=RSP --implicit-check-not={{.}} < 4.txt
40 ; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
41 ; RUN: llvm-bcanalyzer -dump d/2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2
42 ; RUN: llvm-dis < 3.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND3
43 ; RUN: llvm-dis < 4.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND4
44 ; RUN: FileCheck %s --check-prefix=IMPORTS1 --implicit-check-not={{.}} < 1.o.imports
45 ; RUN: count 0 < d/2.o.imports
46 ;; Test that LLD generates an empty index even for lazy object file that is not added to link.
47 ; RUN: count 0 < 3.o.imports
48 ; RUN: count 0 < 4.o.imports
50 ;; Test the other spelling --thinlto-index-only= --thinlto-emit-imports-files and the interaction with --save-temps.
51 ; RUN: rm -f 4.txt 1.o.thinlto.bc d/2.o.thinlto.bc 3.o.thinlto.bc 4.o.thinlto.bc
52 ; RUN: ld.lld --thinlto-index-only=4.txt --thinlto-emit-imports-files --save-temps -shared 0.o 1.o --start-lib d/2.o 3.o --end-lib 4.o -o t
54 ; RUN: FileCheck %s --check-prefix=RSP --implicit-check-not={{.}} < 4.txt
55 ; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
56 ; RUN: FileCheck %s --check-prefix=IMPORTS1 --implicit-check-not={{.}} < 1.o.imports
57 ; RUN: FileCheck %s --check-prefix=RESOLUTION < t.resolution.txt
58 ; RUN: llvm-dis < t.index.bc | FileCheck %s --check-prefix=INDEX-BC
67 ; RESOLUTION-NEXT: -r=0.o,foo,px
68 ; RESOLUTION-NEXT: 1.o
70 ; INDEX-BC: ^0 = module: (path: "1.o", hash: (0, 0, 0, 0, 0))
71 ; INDEX-BC-NEXT: ^1 = module: (path: "4.o", hash: (0, 0, 0, 0, 0))
72 ; INDEX-BC-NEXT: ^2 = module: (path: "d/2.o", hash: (0, 0, 0, 0, 0))
74 ;; Ensure LLD generates an empty index for each bitcode file even if all bitcode files are lazy.
75 ; RUN: rm -f 1.o.thinlto.bc
76 ; RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux-gnu /dev/null -o dummy.o
77 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared dummy.o --start-lib 1.o --end-lib -o /dev/null
78 ; RUN: ls 1.o.thinlto.bc
80 ;; Ensure when the same bitcode object is given as both lazy and non-lazy,
81 ;; LLD does not generate an empty index for the lazy object.
82 ; RUN: rm -f d/2.o.thinlto.bc
83 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o d/2.o --start-lib d/2.o --end-lib -o /dev/null
84 ; RUN: llvm-dis < d/2.o.thinlto.bc | grep -q '\^0 = module:'
85 ; RUN: rm -f d/2.o.thinlto.bc
86 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared --start-lib d/2.o --end-lib d/2.o 1.o -o /dev/null
87 ; RUN: llvm-dis < d/2.o.thinlto.bc | grep -q '\^0 = module:'
89 ;; Ensure when the same lazy bitcode object is given multiple times,
90 ;; no empty index file is generated if one of the copies is linked.
91 ; RUN: rm -f d/2.o.thinlto.bc
92 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o --start-lib d/2.o --end-lib --start-lib d/2.o --end-lib -o /dev/null
93 ; RUN: llvm-dis < d/2.o.thinlto.bc | grep -q '\^0 = module:'
97 ;; The backend index for this module contains summaries from itself and
98 ;; Inputs/thinlto.ll, as it imports from the latter.
99 ; BACKEND1: <MODULE_STRTAB_BLOCK
100 ; BACKEND1-NEXT: <ENTRY {{.*}} record string = '1.o'
101 ; BACKEND1-NEXT: <ENTRY {{.*}} record string = 'd/2.o'
102 ; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
103 ; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
106 ; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
107 ; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
108 ; BACKEND1: <COMBINED
109 ; BACKEND1: <COMBINED
110 ; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
112 ;; The backend index for Input/thinlto.ll contains summaries from itself only,
113 ;; as it does not import anything.
114 ; BACKEND2: <MODULE_STRTAB_BLOCK
115 ; BACKEND2-NEXT: <ENTRY {{.*}} record string = 'd/2.o'
116 ; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
117 ; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
118 ; BACKEND2-NEXT: <VERSION
119 ; BACKEND2-NEXT: <FLAGS
120 ; BACKEND2-NEXT: <VALUE_GUID {{.*}} op0=1 op1=3060885059 op2=1207956914
121 ; BACKEND2-NEXT: <COMBINED
122 ; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
124 ; BACKEND3: ^0 = flags:
126 ; BACKEND4: ^0 = module: (path: "4.o", hash: (0, 0, 0, 0, 0))
129 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
130 target triple = "x86_64-unknown-linux-gnu"
137 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
138 target triple = "x86_64-unknown-linux-gnu"