Skip to content

[lld][WebAssembly] Work around limited architecture detection for wasm64 shared libraries #98961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lld/test/wasm/dylink.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
# RUN: wasm-ld --experimental-pic -pie -o %t.wasm %t.o %t.lib.so
# RUN: obj2yaml %t.wasm | FileCheck %s

# Same again for wasm64

# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-emscripten -o %t.o %s
# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-emscripten %p/Inputs/ret32.s -o %t.ret32.o
# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-emscripten %p/Inputs/libsearch-dyn.s -o %t.dyn.o
# RUN: wasm-ld --experimental-pic -mwasm64 -shared %t.ret32.o %t.dyn.o -o %t.lib.so
# RUN: not wasm-ld --experimental-pic -mwasm64 -pie -o %t.wasm %t.o 2>&1 | FileCheck --check-prefix=ERROR %s
# RUN: wasm-ld --experimental-pic -mwasm64 -pie -o %t.wasm %t.o %t.lib.so
# RUN: obj2yaml %t.wasm | FileCheck %s

# ERROR: error: {{.*}}: undefined symbol: ret32
# ERROR: error: {{.*}}: undefined symbol: _bar
.functype ret32 (f32) -> (i32)
Expand Down
8 changes: 6 additions & 2 deletions lld/wasm/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,12 @@ ObjFile::ObjFile(MemoryBufferRef m, StringRef archiveName, bool lazy)
this->lazy = lazy;
this->archiveName = std::string(archiveName);

// Currently we only do this check for regular object file, and not for shared
// object files. This is because architecture detection for shared objects is
// currently based on a heuristic, which is fallable:
// https://github.com/llvm/llvm-project/issues/98778
checkArch(wasmObj->getArch());
Comment on lines +411 to +415
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this problem (that we cannot determine arch if there is no memory) only happen with shared objects? If so, why? If non-shared objects don't have a memory, how do we determine the arch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, non-shared objects, produced by llvm always import the memory. We just get lucky that is the case.

In fact even shared object do, just not once they have been though wasm-opt, which will eliminate the memory completely if its unused.


// If this isn't part of an archive, it's eagerly linked, so mark it live.
if (archiveName.empty())
markLive();
Expand Down Expand Up @@ -456,8 +462,6 @@ WasmFileBase::WasmFileBase(Kind k, MemoryBufferRef m) : InputFile(k, m) {

bin.release();
wasmObj.reset(obj);

checkArch(obj->getArch());
}

void ObjFile::parse(bool ignoreComdats) {
Expand Down
Loading