zig icon indicating copy to clipboard operation
zig copied to clipboard

"no-entry" argument not recognized

Open danielchasehooper opened this issue 2 years ago • 6 comments

Zig Version

0.10.0-dev.871+bb05a8a08

Steps to Reproduce

run this:

echo "int add(int a,int b){return a+b;}" > main.c
zig cc main.c -target wasm32-freestanding-none -nostdlib -o binary.wasm -Wl,--no-entry

Expected Behavior

should compile without issue

Actual Behavior

output:

warning: unsupported linker arg: --no-entry
wasm-ld: error: entry symbol not defined (pass --no-entry to suppress): _start

similarly, if you run zig cc main.c -target wasm32-freestanding-none -nostdlib -o binary.wasm --no-entry you get error: Unknown Clang option: '--no-entry'

so whether you pass the argument to zig cc with --no-entry or the linker with -Wl,--no-entry, it doesn't work

danielchasehooper avatar Mar 03 '22 14:03 danielchasehooper

Note --no-entry is a wasm-specific option: https://github.com/llvm/llvm-project/blob/main/lld/docs/WebAssembly.rst#usage

matu3ba avatar Mar 03 '22 17:03 matu3ba

Linking my comment from the PR here for visibility: https://github.com/ziglang/zig/issues/11742#issuecomment-1140243360

As mentioned, the solution is to build a library, rather than an executable.

Luukdegram avatar May 28 '22 11:05 Luukdegram

@Luukdegram If the ship has sailed on flag compatibility with clang, then something must be done to address the usability of this situation. Zig cc is being advertised as an easy entry into the zig world - but incompatibility+bad error messages like this will discourage adoption.

Either

  1. wasm-ld: error: entry symbol not defined (pass --no-entry to suppress): _start should be changed to wasm-ld: error: entry symbol not defined (pass -shared to suppress): _start
  2. or zig cc should detect the --no-entry linker flag and tell you it to use -shared instead. This way even if the wasm-ld error message isn't changed, people will get directed to do the right thing.

Probably both should be done, so if you are transitioning an existing command to zig cc, it'll tell you the flag is invalid, or if you're working on something new, it'll tell you to add -shared

danielchasehooper avatar May 28 '22 14:05 danielchasehooper

@danielchasehooper Pardon the late response. I will re-open this ticket so we can improve the error messaging toward the user in the future.

Luukdegram avatar Jun 03 '22 16:06 Luukdegram

I might have been stuck for hours on this exact problem if I had not found this ticket via Google, and learning that I just need to add the -shared option. Thanks.

williamstein avatar Jul 29 '22 21:07 williamstein

im slightly confused by the workaround

jim@gentoo ~/work/gztool $ zig build-exe -I /usr/include/ -O ReleaseSmall -target wasm32-wasi gztool.c -shared
error: unrecognized parameter: '-shared'
jim@gentoo ~/work/gztool $ zig build-exe -I /usr/include/ -O ReleaseSmall -target wasm32-wasi gztool.c --shared
error: unrecognized parameter: '--shared' 

here from

jim@gentoo ~/work/gztool $ zig build-exe -I /usr/include/ -O ReleaseSmall -target wasm32-wasi gztool.c ----no-entry 
error: unrecognized parameter: '--no-entry'

using a single c file exe https://raw.githubusercontent.com/circulosmeos/gztool/master/gztool.c

I am a first-time zig user also, happy to learn how this can simplify wasm targets

edit: this works zig cc -I /usr/include/ -target wasm32-freestanding gztool.c -shared

jnorthrup avatar Mar 08 '23 10:03 jnorthrup

I'm still stuck on this for compiling c libraries to wasm32-wasi, and with cmake there doesn't seem to be an easy fix because using wasm-ld directly causes more issues. This argument is required to build libraries for wasm32-wasi because without it, it errors saying main isn't defined 😕

It seems like this is where the error occurs: https://github.com/ziglang/zig/blob/6bc9c4f716afbb15465f79f84f61221f394fa5b6/src/main.zig#L2224

However I have no idea what the correct fix would be.

Edit: I have found a workaround that actually works but it doesn't support existing build systems like cmake.

zig cc -I ./c/include -target wasm32-wasi -Oz -flto ./c/dec/* ./c/enc/*.c -c -o ./brotli.o
wasm-ld --no-entry --export-all brotli.o -o libbrotli.wasm

theoparis avatar Jul 12 '23 01:07 theoparis