Skip to content

Commit fd791f0

Browse files
committed
[ELF] Move TarWriter into Ctx. NFC
Similar to e980f16.
1 parent b7e4fba commit fd791f0

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

lld/ELF/Config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/Support/FileSystem.h"
2828
#include "llvm/Support/GlobPattern.h"
2929
#include "llvm/Support/PrettyStackTrace.h"
30+
#include "llvm/Support/TarWriter.h"
3031
#include <atomic>
3132
#include <memory>
3233
#include <optional>
@@ -489,6 +490,9 @@ struct Ctx {
489490
std::pair<const InputFile *, const InputFile *>>
490491
backwardReferences;
491492
llvm::SmallSet<llvm::StringRef, 0> auxiliaryFiles;
493+
// If --reproduce is specified, all input files are written to this tar
494+
// archive.
495+
std::unique_ptr<llvm::TarWriter> tar;
492496
// InputFile for linker created symbols with no source location.
493497
InputFile *internalFile;
494498
// True if SHT_LLVM_SYMPART is used.

lld/ELF/Driver.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ void Ctx::reset() {
106106
whyExtractRecords.clear();
107107
backwardReferences.clear();
108108
auxiliaryFiles.clear();
109+
tar.reset();
109110
internalFile = nullptr;
110111
hasSympart.store(false, std::memory_order_relaxed);
111112
hasTlsIe.store(false, std::memory_order_relaxed);
@@ -138,7 +139,6 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
138139
outputSections.clear();
139140
symAux.clear();
140141

141-
tar = nullptr;
142142
in.reset();
143143

144144
partitions.clear();
@@ -224,14 +224,15 @@ std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
224224

225225
std::vector<std::pair<MemoryBufferRef, uint64_t>> v;
226226
Error err = Error::success();
227-
bool addToTar = file->isThin() && tar;
227+
bool addToTar = file->isThin() && ctx.tar;
228228
for (const Archive::Child &c : file->children(err)) {
229229
MemoryBufferRef mbref =
230230
CHECK(c.getMemoryBufferRef(),
231231
mb.getBufferIdentifier() +
232232
": could not get the buffer for a child of the archive");
233233
if (addToTar)
234-
tar->append(relativeToRoot(check(c.getFullName())), mbref.getBuffer());
234+
ctx.tar->append(relativeToRoot(check(c.getFullName())),
235+
mbref.getBuffer());
235236
v.push_back(std::make_pair(mbref, c.getChildOffset()));
236237
}
237238
if (err)
@@ -640,9 +641,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
640641
Expected<std::unique_ptr<TarWriter>> errOrWriter =
641642
TarWriter::create(path, path::stem(path));
642643
if (errOrWriter) {
643-
tar = std::move(*errOrWriter);
644-
tar->append("response.txt", createResponseFile(args));
645-
tar->append("version.txt", getLLDVersion() + "\n");
644+
ctx.tar = std::move(*errOrWriter);
645+
ctx.tar->append("response.txt", createResponseFile(args));
646+
ctx.tar->append("version.txt", getLLDVersion() + "\n");
646647
StringRef ltoSampleProfile = args.getLastArgValue(OPT_lto_sample_profile);
647648
if (!ltoSampleProfile.empty())
648649
readFile(ltoSampleProfile);

lld/ELF/InputFiles.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "llvm/Support/FileSystem.h"
2929
#include "llvm/Support/Path.h"
3030
#include "llvm/Support/RISCVAttributeParser.h"
31-
#include "llvm/Support/TarWriter.h"
3231
#include "llvm/Support/TimeProfiler.h"
3332
#include "llvm/Support/raw_ostream.h"
3433
#include <optional>
@@ -52,8 +51,6 @@ extern template void ObjFile<ELF64BE>::importCmseSymbols();
5251
bool InputFile::isInGroup;
5352
uint32_t InputFile::nextGroupId;
5453

55-
std::unique_ptr<TarWriter> elf::tar;
56-
5754
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
5855
std::string lld::toString(const InputFile *f) {
5956
static std::mutex mu;
@@ -261,8 +258,8 @@ std::optional<MemoryBufferRef> elf::readFile(StringRef path) {
261258
MemoryBufferRef mbref = (*mbOrErr)->getMemBufferRef();
262259
ctx.memoryBuffers.push_back(std::move(*mbOrErr)); // take MB ownership
263260

264-
if (tar)
265-
tar->append(relativeToRoot(path), mbref.getBuffer());
261+
if (ctx.tar)
262+
ctx.tar->append(relativeToRoot(path), mbref.getBuffer());
266263
return mbref;
267264
}
268265

lld/ELF/InputFiles.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ namespace elf {
3939
class InputSection;
4040
class Symbol;
4141

42-
// If --reproduce is specified, all input files are written to this tar archive.
43-
extern std::unique_ptr<llvm::TarWriter> tar;
44-
4542
// Opens a given file.
4643
std::optional<MemoryBufferRef> readFile(StringRef path);
4744

0 commit comments

Comments
 (0)