[lld] a65678b - [lld-macho] Avoid running LTO pipeline for no files
Keith Smiley via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 3 15:49:26 PST 2023
Author: Keith Smiley
Date: 2023-03-03T15:28:59-08:00
New Revision: a65678b35bbce31f09aebb2d1188c385b9dbac5e
URL: https://github.com/llvm/llvm-project/commit/a65678b35bbce31f09aebb2d1188c385b9dbac5e
DIFF: https://github.com/llvm/llvm-project/commit/a65678b35bbce31f09aebb2d1188c385b9dbac5e.diff
LOG: [lld-macho] Avoid running LTO pipeline for no files
If no bitcode files are given as inputs but -object_path_lto is passed
we should avoid running the LTO pipeline.
This mirrors this patch from the ELF port https://github.com/llvm/llvm-project/commit/f3994e4dfa0214b2a09a0e327ba37e6b38bbcdb3
Fixes https://github.com/llvm/llvm-project/issues/61031
Differential Revision: https://reviews.llvm.org/D145273
Added:
Modified:
lld/MachO/LTO.cpp
lld/MachO/LTO.h
lld/test/MachO/lto-object-path.ll
Removed:
################################################################################
diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 6e3d4f3c230f..af15336b21ea 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -160,6 +160,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
// TODO: set the other resolution configs properly
}
checkError(ltoObj->add(std::move(f.obj), resols));
+ hasFiles = true;
}
// If LazyObjFile has not been added to link, emit empty index files.
@@ -211,12 +212,13 @@ std::vector<ObjFile *> BitcodeCompiler::compile() {
files[task] = std::move(mb);
}));
- checkError(ltoObj->run(
- [&](size_t task, const Twine &moduleName) {
- return std::make_unique<CachedFileStream>(
- std::make_unique<raw_svector_ostream>(buf[task]));
- },
- cache));
+ if (hasFiles)
+ checkError(ltoObj->run(
+ [&](size_t task, const Twine &moduleName) {
+ return std::make_unique<CachedFileStream>(
+ std::make_unique<raw_svector_ostream>(buf[task]));
+ },
+ cache));
// Emit empty index files for non-indexed files
for (StringRef s : thinIndices) {
diff --git a/lld/MachO/LTO.h b/lld/MachO/LTO.h
index f07b1e39e016..86c39b145070 100644
--- a/lld/MachO/LTO.h
+++ b/lld/MachO/LTO.h
@@ -39,6 +39,7 @@ class BitcodeCompiler {
std::vector<std::unique_ptr<llvm::MemoryBuffer>> files;
std::unique_ptr<llvm::raw_fd_ostream> indexFile;
llvm::DenseSet<StringRef> thinIndices;
+ bool hasFiles = false;
};
} // namespace lld::macho
diff --git a/lld/test/MachO/lto-object-path.ll b/lld/test/MachO/lto-object-path.ll
index d36e536dddd0..93e4e2add9f5 100644
--- a/lld/test/MachO/lto-object-path.ll
+++ b/lld/test/MachO/lto-object-path.ll
@@ -2,12 +2,16 @@
; UNSUPPORTED: system-windows
; RUN: rm -rf %t; mkdir %t
+; RUN: llc -filetype=obj %s -o %t/test-obj.o
; RUN: opt -thinlto-bc %s -o %t/test.o
; RUN: opt %s -o %t/test-nonthin.o
; RUN: %lld %t/test.o -o %t/test
; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,NOOBJPATH
+; RUN: %lld %t/test-obj.o -o %t/test-obj -object_path_lto %t/lto-temps-obj
+; RUN: llvm-nm -pa %t/test-obj | FileCheck %s --check-prefixes CHECK,NOLTOFILES -DDIR=%t
+
; RUN: ZERO_AR_DATE=0 %lld %t/test.o -o %t/test -object_path_lto %t/lto-temps
; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,OBJPATH-DIR -DDIR=%t/lto-temps
@@ -31,10 +35,12 @@
; RUN: touch %t/lto-tmp.o
; RUN: ZERO_AR_DATE=0 %lld %t/test-nonthin.o -o %t/test -object_path_lto %t/lto-tmp.o
; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,OBJPATH-FILE -DFILE=%t/lto-tmp.o
+; RUN: llvm-otool -l %t/lto-tmp.o | FileCheck %s --check-prefixes=MINOS
; CHECK: 0000000000000000 - 00 0000 SO /tmp/test.cpp
; NOOBJPATH-NEXT: 0000000000000000 - 03 0001 OSO /tmp/lto.tmp
+; NOLTOFILES-NEXT: 0000000000000000 - 03 0001 OSO [[DIR]]/test-obj.o
;; check that modTime is nonzero when `-object_path_lto` is provided
; OBJPATH-DIR-NEXT: {{[0-9a-f]*[1-9a-f]+[0-9a-f]*}} - 03 0001 OSO [[DIR]]/1.x86_64.lto.o
; OBJPATH-FILE-NEXT: {{[0-9a-f]*[1-9a-f]+[0-9a-f]*}} - 03 0001 OSO [[FILE]]
@@ -45,6 +51,8 @@
; DSYM: DW_AT_name ("test.cpp")
; HARDLINK: 2
+; MINOS: 10.15
+
target triple = "x86_64-apple-macosx10.15.0"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
More information about the llvm-commits
mailing list