2 ; RUN: rm -rf %t && mkdir %t && cd %t
4 ;; First ensure that the ThinLTO handling in lld handles
5 ;; bitcode without summary sections gracefully and generates index file.
6 ; RUN: llvm-as %s -o 1.o
7 ; RUN: llvm-as %p/Inputs/thinlto.ll -o 2.o
8 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o 2.o -o 3
9 ; RUN: ls 2.o.thinlto.bc
11 ; RUN: ld.lld -shared 1.o 2.o -o 3
12 ; RUN: llvm-nm 3 | FileCheck %s --check-prefix=NM
14 ;; Basic ThinLTO tests.
15 ; RUN: opt -module-summary %s -o 1.o
16 ; RUN: opt -module-summary %p/Inputs/thinlto.ll -o 2.o
17 ; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o 3.o
19 ;; Ensure lld doesn't generates index files when --thinlto-index-only is not enabled.
20 ; RUN: rm -f 1.o.thinlto.bc 2.o.thinlto.bc
21 ; RUN: ld.lld -shared 1.o 2.o -o 5
22 ; RUN: not ls 1.o.thinlto.bc
23 ; RUN: not ls 2.o.thinlto.bc
25 ;; Ensure lld generates an index and not a binary if requested.
26 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o 2.o -o 4
27 ; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
28 ; RUN: llvm-bcanalyzer -dump 2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2
31 ;; Ensure lld generates an index even if the file is wrapped in --start-lib/--end-lib.
32 ; RUN: rm -f 2.o.thinlto.bc 4
33 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o 3.o --start-lib 2.o --end-lib -o 4
34 ; RUN: llvm-dis < 2.o.thinlto.bc | grep -q '\^0 = module:'
37 ;; Test that LLD generates an empty index even for lazy object file that is not added to link.
38 ;; Test LLD generates empty imports file either because of thinlto-emit-imports-files option.
39 ; RUN: rm -f 1.o.thinlto.bc 1.o.imports
40 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 2.o --start-lib 1.o --end-lib \
41 ; RUN: --plugin-opt=thinlto-emit-imports-files -o 3
42 ; RUN: ls 1.o.thinlto.bc
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 --plugin-opt=thinlto-index-only -shared dummy.o --start-lib 1.o --end-lib -o /dev/null
49 ; RUN: ls 1.o.thinlto.bc
51 ;; Ensure when the same bitcode object is given as both lazy and non-lazy,
52 ;; LLD does not generate an empty index for the lazy object.
53 ; RUN: rm -f 2.o.thinlto.bc
54 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o 2.o --start-lib 2.o --end-lib -o /dev/null
55 ; RUN: llvm-dis < 2.o.thinlto.bc | grep -q '\^0 = module:'
56 ; RUN: rm -f 2.o.thinlto.bc
57 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared --start-lib 2.o --end-lib 2.o 1.o -o /dev/null
58 ; RUN: llvm-dis < 2.o.thinlto.bc | grep -q '\^0 = module:'
60 ;; Ensure when the same lazy bitcode object is given multiple times,
61 ;; no empty index file is generated if one of the copies is linked.
62 ; RUN: rm -f 2.o.thinlto.bc
63 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o --start-lib 2.o --end-lib --start-lib 2.o --end-lib -o /dev/null
64 ; RUN: llvm-dis < 2.o.thinlto.bc | grep -q '\^0 = module:'
68 ;; The backend index for this module contains summaries from itself and
69 ;; Inputs/thinlto.ll, as it imports from the latter.
70 ; BACKEND1: <MODULE_STRTAB_BLOCK
71 ; BACKEND1-NEXT: <ENTRY {{.*}} record string = '1.o'
72 ; BACKEND1-NEXT: <ENTRY {{.*}} record string = '2.o'
73 ; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
74 ; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
77 ; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
78 ; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
81 ; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
83 ;; The backend index for Input/thinlto.ll contains summaries from itself only,
84 ;; as it does not import anything.
85 ; BACKEND2: <MODULE_STRTAB_BLOCK
86 ; BACKEND2-NEXT: <ENTRY {{.*}} record string = '2.o'
87 ; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
88 ; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
89 ; BACKEND2-NEXT: <VERSION
90 ; BACKEND2-NEXT: <FLAGS
91 ; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
92 ; BACKEND2-NEXT: <COMBINED
93 ; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
95 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
96 target triple = "x86_64-unknown-linux-gnu"