[lld] fd791f0 - [ELF] Move TarWriter into Ctx. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 15:32:27 PDT 2024
Author: Fangrui Song
Date: 2024-07-28T15:32:22-07:00
New Revision: fd791f0fe562a41d8569fcb4d1e84b4c1e5719c7
URL: https://github.com/llvm/llvm-project/commit/fd791f0fe562a41d8569fcb4d1e84b4c1e5719c7
DIFF: https://github.com/llvm/llvm-project/commit/fd791f0fe562a41d8569fcb4d1e84b4c1e5719c7.diff
LOG: [ELF] Move TarWriter into Ctx. NFC
Similar to e980f16d52196fb2bc672ecb87e0f622253addec.
Added:
Modified:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/InputFiles.h
Removed:
################################################################################
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 0173be396163e..2f6758743c0d6 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -27,6 +27,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/GlobPattern.h"
#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/TarWriter.h"
#include <atomic>
#include <memory>
#include <optional>
@@ -489,6 +490,9 @@ struct Ctx {
std::pair<const InputFile *, const InputFile *>>
backwardReferences;
llvm::SmallSet<llvm::StringRef, 0> auxiliaryFiles;
+ // If --reproduce is specified, all input files are written to this tar
+ // archive.
+ std::unique_ptr<llvm::TarWriter> tar;
// InputFile for linker created symbols with no source location.
InputFile *internalFile;
// True if SHT_LLVM_SYMPART is used.
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 63dbd0ea3f95a..cd85040a4ca73 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -106,6 +106,7 @@ void Ctx::reset() {
whyExtractRecords.clear();
backwardReferences.clear();
auxiliaryFiles.clear();
+ tar.reset();
internalFile = nullptr;
hasSympart.store(false, std::memory_order_relaxed);
hasTlsIe.store(false, std::memory_order_relaxed);
@@ -138,7 +139,6 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
outputSections.clear();
symAux.clear();
- tar = nullptr;
in.reset();
partitions.clear();
@@ -224,14 +224,15 @@ std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
std::vector<std::pair<MemoryBufferRef, uint64_t>> v;
Error err = Error::success();
- bool addToTar = file->isThin() && tar;
+ bool addToTar = file->isThin() && ctx.tar;
for (const Archive::Child &c : file->children(err)) {
MemoryBufferRef mbref =
CHECK(c.getMemoryBufferRef(),
mb.getBufferIdentifier() +
": could not get the buffer for a child of the archive");
if (addToTar)
- tar->append(relativeToRoot(check(c.getFullName())), mbref.getBuffer());
+ ctx.tar->append(relativeToRoot(check(c.getFullName())),
+ mbref.getBuffer());
v.push_back(std::make_pair(mbref, c.getChildOffset()));
}
if (err)
@@ -640,9 +641,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
Expected<std::unique_ptr<TarWriter>> errOrWriter =
TarWriter::create(path, path::stem(path));
if (errOrWriter) {
- tar = std::move(*errOrWriter);
- tar->append("response.txt", createResponseFile(args));
- tar->append("version.txt", getLLDVersion() + "\n");
+ ctx.tar = std::move(*errOrWriter);
+ ctx.tar->append("response.txt", createResponseFile(args));
+ ctx.tar->append("version.txt", getLLDVersion() + "\n");
StringRef ltoSampleProfile = args.getLastArgValue(OPT_lto_sample_profile);
if (!ltoSampleProfile.empty())
readFile(ltoSampleProfile);
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 03ff4eadfe670..3bc39848d6035 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -28,7 +28,6 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/RISCVAttributeParser.h"
-#include "llvm/Support/TarWriter.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
@@ -52,8 +51,6 @@ extern template void ObjFile<ELF64BE>::importCmseSymbols();
bool InputFile::isInGroup;
uint32_t InputFile::nextGroupId;
-std::unique_ptr<TarWriter> elf::tar;
-
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
std::string lld::toString(const InputFile *f) {
static std::mutex mu;
@@ -261,8 +258,8 @@ std::optional<MemoryBufferRef> elf::readFile(StringRef path) {
MemoryBufferRef mbref = (*mbOrErr)->getMemBufferRef();
ctx.memoryBuffers.push_back(std::move(*mbOrErr)); // take MB ownership
- if (tar)
- tar->append(relativeToRoot(path), mbref.getBuffer());
+ if (ctx.tar)
+ ctx.tar->append(relativeToRoot(path), mbref.getBuffer());
return mbref;
}
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index 0617f41e1e13a..755b30de12bc7 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -39,9 +39,6 @@ namespace elf {
class InputSection;
class Symbol;
-// If --reproduce is specified, all input files are written to this tar archive.
-extern std::unique_ptr<llvm::TarWriter> tar;
-
// Opens a given file.
std::optional<MemoryBufferRef> readFile(StringRef path);
More information about the llvm-commits
mailing list