[lld] 5529a75 - [ELF][Distributed ThinLTO] Do not generate empty index when bitcode object is linked
Wei Wang via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 13 14:36:26 PDT 2022
Author: Wei Wang
Date: 2022-09-13T14:34:41-07:00
New Revision: 5529a7524ad72962deba9ba061296f8b169d938f
URL: https://github.com/llvm/llvm-project/commit/5529a7524ad72962deba9ba061296f8b169d938f
DIFF: https://github.com/llvm/llvm-project/commit/5529a7524ad72962deba9ba061296f8b169d938f.diff
LOG: [ELF][Distributed ThinLTO] Do not generate empty index when bitcode object is linked
When the same bitcode object file is given multiple times from the Command-line
as lazy object file, empty index is generated which overwrites the one from thinlink.
This could cause undefined symbols during final link.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D133740
Added:
Modified:
lld/ELF/LTO.cpp
lld/test/ELF/lto/thinlto-index-only.ll
Removed:
################################################################################
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index d39a7ac25d7c..a8634c4c6110 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -290,9 +290,15 @@ void BitcodeCompiler::add(BitcodeFile &f) {
// This is needed because this is what GNU gold plugin does and we have a
// distributed build system that depends on that behavior.
static void thinLTOCreateEmptyIndexFiles() {
+ DenseSet<StringRef> linkedBitCodeFiles;
+ for (BitcodeFile *f : ctx->bitcodeFiles)
+ linkedBitCodeFiles.insert(f->getName());
+
for (BitcodeFile *f : ctx->lazyBitcodeFiles) {
if (!f->lazy)
continue;
+ if (linkedBitCodeFiles.contains(f->getName()))
+ continue;
std::string path = replaceThinLTOSuffix(getThinLTOOutputFile(f->getName()));
std::unique_ptr<raw_fd_ostream> os = openFile(path + ".thinlto.bc");
if (!os)
diff --git a/lld/test/ELF/lto/thinlto-index-only.ll b/lld/test/ELF/lto/thinlto-index-only.ll
index 7385d6680826..fd95f67fa5ae 100644
--- a/lld/test/ELF/lto/thinlto-index-only.ll
+++ b/lld/test/ELF/lto/thinlto-index-only.ll
@@ -42,6 +42,21 @@
; RUN: ld.lld --plugin-opt=thinlto-index-only -shared dummy.o --start-lib 1.o --end-lib -o /dev/null
; RUN: ls 1.o.thinlto.bc
+;; Ensure when the same bitcode object is given as both lazy and non-lazy,
+;; LLD does not generate an empty index for the lazy object.
+; RUN: rm -f 2.o.thinlto.bc
+; RUN: ld.lld --plugin-opt=thinlto-index-only -shared 1.o 2.o --start-lib 2.o --end-lib -o /dev/null
+; RUN: llvm-dis < 2.o.thinlto.bc | grep -q '\^0 = module:'
+; RUN: rm -f 2.o.thinlto.bc
+; RUN: ld.lld --plugin-opt=thinlto-index-only -shared --start-lib 2.o --end-lib 2.o 1.o -o /dev/null
+; RUN: llvm-dis < 2.o.thinlto.bc | grep -q '\^0 = module:'
+
+;; Ensure when the same lazy bitcode object is given multiple times,
+;; no empty index file is generated if one of the copies is linked.
+; RUN: rm -f 2.o.thinlto.bc
+; 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
+; RUN: llvm-dis < 2.o.thinlto.bc | grep -q '\^0 = module:'
+
; NM: T f
;; The backend index for this module contains summaries from itself and
More information about the llvm-commits
mailing list