diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -553,12 +553,15 @@ static bool compileBitcodeFiles() { TimeTraceScope timeScope("LTO"); auto *lto = make(); + bool hasFiles = false; for (InputFile *file : inputFiles) if (auto *bitcodeFile = dyn_cast(file)) - if (!file->lazy) + if (!file->lazy) { + hasFiles = true; lto->add(*bitcodeFile); + } - std::vector compiled = lto->compile(); + std::vector compiled = lto->compile(hasFiles); for (ObjFile *file : compiled) inputFiles.insert(file); diff --git a/lld/MachO/LTO.h b/lld/MachO/LTO.h --- a/lld/MachO/LTO.h +++ b/lld/MachO/LTO.h @@ -31,7 +31,7 @@ BitcodeCompiler(); void add(BitcodeFile &f); - std::vector compile(); + std::vector compile(bool hasFilesToCompile); private: std::unique_ptr ltoObj; diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -195,7 +195,7 @@ // Merge all the bitcode files we have seen, codegen the result // and return the resulting ObjectFile(s). -std::vector BitcodeCompiler::compile() { +std::vector BitcodeCompiler::compile(bool hasFilesToCompile) { unsigned maxTasks = ltoObj->getMaxTasks(); buf.resize(maxTasks); files.resize(maxTasks); @@ -211,7 +211,8 @@ files[task] = std::move(mb); })); - checkError(ltoObj->run( + if (hasFilesToCompile) + checkError(ltoObj->run( [&](size_t task, const Twine &moduleName) { return std::make_unique( std::make_unique(buf[task])); diff --git a/lld/test/MachO/lto-object-path.ll b/lld/test/MachO/lto-object-path.ll --- 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,NOLTOPATH -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 +; NOLTOPATH-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"