[PATCH] D42995: [ThinLTO] Ignore object files with empty ThinLTO index

Vitaly Buka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 6 17:18:01 PST 2018


vitalybuka created this revision.
vitalybuka added reviewers: pcc, tejohnson.
Herald added subscribers: eraman, inglorion, mehdi_amini.

Empty ThinLTOIndexFile signals that we don't need this module during
linking. So we should not run ThinLTO backend even if it contains the
ThinLTO module. Backend may fail because of lack of necessary
information which should be provided by ThinLTOIndex.


https://reviews.llvm.org/D42995

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===================================================================
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -9,16 +9,14 @@
 ; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir'
 
 ; Ensure we get expected error for missing index file
-; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1
+; RUN: not %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1
 ; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc'
 
 ; Ensure we ignore empty index file, and run non-ThinLTO compilation which
 ; would not import f2
 ; RUN: touch %t4.thinlto.bc
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=%t4.thinlto.bc
-; RUN: llvm-nm %t4.o | FileCheck --check-prefix=CHECK-OBJ-IGNORE-EMPTY %s
-; CHECK-OBJ-IGNORE-EMPTY: T f1
-; CHECK-OBJ-IGNORE-EMPTY: U f2
+; RUN: llvm-nm %t4.o | wc -l | FileCheck %s --check-prefix=CHECK-OBJ-EMPTY
 
 ; Ensure we don't fail with index and non-ThinLTO object file, and output must
 ; be empty file.
Index: clang/lib/CodeGen/CodeGenAction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -953,6 +953,21 @@
       return M;
     };
 
+    sys::fs::file_status Status;
+    if (auto E = sys::fs::status(CI.getCodeGenOpts().ThinLTOIndexFile, Status,
+                                 true)) {
+      return DiagErrors(make_error<StringError>(
+          "Error loading index file '" + CI.getCodeGenOpts().ThinLTOIndexFile +
+              "'",
+          E));
+    }
+    // Empty ThinLTOIndexFile signals that we don't need this module during
+    // linking. So we should not run ThinLTO backend even if it contains the
+    // ThinLTO module. Backend even may fail because of lack of necessary
+    // information which should be provided by ThinLTOIndex.
+    if (!Status.getSize())
+      return CreateEmptyModule();
+
     Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef);
     if (!BMsOrErr)
       return DiagErrors(BMsOrErr.takeError());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42995.133117.patch
Type: text/x-patch
Size: 2299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180207/55fbc7d6/attachment-0001.bin>


More information about the cfe-commits mailing list