[ELF] Fix --thinlto-index-only regression after D79300
authorFangrui Song <maskray@google.com>
Wed, 10 Jun 2020 06:08:04 +0000 (23:08 -0700)
committerFangrui Song <maskray@google.com>
Wed, 10 Jun 2020 06:10:30 +0000 (23:10 -0700)
After D79300, we don't rewrite InputFile::mb to an empty buffer.
In thinLTOCreateEmptyIndexFiles(), we should check LazyObjFile::fetched
as well as checking whether mb is a bitcode, otherwise we would overwrite (path + .thinlto.bc) with an empty index.

lld/ELF/LTO.cpp
lld/test/ELF/lto/thinlto-index-only.ll

index 56bf5b4..1f1c217 100644 (file)
@@ -255,7 +255,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
 // distributed build system that depends on that behavior.
 static void thinLTOCreateEmptyIndexFiles() {
   for (LazyObjFile *f : lazyObjFiles) {
-    if (!isBitcode(f->mb))
+    if (f->fetched || !isBitcode(f->mb))
       continue;
     std::string path = replaceThinLTOSuffix(getThinLTOOutputFile(f->getName()));
     std::unique_ptr<raw_fd_ostream> os = openFile(path + ".thinlto.bc");
index cccab1d..4c3c7e1 100644 (file)
@@ -26,7 +26,7 @@
 ; Ensure lld generates an index even if the file is wrapped in --start-lib/--end-lib
 ; RUN: rm -f %t2.o.thinlto.bc %t4
 ; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t1.o %t3.o --start-lib %t2.o --end-lib -o %t4
-; RUN: ls %t2.o.thinlto.bc
+; RUN: llvm-dis < %t2.o.thinlto.bc | grep -q '\^0 = module:'
 ; RUN: not test -e %t4
 
 ; Test that LLD generates an empty index even for lazy object file that is not added to link.