Skip to content

Commit 821a1ac

Browse files
committed
Remove LazyObjFile::AddedToLink.
Instead we can just clear a MemoryBuffer so that we cannot get the same buffer more than once. llvm-svn: 361477
1 parent 4bce63a commit 821a1ac

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,21 +1469,15 @@ InputFile *elf::createSharedFile(MemoryBufferRef MB, StringRef DefaultSoName) {
14691469
return F;
14701470
}
14711471

1472-
MemoryBufferRef LazyObjFile::getBuffer() {
1473-
if (AddedToLink)
1474-
return MemoryBufferRef();
1475-
AddedToLink = true;
1476-
return MB;
1477-
}
1478-
14791472
InputFile *LazyObjFile::fetch() {
1480-
MemoryBufferRef MBRef = getBuffer();
1481-
if (MBRef.getBuffer().empty())
1473+
if (MB.getBuffer().empty())
14821474
return nullptr;
14831475

1484-
InputFile *File = createObjectFile(MBRef, ArchiveName, OffsetInArchive);
1476+
InputFile *File = createObjectFile(MB, ArchiveName, OffsetInArchive);
14851477
File->GroupId = GroupId;
14861478

1479+
MB = {};
1480+
14871481
// Copy symbol vector so that the new InputFile doesn't have to
14881482
// insert the same defined symbols to the symbol table again.
14891483
File->Symbols = std::move(Symbols);
@@ -1538,7 +1532,9 @@ template <class ELFT> void LazyObjFile::parse() {
15381532
if (!Sym)
15391533
continue;
15401534
Sym->resolve(LazyObject{*this, Sym->getName()});
1541-
if (AddedToLink)
1535+
1536+
// MemoryBuffer is emptied if this file is instantiated as ObjFile.
1537+
if (MB.getBuffer().empty())
15421538
return;
15431539
}
15441540
return;

lld/ELF/InputFiles.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,7 @@ class LazyObjFile : public InputFile {
307307
static bool classof(const InputFile *F) { return F->kind() == LazyObjKind; }
308308

309309
template <class ELFT> void parse();
310-
MemoryBufferRef getBuffer();
311310
InputFile *fetch();
312-
bool AddedToLink = false;
313311

314312
private:
315313
uint64_t OffsetInArchive;

lld/ELF/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
212212
// distributed build system that depends on that behavior.
213213
static void thinLTOCreateEmptyIndexFiles() {
214214
for (LazyObjFile *F : LazyObjFiles) {
215-
if (F->AddedToLink || !isBitcode(F->MB))
215+
if (!isBitcode(F->MB))
216216
continue;
217217
std::string Path = replaceThinLTOSuffix(getThinLTOOutputFile(F->getName()));
218218
std::unique_ptr<raw_fd_ostream> OS = openFile(Path + ".thinlto.bc");

0 commit comments

Comments
 (0)