[PATCH] D65565: [LLD] [COFF] Fix wholearchive with thin archives
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 02:27:43 PDT 2019
mstorsjo created this revision.
mstorsjo added reviewers: rnk, ruiu.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The Archive object created when loading an archive specified with wholearchive got cleaned up immediately, when the owning std::unique_ptr went out of scope, even if persisted StringRefs pointed to memory that belonged to the archive, which no longer was mapped in memory.
This hasn't been an issue with regular (as opposed to thin) archives, as references to the member objects has kept the mapping for the whole archive file alive - but with thin archives, all such references point to other files.
Add the std::unique_ptr to the arena allocator, to retain it as long as necessary.
This fixes (the last issue raised in) PR42388.
@hans I think this should be a safe backport once it lands.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D65565
Files:
COFF/Driver.cpp
test/COFF/thin-archive.s
Index: test/COFF/thin-archive.s
===================================================================
--- test/COFF/thin-archive.s
+++ test/COFF/thin-archive.s
@@ -11,6 +11,8 @@
# RUN: FileCheck --allow-empty %s
# RUN: lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe 2>&1 | \
# RUN: FileCheck --allow-empty %s
+# RUN: lld-link /entry:main %t.main.obj /wholearchive:%t_thin.lib /out:%t.exe 2>&1 | \
+# RUN: FileCheck --allow-empty %s
# RUN: rm %t.lib.obj
# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -187,6 +187,7 @@
for (MemoryBufferRef m : getArchiveMembers(file.get()))
addArchiveBuffer(m, "<whole-archive>", filename, 0);
+ make<std::unique_ptr<Archive>>(std::move(file)); // take ownership
return;
}
symtab->addFile(make<ArchiveFile>(mbref));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65565.212761.patch
Type: text/x-patch
Size: 970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190801/64ae84b7/attachment.bin>
More information about the llvm-commits
mailing list