-
Notifications
You must be signed in to change notification settings - Fork 206
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
remove -nostdlib
from libc.so link command
#440
Conversation
Per https://reviews.llvm.org/D156205 (which we're planning to backport to LLVM 17 and pull into `wasi-sdk`), we want to link crt1-reactor.o into libc.so so it exports `_initialize` instead of `__wasm_call_ctors`. Signed-off-by: Joel Dice <[email protected]>
Makefile
Outdated
@@ -506,7 +506,7 @@ PIC_OBJS = \ | |||
# to CC. This is a workaround for a Windows command line size limitation. See | |||
# the `%.a` rule below for details. | |||
$(SYSROOT_LIB)/%.so: $(OBJDIR)/%.so.a $(BUILTINS_LIB) | |||
$(CC) -nostdlib -shared -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive $(BUILTINS_LIB) | |||
$(CC) -shared -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive $(BUILTINS_LIB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want -nolibc
perhaps? (We wouldn't want the static version of libc linked into the dynamic version.. but I'm not sure if that would actually happen..).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Can you see of -lc
is added to the link line.. I don't think we would want that when building libc itself).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like -lc
does show up:
"/Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/wasm-ld" -m wasm32 -L/Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi/crt1-reactor.o --entry _initialize -shared --whole-archive build/wasm32-wasi/libc.so.a --no-whole-archive /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/lib/clang/17/lib/wasi/libclang_rt.builtins-wasm32.a -lc /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/lib/clang/17/lib/wasi/libclang_rt.builtins-wasm32.a -o /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi/libc.so
There's no obvious ill effect, but I can go ahead and add -nolibc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently I'm doing it wrong:
$ /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/clang -v -nolibc -shared -o /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi/libc.so -Wl,--whole-archive build/wasm32-wasi/libc.so.a -Wl,--no-whole-archive /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/lib/clang/17/lib/wasi/libclang_rt.builtins-wasm32.a
clang version 17.0.1 (https://github.com/dicej/llvm-project e19b7dc36bc047b9eb72078d034596be766da350)
Target: wasm32-unknown-wasi
Thread model: posix
InstalledDir: /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin
clang: warning: argument unused during compilation: '-nolibc' [-Wunused-command-line-argument]
"/Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/wasm-ld" -m wasm32 -L/Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi/crt1-reactor.o --entry _initialize -shared --whole-archive build/wasm32-wasi/libc.so.a --no-whole-archive /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/lib/clang/17/lib/wasi/libclang_rt.builtins-wasm32.a -lc /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/lib/clang/17/lib/wasi/libclang_rt.builtins-wasm32.a -o /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi/libc.so
wasm-ld: warning: creating shared libraries, with -shared, is not yet stable
$ /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/clang -v -Wl,-nolibc -shared -o /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi/libc.so -Wl,--whole-archive build/wasm32-wasi/libc.so.a -Wl,--no-whole-archive /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/lib/clang/17/lib/wasi/libclang_rt.builtins-wasm32.a
clang version 17.0.1 (https://github.com/dicej/llvm-project e19b7dc36bc047b9eb72078d034596be766da350)
Target: wasm32-unknown-wasi
Thread model: posix
InstalledDir: /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin
"/Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/wasm-ld" -m wasm32 -L/Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/bin/../share/wasi-sysroot/lib/wasm32-wasi/crt1-reactor.o --entry _initialize -shared -nolibc --whole-archive build/wasm32-wasi/libc.so.a --no-whole-archive /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/lib/clang/17/lib/wasi/libclang_rt.builtins-wasm32.a -lc /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/lib/clang/17/lib/wasi/libclang_rt.builtins-wasm32.a -o /Users/dicej/p/component-linking-demo/wasi-sdk/build/install/opt/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi/libc.so
wasm-ld: error: unknown argument: -nolibc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh.. maybe clang doesn't support that flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe -nodefaultlibs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, -nodefaultlibs
seems to do the trick. I really wish clang --help
would list all the options it supports.
This ensures that `-lc` is not passed to `wasm-ld`. Signed-off-by: Joel Dice <[email protected]>
Per https://reviews.llvm.org/D156205 (which we're planning to backport to LLVM 17 and pull into
wasi-sdk
), we want to link crt1-reactor.o into libc.so so it exports_initialize
instead of__wasm_call_ctors
.