aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2019-08-05 07:35:49 +0000
committerHans Wennborg <hans@hanshq.net>2019-08-05 07:35:49 +0000
commited144118e418146543025991915be28540d31a40 (patch)
tree8f84fda485cda9f13a8323b329445e35e6e89cfe
parentf3cba819d7371fcc997dfb40040348ec1eaf97b2 (diff)
Merge r367599 - [COFF] Fix wholearchive with thin archives (PR42388, D65565)
git-svn-id: https://llvm.org/svn/llvm-project/lld/branches/release_90@367806 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--COFF/Driver.cpp4
-rw-r--r--test/COFF/Inputs/mangled-symbol.s9
-rw-r--r--test/COFF/thin-archive.s32
3 files changed, 44 insertions, 1 deletions
diff --git a/COFF/Driver.cpp b/COFF/Driver.cpp
index d7af50b93..7214d12bd 100644
--- a/COFF/Driver.cpp
+++ b/COFF/Driver.cpp
@@ -184,8 +184,10 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
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
- for (MemoryBufferRef m : getArchiveMembers(file.get()))
+ for (MemoryBufferRef m : getArchiveMembers(archive))
addArchiveBuffer(m, "<whole-archive>", filename, 0);
return;
}
diff --git a/test/COFF/Inputs/mangled-symbol.s b/test/COFF/Inputs/mangled-symbol.s
new file mode 100644
index 000000000..d39323676
--- /dev/null
+++ b/test/COFF/Inputs/mangled-symbol.s
@@ -0,0 +1,9 @@
+ .text
+
+ .def "?f@@YAHXZ"
+ .scl 2
+ .type 32
+ .endef
+ .global "?f@@YAHXZ"
+"?f@@YAHXZ":
+ retq $0
diff --git a/test/COFF/thin-archive.s b/test/COFF/thin-archive.s
new file mode 100644
index 000000000..f24911de4
--- /dev/null
+++ b/test/COFF/thin-archive.s
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -o %t.main.obj %s
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -o %t.lib.obj \
+# RUN: %S/Inputs/mangled-symbol.s
+# RUN: lld-link /lib /out:%t.lib %t.lib.obj
+# RUN: lld-link /lib /llvmlibthin /out:%t_thin.lib %t.lib.obj
+
+# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
+# 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 | \
+# RUN: FileCheck --allow-empty %s
+
+# CHECK-NOT: error: could not get the buffer for the member defining
+
+ .text
+
+ .def main
+ .scl 2
+ .type 32
+ .endef
+ .global main
+main:
+ call "?f@@YAHXZ"
+ retq $0