Skip to content
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

wasm-ld: error: /tmp/wasm-shared-issue-60c549.o: relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol .L.str; recompile with -fPIC #42059

Closed
ids1024 mannequin opened this issue Jul 22, 2019 · 6 comments
Labels
backend:WebAssembly bugzilla Issues migrated from bugzilla lld:wasm

Comments

@ids1024
Copy link
Mannequin

ids1024 mannequin commented Jul 22, 2019

Bugzilla Link 42714
Version trunk
OS Linux
Attachments C code that produces this issue
CC @sbc100

Extended Description

The attached C code fails to build with "clang --target=wasm32-unknown-unknown -fPIC -nostdlib -Wl,--shared -Wl,--export-all wasm-shared-issue.c".

@sbc100
Copy link
Collaborator

sbc100 commented Aug 8, 2019

This is actually WAI, but we should try to find a better way to convey the real error here.

The problem is that wasm32-unknown-unknown doesn't yet support building shared libraries.

Only wasm32-unknown-emscripten will generate the correct relocation types required for shared libraries.

We are looking into couple of options for fix this:

  1. Warn or error on -fPIC combined with wasm32-unknown-unknown
  2. Embed the triple in the object file so the linker can give a better error

(1) might be a problem since many build system pass fPIC even when building static binaries and we want to continue to support that. (2) involves some design work to decided exactly how much info to embed and where in the object format.

Perhaps (1) with just a warning and not an error might be acceptable is a quick solution?

@ids1024
Copy link
Mannequin Author

ids1024 mannequin commented Aug 8, 2019

Interesting.

So if I want to try out the dynamic linking support without using Emscripten, should I currently just use the target "wasm32-unknown-emscripten" (even though it's not actually Emscripten)? Or use a patched llvm with a new target (requiring long build times)?

Given the word "yet", is this expected to work at some point? For ordinary architectures, it makes sense that a bare-metal target won't ever support dynamic linking, but WASM is different since it always has some kind of host environment. If it's intended to be supported, what exactly is preventing this now?

But anyway, yeah, adding a warning sounds sensible as an easy short-term solution.

@sbc100
Copy link
Collaborator

sbc100 commented Aug 8, 2019

Currently the dynamic linking ABI is still a work in progress: https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md

Originally I landed fPIC support in LLVM for wasm targets I caused some confusion since fPIC object files were not compatible with static linking (at least not until this change lands: https://reviews.llvm.org/D65922

PIC codegen was (temporarily I hope) disabled for non-emscripten triples: https://reviews.llvm.org/D62542.

If you want to experiment I would just pass the emscripten triple for now, but be aware that this still a work in progress. Please let me know how you get on.

@ids1024
Copy link
Mannequin Author

ids1024 mannequin commented Aug 8, 2019

Makes sense. My test code (https://github.com/ids1024/wasm-dynamic-test) works using the emscripten triple; so I'll use that for now.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@sbc100
Copy link
Collaborator

sbc100 commented Aug 23, 2023

I believe this was fixed in https://reviews.llvm.org/D153293

@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2023

@llvm/issue-subscribers-lld-wasm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:WebAssembly bugzilla Issues migrated from bugzilla lld:wasm
Projects
None yet
Development

No branches or pull requests

3 participants