Followup on https://reviews.llvm.org/D85062 which ignores
entire library objects when no symbols are used within them.
This is shouldn't apply with `--whole-archive` since this
is specified to treat them like direct object inputs.
Differential Revision: https://reviews.llvm.org/D89290
; RUN: rm -f %t.lib.a
; RUN: llvm-ar rcs %t.lib.a %t.lib.o %t.ctor.o
; RUN: wasm-ld %t.start.o %t.lib.a -o %t.wasm
+; RUN: wasm-ld %t.start.o --whole-archive %t.lib.a -o %t2.wasm
; RUN: obj2yaml %t.wasm | FileCheck %s
+; RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefix=WHOLEARCHIVE
; CHECK-NOT: __wasm_call_ctors
+
+; WHOLEARCHIVE: __wasm_call_ctors
// Handle -whole-archive.
if (inWholeArchive) {
- for (MemoryBufferRef &m : getArchiveMembers(mbref))
- files.push_back(createObjectFile(m, path));
+ for (MemoryBufferRef &m : getArchiveMembers(mbref)) {
+ auto *object = createObjectFile(m, path);
+ // Mark object as live; object members are normally not
+ // live by default but -whole-archive is designed to treat
+ // them as such.
+ object->markLive();
+ files.push_back(object);
+ }
+
return;
}
return mbref;
}
-InputFile *createObjectFile(MemoryBufferRef mb,
- StringRef archiveName) {
+InputFile *createObjectFile(MemoryBufferRef mb, StringRef archiveName) {
file_magic magic = identify_magic(mb.getBuffer());
if (magic == file_magic::wasm_object) {
std::unique_ptr<Binary> bin =