2020-10-26 19:18:29 -07:00
|
|
|
//===- LTO.cpp ------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "LTO.h"
|
|
|
|
#include "Config.h"
|
2020-12-02 20:34:17 -08:00
|
|
|
#include "Driver.h"
|
2020-10-26 19:18:29 -07:00
|
|
|
#include "InputFiles.h"
|
[lld-macho] Basic support for linkage and visibility attributes in LTO
When parsing bitcode, convert LTO Symbols to LLD Symbols in order to perform
resolution. The "winning" symbol will then be marked as Prevailing at LTO
compilation time. This is similar to what the other LLD ports do.
This change allows us to handle `linkonce` symbols correctly, and to deal with
duplicate bitcode symbols gracefully. Previously, both scenarios would result in
an assertion failure inside the LTO code, complaining that multiple Prevailing
definitions are not allowed.
While at it, I also added basic logic around visibility. We don't do anything
useful with it yet, but we do check that its value is valid. LLD-ELF appears to
use it only to set FinalDefinitionInLinkageUnit for LTO, which I think is just a
performance optimization.
From my local experimentation, the linker itself doesn't seem to do anything
differently when encountering linkonce / linkonce_odr / weak / weak_odr. So I've
only written a test for one of them. LLD-ELF has more, but they seem to mostly
be testing the intermediate bitcode output of their LTO backend...? I'm far from
an expert here though, so I might very well be missing things.
Reviewed By: #lld-macho, MaskRay, smeenai
Differential Revision: https://reviews.llvm.org/D94342
2021-02-25 13:27:40 -05:00
|
|
|
#include "Symbols.h"
|
2021-04-02 18:46:18 -04:00
|
|
|
#include "Target.h"
|
2020-10-26 19:18:29 -07:00
|
|
|
|
2021-07-01 15:01:59 -04:00
|
|
|
#include "lld/Common/Args.h"
|
2022-01-20 14:53:18 -05:00
|
|
|
#include "lld/Common/CommonLinkerContext.h"
|
2023-09-28 00:06:48 +02:00
|
|
|
#include "lld/Common/Filesystem.h"
|
2020-10-26 19:18:29 -07:00
|
|
|
#include "lld/Common/Strings.h"
|
|
|
|
#include "lld/Common/TargetOptionsCommandFlags.h"
|
2022-11-20 11:59:16 -05:00
|
|
|
#include "llvm/Bitcode/BitcodeWriter.h"
|
2021-07-15 12:56:13 -04:00
|
|
|
#include "llvm/LTO/Config.h"
|
2020-10-26 19:18:29 -07:00
|
|
|
#include "llvm/LTO/LTO.h"
|
2021-10-18 18:40:57 -07:00
|
|
|
#include "llvm/Support/Caching.h"
|
2020-12-02 20:34:17 -08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
2020-10-26 19:18:29 -07:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2021-01-12 14:41:56 -05:00
|
|
|
#include "llvm/Transforms/ObjCARC.h"
|
2020-10-26 19:18:29 -07:00
|
|
|
|
|
|
|
using namespace lld;
|
|
|
|
using namespace lld::macho;
|
|
|
|
using namespace llvm;
|
2021-04-15 21:14:29 -04:00
|
|
|
using namespace llvm::MachO;
|
2020-12-02 20:34:17 -08:00
|
|
|
using namespace llvm::sys;
|
2020-10-26 19:18:29 -07:00
|
|
|
|
2022-11-20 11:59:16 -05:00
|
|
|
static std::string getThinLTOOutputFile(StringRef modulePath) {
|
2023-04-26 20:43:11 -07:00
|
|
|
return lto::getThinLTOOutputFile(modulePath, config->thinLTOPrefixReplaceOld,
|
|
|
|
config->thinLTOPrefixReplaceNew);
|
2022-11-20 11:59:16 -05:00
|
|
|
}
|
|
|
|
|
2020-10-26 19:18:29 -07:00
|
|
|
static lto::Config createConfig() {
|
|
|
|
lto::Config c;
|
|
|
|
c.Options = initTargetOptionsFromCodeGenFlags();
|
2022-06-12 17:26:08 -04:00
|
|
|
c.Options.EmitAddrsig = config->icfLevel == ICFLevel::safe;
|
2022-11-14 14:23:56 -05:00
|
|
|
for (StringRef C : config->mllvmOpts)
|
|
|
|
c.MllvmArgs.emplace_back(C.str());
|
2020-12-08 05:08:56 -08:00
|
|
|
c.CodeModel = getCodeModelFromCMModel();
|
|
|
|
c.CPU = getCPUStr();
|
|
|
|
c.MAttrs = getMAttrs();
|
2021-09-04 17:40:07 -04:00
|
|
|
c.DiagHandler = diagnosticHandler;
|
2024-05-24 08:13:24 +02:00
|
|
|
c.PreCodeGenPassesHook = [](legacy::PassManager &pm) {
|
|
|
|
pm.add(createObjCARCContractPass());
|
|
|
|
};
|
2022-11-20 11:59:16 -05:00
|
|
|
|
|
|
|
c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty();
|
|
|
|
|
2021-03-25 00:57:39 -04:00
|
|
|
c.TimeTraceEnabled = config->timeTraceEnabled;
|
|
|
|
c.TimeTraceGranularity = config->timeTraceGranularity;
|
2023-05-31 14:02:23 -07:00
|
|
|
c.DebugPassManager = config->ltoDebugPassManager;
|
2023-05-31 14:17:35 -07:00
|
|
|
c.CSIRProfile = std::string(config->csProfilePath);
|
|
|
|
c.RunCSIRInstr = config->csProfileGenerate;
|
2023-09-11 09:13:55 -07:00
|
|
|
c.PGOWarnMismatch = config->pgoWarnMismatch;
|
2021-07-01 15:01:59 -04:00
|
|
|
c.OptLevel = config->ltoo;
|
2023-02-15 17:12:47 +00:00
|
|
|
c.CGOptLevel = config->ltoCgo;
|
2021-04-15 21:14:29 -04:00
|
|
|
if (config->saveTemps)
|
|
|
|
checkError(c.addSaveTemps(config->outputFile.str() + ".",
|
|
|
|
/*UseInputModulePath=*/true));
|
2020-10-26 19:18:29 -07:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2022-09-02 13:50:01 -04:00
|
|
|
// If `originalPath` exists, hardlinks `path` to `originalPath`. If that fails,
|
|
|
|
// or `originalPath` is not set, saves `buffer` to `path`.
|
|
|
|
static void saveOrHardlinkBuffer(StringRef buffer, const Twine &path,
|
2022-11-27 16:54:07 -08:00
|
|
|
std::optional<StringRef> originalPath) {
|
2022-09-02 13:50:01 -04:00
|
|
|
if (originalPath) {
|
|
|
|
auto err = fs::create_hard_link(*originalPath, path);
|
|
|
|
if (!err)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
saveBuffer(buffer, path);
|
|
|
|
}
|
|
|
|
|
2020-10-26 19:18:29 -07:00
|
|
|
BitcodeCompiler::BitcodeCompiler() {
|
2022-11-20 11:59:16 -05:00
|
|
|
// Initialize indexFile.
|
|
|
|
if (!config->thinLTOIndexOnlyArg.empty())
|
|
|
|
indexFile = openFile(config->thinLTOIndexOnlyArg);
|
|
|
|
|
|
|
|
// Initialize ltoObj.
|
|
|
|
lto::ThinBackend backend;
|
|
|
|
auto onIndexWrite = [&](StringRef S) { thinIndices.erase(S); };
|
|
|
|
if (config->thinLTOIndexOnly) {
|
|
|
|
backend = lto::createWriteIndexesThinBackend(
|
2023-04-04 09:57:53 -07:00
|
|
|
std::string(config->thinLTOPrefixReplaceOld),
|
|
|
|
std::string(config->thinLTOPrefixReplaceNew),
|
|
|
|
std::string(config->thinLTOPrefixReplaceNativeObject),
|
2022-11-20 11:59:16 -05:00
|
|
|
config->thinLTOEmitImportsFiles, indexFile.get(), onIndexWrite);
|
|
|
|
} else {
|
|
|
|
backend = lto::createInProcessThinBackend(
|
|
|
|
llvm::heavyweight_hardware_concurrency(config->thinLTOJobs),
|
|
|
|
onIndexWrite, config->thinLTOEmitIndexFiles,
|
|
|
|
config->thinLTOEmitImportsFiles);
|
|
|
|
}
|
|
|
|
|
2020-10-26 19:18:29 -07:00
|
|
|
ltoObj = std::make_unique<lto::LTO>(createConfig(), backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitcodeCompiler::add(BitcodeFile &f) {
|
2022-11-20 11:59:16 -05:00
|
|
|
lto::InputFile &obj = *f.obj;
|
|
|
|
|
|
|
|
if (config->thinLTOEmitIndexFiles)
|
|
|
|
thinIndices.insert(obj.getName());
|
|
|
|
|
|
|
|
ArrayRef<lto::InputFile::Symbol> objSyms = obj.symbols();
|
2020-10-26 19:18:29 -07:00
|
|
|
std::vector<lto::SymbolResolution> resols;
|
|
|
|
resols.reserve(objSyms.size());
|
|
|
|
|
|
|
|
// Provide a resolution to the LTO API for each symbol.
|
2022-02-11 22:24:09 -05:00
|
|
|
bool exportDynamic =
|
|
|
|
config->outputType != MH_EXECUTE || config->exportDynamic;
|
[lld-macho] Basic support for linkage and visibility attributes in LTO
When parsing bitcode, convert LTO Symbols to LLD Symbols in order to perform
resolution. The "winning" symbol will then be marked as Prevailing at LTO
compilation time. This is similar to what the other LLD ports do.
This change allows us to handle `linkonce` symbols correctly, and to deal with
duplicate bitcode symbols gracefully. Previously, both scenarios would result in
an assertion failure inside the LTO code, complaining that multiple Prevailing
definitions are not allowed.
While at it, I also added basic logic around visibility. We don't do anything
useful with it yet, but we do check that its value is valid. LLD-ELF appears to
use it only to set FinalDefinitionInLinkageUnit for LTO, which I think is just a
performance optimization.
From my local experimentation, the linker itself doesn't seem to do anything
differently when encountering linkonce / linkonce_odr / weak / weak_odr. So I've
only written a test for one of them. LLD-ELF has more, but they seem to mostly
be testing the intermediate bitcode output of their LTO backend...? I'm far from
an expert here though, so I might very well be missing things.
Reviewed By: #lld-macho, MaskRay, smeenai
Differential Revision: https://reviews.llvm.org/D94342
2021-02-25 13:27:40 -05:00
|
|
|
auto symIt = f.symbols.begin();
|
2020-10-26 19:18:29 -07:00
|
|
|
for (const lto::InputFile::Symbol &objSym : objSyms) {
|
|
|
|
resols.emplace_back();
|
|
|
|
lto::SymbolResolution &r = resols.back();
|
[lld-macho] Basic support for linkage and visibility attributes in LTO
When parsing bitcode, convert LTO Symbols to LLD Symbols in order to perform
resolution. The "winning" symbol will then be marked as Prevailing at LTO
compilation time. This is similar to what the other LLD ports do.
This change allows us to handle `linkonce` symbols correctly, and to deal with
duplicate bitcode symbols gracefully. Previously, both scenarios would result in
an assertion failure inside the LTO code, complaining that multiple Prevailing
definitions are not allowed.
While at it, I also added basic logic around visibility. We don't do anything
useful with it yet, but we do check that its value is valid. LLD-ELF appears to
use it only to set FinalDefinitionInLinkageUnit for LTO, which I think is just a
performance optimization.
From my local experimentation, the linker itself doesn't seem to do anything
differently when encountering linkonce / linkonce_odr / weak / weak_odr. So I've
only written a test for one of them. LLD-ELF has more, but they seem to mostly
be testing the intermediate bitcode output of their LTO backend...? I'm far from
an expert here though, so I might very well be missing things.
Reviewed By: #lld-macho, MaskRay, smeenai
Differential Revision: https://reviews.llvm.org/D94342
2021-02-25 13:27:40 -05:00
|
|
|
Symbol *sym = *symIt++;
|
2020-10-26 19:18:29 -07:00
|
|
|
|
|
|
|
// Ideally we shouldn't check for SF_Undefined but currently IRObjectFile
|
|
|
|
// reports two symbols for module ASM defined. Without this check, lld
|
|
|
|
// flags an undefined in IR with a definition in ASM as prevailing.
|
|
|
|
// Once IRObjectFile is fixed to report only one symbol this hack can
|
|
|
|
// be removed.
|
[lld-macho] Basic support for linkage and visibility attributes in LTO
When parsing bitcode, convert LTO Symbols to LLD Symbols in order to perform
resolution. The "winning" symbol will then be marked as Prevailing at LTO
compilation time. This is similar to what the other LLD ports do.
This change allows us to handle `linkonce` symbols correctly, and to deal with
duplicate bitcode symbols gracefully. Previously, both scenarios would result in
an assertion failure inside the LTO code, complaining that multiple Prevailing
definitions are not allowed.
While at it, I also added basic logic around visibility. We don't do anything
useful with it yet, but we do check that its value is valid. LLD-ELF appears to
use it only to set FinalDefinitionInLinkageUnit for LTO, which I think is just a
performance optimization.
From my local experimentation, the linker itself doesn't seem to do anything
differently when encountering linkonce / linkonce_odr / weak / weak_odr. So I've
only written a test for one of them. LLD-ELF has more, but they seem to mostly
be testing the intermediate bitcode output of their LTO backend...? I'm far from
an expert here though, so I might very well be missing things.
Reviewed By: #lld-macho, MaskRay, smeenai
Differential Revision: https://reviews.llvm.org/D94342
2021-02-25 13:27:40 -05:00
|
|
|
r.Prevailing = !objSym.isUndefined() && sym->getFile() == &f;
|
|
|
|
|
2022-03-15 20:25:06 -04:00
|
|
|
if (const auto *defined = dyn_cast<Defined>(sym)) {
|
2022-02-11 22:24:09 -05:00
|
|
|
r.ExportDynamic =
|
|
|
|
defined->isExternal() && !defined->privateExtern && exportDynamic;
|
2022-03-15 20:25:06 -04:00
|
|
|
r.FinalDefinitionInLinkageUnit =
|
|
|
|
!defined->isExternalWeakDef() && !defined->interposable;
|
|
|
|
} else if (const auto *common = dyn_cast<CommonSymbol>(sym)) {
|
2022-02-11 22:24:09 -05:00
|
|
|
r.ExportDynamic = !common->privateExtern && exportDynamic;
|
2022-03-15 20:25:06 -04:00
|
|
|
r.FinalDefinitionInLinkageUnit = true;
|
|
|
|
}
|
2022-02-11 22:24:09 -05:00
|
|
|
|
|
|
|
r.VisibleToRegularObj =
|
|
|
|
sym->isUsedInRegularObj || (r.Prevailing && r.ExportDynamic);
|
2021-04-15 21:14:29 -04:00
|
|
|
|
[lld-macho] Basic support for linkage and visibility attributes in LTO
When parsing bitcode, convert LTO Symbols to LLD Symbols in order to perform
resolution. The "winning" symbol will then be marked as Prevailing at LTO
compilation time. This is similar to what the other LLD ports do.
This change allows us to handle `linkonce` symbols correctly, and to deal with
duplicate bitcode symbols gracefully. Previously, both scenarios would result in
an assertion failure inside the LTO code, complaining that multiple Prevailing
definitions are not allowed.
While at it, I also added basic logic around visibility. We don't do anything
useful with it yet, but we do check that its value is valid. LLD-ELF appears to
use it only to set FinalDefinitionInLinkageUnit for LTO, which I think is just a
performance optimization.
From my local experimentation, the linker itself doesn't seem to do anything
differently when encountering linkonce / linkonce_odr / weak / weak_odr. So I've
only written a test for one of them. LLD-ELF has more, but they seem to mostly
be testing the intermediate bitcode output of their LTO backend...? I'm far from
an expert here though, so I might very well be missing things.
Reviewed By: #lld-macho, MaskRay, smeenai
Differential Revision: https://reviews.llvm.org/D94342
2021-02-25 13:27:40 -05:00
|
|
|
// Un-define the symbol so that we don't get duplicate symbol errors when we
|
|
|
|
// load the ObjFile emitted by LTO compilation.
|
|
|
|
if (r.Prevailing)
|
|
|
|
replaceSymbol<Undefined>(sym, sym->getName(), sym->getFile(),
|
2022-10-21 22:48:25 -04:00
|
|
|
RefState::Strong, /*wasBitcodeSymbol=*/true);
|
2020-10-26 19:18:29 -07:00
|
|
|
|
|
|
|
// TODO: set the other resolution configs properly
|
|
|
|
}
|
|
|
|
checkError(ltoObj->add(std::move(f.obj), resols));
|
2023-03-03 13:27:03 -08:00
|
|
|
hasFiles = true;
|
2020-10-26 19:18:29 -07:00
|
|
|
}
|
|
|
|
|
2022-11-20 11:59:16 -05:00
|
|
|
// If LazyObjFile has not been added to link, emit empty index files.
|
|
|
|
// 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 (InputFile *file : inputFiles)
|
|
|
|
if (auto *f = dyn_cast<BitcodeFile>(file))
|
|
|
|
if (!f->lazy)
|
|
|
|
linkedBitCodeFiles.insert(f->getName());
|
|
|
|
|
|
|
|
for (InputFile *file : inputFiles) {
|
|
|
|
if (auto *f = dyn_cast<BitcodeFile>(file)) {
|
|
|
|
if (!f->lazy)
|
|
|
|
continue;
|
|
|
|
if (linkedBitCodeFiles.contains(f->getName()))
|
|
|
|
continue;
|
|
|
|
std::string path =
|
|
|
|
replaceThinLTOSuffix(getThinLTOOutputFile(f->obj->getName()));
|
|
|
|
std::unique_ptr<raw_fd_ostream> os = openFile(path + ".thinlto.bc");
|
|
|
|
if (!os)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ModuleSummaryIndex m(/*HaveGVs=*/false);
|
|
|
|
m.setSkipModuleByDistributedBackend();
|
|
|
|
writeIndexToFile(m, *os);
|
|
|
|
if (config->thinLTOEmitImportsFiles)
|
|
|
|
openFile(path + ".imports");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 19:18:29 -07:00
|
|
|
// Merge all the bitcode files we have seen, codegen the result
|
|
|
|
// and return the resulting ObjectFile(s).
|
|
|
|
std::vector<ObjFile *> BitcodeCompiler::compile() {
|
|
|
|
unsigned maxTasks = ltoObj->getMaxTasks();
|
|
|
|
buf.resize(maxTasks);
|
2021-07-15 12:56:13 -04:00
|
|
|
files.resize(maxTasks);
|
|
|
|
|
|
|
|
// The -cache_path_lto option specifies the path to a directory in which
|
|
|
|
// to cache native object files for ThinLTO incremental builds. If a path was
|
|
|
|
// specified, configure LTO to use it as the cache directory.
|
2021-11-04 12:59:59 -07:00
|
|
|
FileCache cache;
|
2021-07-15 12:56:13 -04:00
|
|
|
if (!config->thinLTOCacheDir.empty())
|
2022-11-22 13:46:42 -08:00
|
|
|
cache = check(localCache("ThinLTO", "Thin", config->thinLTOCacheDir,
|
|
|
|
[&](size_t task, const Twine &moduleName,
|
|
|
|
std::unique_ptr<MemoryBuffer> mb) {
|
|
|
|
files[task] = std::move(mb);
|
|
|
|
}));
|
2021-07-15 12:56:13 -04:00
|
|
|
|
2023-03-03 13:27:03 -08:00
|
|
|
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));
|
2021-07-15 12:56:13 -04:00
|
|
|
|
2022-11-20 11:59:16 -05:00
|
|
|
// Emit empty index files for non-indexed files
|
|
|
|
for (StringRef s : thinIndices) {
|
|
|
|
std::string path = getThinLTOOutputFile(s);
|
|
|
|
openFile(path + ".thinlto.bc");
|
|
|
|
if (config->thinLTOEmitImportsFiles)
|
|
|
|
openFile(path + ".imports");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->thinLTOEmitIndexFiles)
|
|
|
|
thinLTOCreateEmptyIndexFiles();
|
2020-10-26 19:18:29 -07:00
|
|
|
|
2022-07-14 01:17:48 +02:00
|
|
|
// In ThinLTO mode, Clang passes a temporary directory in -object_path_lto,
|
|
|
|
// while the argument is a single file in FullLTO mode.
|
|
|
|
bool objPathIsDir = true;
|
|
|
|
if (!config->ltoObjPath.empty()) {
|
|
|
|
if (std::error_code ec = fs::create_directories(config->ltoObjPath))
|
|
|
|
fatal("cannot create LTO object path " + config->ltoObjPath + ": " +
|
|
|
|
ec.message());
|
|
|
|
|
|
|
|
if (!fs::is_directory(config->ltoObjPath)) {
|
|
|
|
objPathIsDir = false;
|
|
|
|
unsigned objCount =
|
|
|
|
count_if(buf, [](const SmallString<0> &b) { return !b.empty(); });
|
|
|
|
if (objCount > 1)
|
|
|
|
fatal("-object_path_lto must specify a directory when using ThinLTO");
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 20:34:17 -08:00
|
|
|
|
2022-11-20 11:59:16 -05:00
|
|
|
auto outputFilePath = [objPathIsDir](int i) {
|
|
|
|
SmallString<261> filePath("/tmp/lto.tmp");
|
|
|
|
if (!config->ltoObjPath.empty()) {
|
|
|
|
filePath = config->ltoObjPath;
|
|
|
|
if (objPathIsDir)
|
|
|
|
path::append(filePath, Twine(i) + "." +
|
|
|
|
getArchitectureName(config->arch()) +
|
|
|
|
".lto.o");
|
|
|
|
}
|
|
|
|
return filePath;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ThinLTO with index only option is required to generate only the index
|
|
|
|
// files. After that, we exit from linker and ThinLTO backend runs in a
|
|
|
|
// distributed environment.
|
|
|
|
if (config->thinLTOIndexOnly) {
|
|
|
|
if (!config->ltoObjPath.empty())
|
|
|
|
saveBuffer(buf[0], outputFilePath(0));
|
|
|
|
if (indexFile)
|
|
|
|
indexFile->close();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!config->thinLTOCacheDir.empty())
|
|
|
|
pruneCache(config->thinLTOCacheDir, config->thinLTOCachePolicy, files);
|
|
|
|
|
2020-10-26 19:18:29 -07:00
|
|
|
std::vector<ObjFile *> ret;
|
2022-08-10 17:44:27 -04:00
|
|
|
for (unsigned i = 0; i < maxTasks; ++i) {
|
|
|
|
// Get the native object contents either from the cache or from memory. Do
|
|
|
|
// not use the cached MemoryBuffer directly to ensure dsymutil does not
|
|
|
|
// race with the cache pruner.
|
|
|
|
StringRef objBuf;
|
2023-01-14 14:06:18 -08:00
|
|
|
std::optional<StringRef> cachePath;
|
2022-09-02 13:50:01 -04:00
|
|
|
if (files[i]) {
|
2022-08-10 17:44:27 -04:00
|
|
|
objBuf = files[i]->getBuffer();
|
2022-09-02 13:50:01 -04:00
|
|
|
cachePath = files[i]->getBufferIdentifier();
|
|
|
|
} else {
|
2022-08-10 17:44:27 -04:00
|
|
|
objBuf = buf[i];
|
2022-09-02 13:50:01 -04:00
|
|
|
}
|
2022-08-10 17:44:27 -04:00
|
|
|
if (objBuf.empty())
|
2020-12-02 20:34:17 -08:00
|
|
|
continue;
|
2022-08-10 17:44:27 -04:00
|
|
|
|
|
|
|
// FIXME: should `saveTemps` and `ltoObjPath` use the same file name?
|
|
|
|
if (config->saveTemps)
|
|
|
|
saveBuffer(objBuf,
|
|
|
|
config->outputFile + ((i == 0) ? "" : Twine(i)) + ".lto.o");
|
|
|
|
|
2022-11-20 11:59:16 -05:00
|
|
|
auto filePath = outputFilePath(i);
|
2020-12-02 20:34:17 -08:00
|
|
|
uint32_t modTime = 0;
|
|
|
|
if (!config->ltoObjPath.empty()) {
|
2022-09-02 13:50:01 -04:00
|
|
|
saveOrHardlinkBuffer(objBuf, filePath, cachePath);
|
2020-12-02 20:34:17 -08:00
|
|
|
modTime = getModTime(filePath);
|
|
|
|
}
|
|
|
|
ret.push_back(make<ObjFile>(
|
2023-08-22 12:02:52 -07:00
|
|
|
MemoryBufferRef(objBuf, saver().save(filePath.str())), modTime,
|
|
|
|
/*archiveName=*/"", /*lazy=*/false,
|
|
|
|
/*forceHidden=*/false, /*compatArch=*/true, /*builtFromBitcode=*/true));
|
2020-12-02 20:34:17 -08:00
|
|
|
}
|
2022-08-10 17:44:27 -04:00
|
|
|
|
2020-10-26 19:18:29 -07:00
|
|
|
return ret;
|
|
|
|
}
|