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

remove -nostdlib from libc.so link command #440

Merged
merged 2 commits into from
Oct 7, 2023

Conversation

dicej
Copy link
Contributor

@dicej dicej commented Oct 6, 2023

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.

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)
Copy link
Member

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..).

Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Contributor Author

@dicej dicej Oct 6, 2023

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)

Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe -nodefaultlibs

Copy link
Contributor Author

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]>
@abrown abrown merged commit 4db5398 into WebAssembly:main Oct 7, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants