[lld] a39ba6e - [LLD][COFF] Move Archive::create call to LinkerDriver::addBuffer (NFC) (#194346)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 02:47:17 PDT 2026
Author: Jacek Caban
Date: 2026-04-29T11:47:12+02:00
New Revision: a39ba6ed4c58a83a7e8f95e643282e6b17503e05
URL: https://github.com/llvm/llvm-project/commit/a39ba6ed4c58a83a7e8f95e643282e6b17503e05
DIFF: https://github.com/llvm/llvm-project/commit/a39ba6ed4c58a83a7e8f95e643282e6b17503e05.diff
LOG: [LLD][COFF] Move Archive::create call to LinkerDriver::addBuffer (NFC) (#194346)
This allows an upcoming change to Archive::create() to make decisions
based on the archive type.
Added:
Modified:
lld/COFF/Driver.cpp
lld/COFF/InputFiles.cpp
lld/COFF/InputFiles.h
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 6d0973c1d0b78..c08ffbd8ae839 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -291,10 +291,10 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
case file_magic::windows_resource:
resources.push_back(mbref);
break;
- case file_magic::archive:
+ case file_magic::archive: {
+ std::unique_ptr<Archive> file =
+ CHECK(Archive::create(mbref), filename + ": failed to parse archive");
if (wholeArchive) {
- std::unique_ptr<Archive> file =
- CHECK(Archive::create(mbref), filename + ": failed to parse archive");
Archive *archive = file.get();
make<std::unique_ptr<Archive>>(std::move(file)); // take ownership
@@ -308,8 +308,9 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
return;
}
- addFile(make<ArchiveFile>(ctx, mbref));
+ addFile(make<ArchiveFile>(ctx, mbref, file));
break;
+ }
case file_magic::bitcode:
addFile(BitcodeFile::create(ctx, mbref, "", 0, lazy));
break;
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index 5e66ff182cd96..0c29e7f670550 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -150,16 +150,16 @@ static bool fixupDllMain(COFFLinkerContext &ctx, llvm::object::Archive *file,
return false;
}
-ArchiveFile::ArchiveFile(COFFLinkerContext &ctx, MemoryBufferRef m)
- : InputFile(ctx.symtab, ArchiveKind, m) {}
+ArchiveFile::ArchiveFile(COFFLinkerContext &ctx, MemoryBufferRef m,
+ std::unique_ptr<Archive> &f)
+ : InputFile(ctx.symtab, ArchiveKind, m) {
+ file.swap(f);
+}
void ArchiveFile::parse() {
COFFLinkerContext &ctx = symtab.ctx;
SymbolTable *archiveSymtab = &symtab;
- // Parse a MemoryBufferRef as an archive file.
- file = CHECK(Archive::create(mb), this);
-
// Try to read symbols from ECSYMBOLS section on ARM64EC.
if (ctx.symtab.isEC()) {
iterator_range<Archive::symbol_iterator> symbols =
diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h
index 21b9aeef21d4f..ce8bc6705e489 100644
--- a/lld/COFF/InputFiles.h
+++ b/lld/COFF/InputFiles.h
@@ -118,7 +118,8 @@ class InputFile {
// .lib or .a file.
class ArchiveFile : public InputFile {
public:
- explicit ArchiveFile(COFFLinkerContext &ctx, MemoryBufferRef m);
+ explicit ArchiveFile(COFFLinkerContext &ctx, MemoryBufferRef mb,
+ std::unique_ptr<Archive> &f);
static bool classof(const InputFile *f) { return f->kind() == ArchiveKind; }
void parse() override;
More information about the llvm-commits
mailing list