llvm.org GIT mirror llvm / 82673ec
Revert "Revert "ThinLTO: Verify bitcode before lauching the ThinLTOCodeGenerator."" This reapplies commit r303438 modified to not verify cross-imported bitcode in FunctionImporter. rdar://problem/31233625 Differential Revision: https://reviews.llvm.org/D33370 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303470 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 2 years ago
5 changed file(s) with 96 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
5252 : Index(Index), ModuleLoader(std::move(ModuleLoader)) {}
5353
5454 /// Import functions in Module \p M based on the supplied import list.
55 Expected
56 importFunctions(Module &M, const ImportMapTy &ImportList);
55 Expected importFunctions(Module &M, const ImportMapTy &ImportList);
5756
5857 private:
5958 /// The summaries index used to trigger importing.
2424 #include "llvm/Bitcode/BitcodeWriterPass.h"
2525 #include "llvm/ExecutionEngine/ObjectMemoryBuffer.h"
2626 #include "llvm/IR/DiagnosticPrinter.h"
27 #include "llvm/IR/DebugInfo.h"
2728 #include "llvm/IR/LLVMContext.h"
2829 #include "llvm/IR/LegacyPassManager.h"
2930 #include "llvm/IR/Mangler.h"
31 #include "llvm/IR/Verifier.h"
3032 #include "llvm/IRReader/IRReader.h"
3133 #include "llvm/LTO/LTO.h"
3234 #include "llvm/Linker/Linker.h"
6163 extern cl::opt LTODiscardValueNames;
6264 extern cl::opt LTORemarksFilename;
6365 extern cl::opt LTOPassRemarksWithHotness;
66 extern cl::opt LTOStripInvalidDebugInfo;
6467 }
6568
6669 namespace {
141144 report_fatal_error("renameModuleForThinLTO failed");
142145 }
143146
147 namespace {
148 class ThinLTODiagnosticInfo : public DiagnosticInfo {
149 const Twine &Msg;
150 public:
151 ThinLTODiagnosticInfo(const Twine &DiagMsg,
152 DiagnosticSeverity Severity = DS_Error)
153 : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
154 void print(DiagnosticPrinter &DP) const override { DP << Msg; }
155 };
156 }
157
158 /// Verify the module and strip broken debug info.
159 static void verifyLoadedModule(Module &TheModule) {
160 bool BrokenDebugInfo = false;
161 if (verifyModule(TheModule, &dbgs(),
162 LTOStripInvalidDebugInfo ? &BrokenDebugInfo : nullptr))
163 report_fatal_error("Broken module found, compilation aborted!");
164 if (BrokenDebugInfo) {
165 TheModule.getContext().diagnose(ThinLTODiagnosticInfo(
166 "Invalid debug info found, debug info will be stripped", DS_Warning));
167 StripDebugInfo(TheModule);
168 }
169 }
170
144171 static std::unique_ptr
145172 loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context,
146173 bool Lazy, bool IsImporting) {
158185 });
159186 report_fatal_error("Can't load module, abort.");
160187 }
188 if (!Lazy)
189 verifyLoadedModule(*ModuleOrErr.get());
161190 return std::move(ModuleOrErr.get());
162191 }
163192
180209 });
181210 report_fatal_error("importFunctions failed");
182211 }
212 // Verify again after cross-importing.
213 verifyLoadedModule(TheModule);
183214 }
184215
185216 static void optimizeModule(Module &TheModule, TargetMachine &TM,
194225 PMB.OptLevel = OptLevel;
195226 PMB.LoopVectorize = true;
196227 PMB.SLPVectorize = true;
197 PMB.VerifyInput = true;
228 // Already did this in verifyLoadedModule().
229 PMB.VerifyInput = false;
198230 PMB.VerifyOutput = false;
199231
200232 legacy::PassManager PM;
0 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
1 target triple = "x86_64-apple-macosx10.12"
2
3 define void @bar() !dbg !3 {
4 ret void
5 }
6
7 !llvm.module.flags = !{!0}
8 !llvm.dbg.cu = !{!1}
9
10 !0 = !{i32 2, !"Debug Info Version", i32 3}
11 !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2)
12 !2 = !DIFile(filename: "broken", directory: "")
13 !3 = distinct !DISubprogram(line: 1000, isDefinition: true)
14
test/LTO/X86/Inputs/strip-debug-info.bc less more
Binary diff not shown
0 ; RUN: llvm-as -disable-verify %s -o %t.bc
1 ; ---- Full LTO ---------------------------------------------
2 ; RUN: not llvm-lto -lto-strip-invalid-debug-info=false \
1 ; RUN: -o %t.o %S/Inputs/strip-debug-info.bc 2>&1 | \
3 ; RUN: -o %t.o %t.bc 2>&1 | \
24 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-ERR
35 ; RUN: llvm-lto -lto-strip-invalid-debug-info=true \
46 ; RUN: -exported-symbol foo -exported-symbol _foo \
5 ; RUN: -o %t.o %S/Inputs/strip-debug-info.bc 2>&1 | \
7 ; RUN: -o %t.o %t.bc 2>&1 | \
68 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN
79 ; RUN: llvm-nm %t.o | FileCheck %s
10 ; ---- Thin LTO (codegen only) ------------------------------
11 ; RUN: not llvm-lto -thinlto -thinlto-action=codegen \
12 ; RUN: -lto-strip-invalid-debug-info=false \
13 ; RUN: %t.bc -disable-verify 2>&1 | \
14 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-ERR
15 ; RUN: llvm-lto -thinlto -thinlto-action=codegen \
16 ; RUN: -lto-strip-invalid-debug-info=true \
17 ; RUN: %t.bc -disable-verify 2>&1 | \
18 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN
19 ; ---- Thin LTO (optimize, strip main file) -----------------
20 ; RUN: opt -disable-verify -module-summary %s -o %t.bc
21 ; RUN: opt -disable-verify -module-summary %S/Inputs/strip-debug-info-bar.ll \
22 ; RUN: -o %t2.bc
23 ; RUN: not llvm-lto -thinlto -thinlto-action=run \
24 ; RUN: -lto-strip-invalid-debug-info=false \
25 ; RUN: %t.bc -disable-verify 2>&1 | \
26 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-ERR
27 ; RUN: llvm-lto -thinlto -thinlto-action=run \
28 ; RUN: -lto-strip-invalid-debug-info=true \
29 ; RUN: %t.bc -disable-verify 2>&1 | \
30 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN
31 ; ---- Thin LTO (optimize, strip imported file) -------------
32 ; RUN: opt -disable-verify -strip-debug -module-summary %t.bc -o %t-stripped.bc
33 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t-stripped.bc %t2.bc
34 ; RUN: not llvm-lto -thinlto -thinlto-action=import \
35 ; RUN: -thinlto-index=%t.index.bc \
36 ; RUN: -lto-strip-invalid-debug-info=false \
37 ; RUN: -exported-symbol foo -exported-symbol _foo \
38 ; RUN: %t-stripped.bc -disable-verify 2>&1 | \
39 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-ERR
40 ; RUN: llvm-lto -thinlto -thinlto-action=import \
41 ; RUN: -lto-strip-invalid-debug-info=true \
42 ; RUN: -thinlto-index=%t.index.bc \
43 ; RUN: -exported-symbol foo -exported-symbol _foo \
44 ; RUN: %t-stripped.bc -disable-verify 2>&1 | \
45 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN
846
947 ; CHECK-ERR: Broken module found, compilation aborted
1048 ; CHECK-WARN: Invalid debug info found, debug info will be stripped
49 ; CHECK-WARN-NOT: Broken module found
1150 ; CHECK: foo
51 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
52 target triple = "x86_64-apple-macosx10.12"
53
54 declare void @bar()
55
1256 define void @foo() {
57 call void @bar()
1358 ret void
1459 }
1560