Skip to content

Commit d7c5180

Browse files
sbc100yuxuanchen1997
authored andcommitted
[lld][WebAssembly] Work around limited architecture detection for wasm64 shared libraries (#98961)
Summary: We don't currently have a great way to detect the architecture of shared object files under wasm. The currently method involves checking if the imported or exported memory is 64-bit. However some shared libraries don't use linear memory at all. See #98778 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251710
1 parent da89acf commit d7c5180

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lld/test/wasm/dylink.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
# RUN: wasm-ld --experimental-pic -pie -o %t.wasm %t.o %t.lib.so
77
# RUN: obj2yaml %t.wasm | FileCheck %s
88

9+
# Same again for wasm64
10+
11+
# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-emscripten -o %t.o %s
12+
# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-emscripten %p/Inputs/ret32.s -o %t.ret32.o
13+
# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-emscripten %p/Inputs/libsearch-dyn.s -o %t.dyn.o
14+
# RUN: wasm-ld --experimental-pic -mwasm64 -shared %t.ret32.o %t.dyn.o -o %t.lib.so
15+
# RUN: not wasm-ld --experimental-pic -mwasm64 -pie -o %t.wasm %t.o 2>&1 | FileCheck --check-prefix=ERROR %s
16+
# RUN: wasm-ld --experimental-pic -mwasm64 -pie -o %t.wasm %t.o %t.lib.so
17+
# RUN: obj2yaml %t.wasm | FileCheck %s
18+
919
# ERROR: error: {{.*}}: undefined symbol: ret32
1020
# ERROR: error: {{.*}}: undefined symbol: _bar
1121
.functype ret32 (f32) -> (i32)

lld/wasm/InputFiles.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ ObjFile::ObjFile(MemoryBufferRef m, StringRef archiveName, bool lazy)
408408
this->lazy = lazy;
409409
this->archiveName = std::string(archiveName);
410410

411+
// Currently we only do this check for regular object file, and not for shared
412+
// object files. This is because architecture detection for shared objects is
413+
// currently based on a heuristic, which is fallable:
414+
// https://github.com/llvm/llvm-project/issues/98778
415+
checkArch(wasmObj->getArch());
416+
411417
// If this isn't part of an archive, it's eagerly linked, so mark it live.
412418
if (archiveName.empty())
413419
markLive();
@@ -456,8 +462,6 @@ WasmFileBase::WasmFileBase(Kind k, MemoryBufferRef m) : InputFile(k, m) {
456462

457463
bin.release();
458464
wasmObj.reset(obj);
459-
460-
checkArch(obj->getArch());
461465
}
462466

463467
void ObjFile::parse(bool ignoreComdats) {

0 commit comments

Comments
 (0)