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

Build fails with WASI SDK 21 #113516

Closed
proman2019 opened this issue Dec 27, 2023 · 17 comments
Closed

Build fails with WASI SDK 21 #113516

proman2019 opened this issue Dec 27, 2023 · 17 comments
Assignees
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes OS-wasi type-bug An unexpected behavior, bug, or error

Comments

@proman2019
Copy link

proman2019 commented Dec 27, 2023

Bug report

Bug description:

Hello!
when executing
python3 Tools/wasm/wasi.py make-host
on ubuntu 22.04 with wasi-ld version: LLD 17.0.6 (tried earlier versions too)
Errors are as follows:

/opt/wasi-sdk/bin/wasm-ld   -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760   Modules/_testimportmultiple.o   -o Modules/_testimportmultiple.cpython-313d-wasm32-wasi.so
/opt/wasi-sdk/bin/wasm-ld   -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760   Modules/_testmultiphase.o   -o Modules/_testmultiphase.cpython-313d-wasm32-wasi.so
/opt/wasi-sdk/bin/wasm-ld   -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760   Modules/_testsinglephase.o   -o Modules/_testsinglephase.cpython-313d-wasm32-wasi.so
/opt/wasi-sdk/bin/wasm-ld   -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760   Modules/xxlimited.o   -o Modules/xxlimited.cpython-313d-wasm32-wasi.so
/opt/wasi-sdk/bin/wasm-ld   -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760   Modules/xxlimited_35.o   -o Modules/xxlimited_35.cpython-313d-wasm32-wasi.so
wasm-ld: error: unknown argument: -Wl,--stack-first
wasm-ld: error: unknown argument: -Wl,--stack-first
wasm-ld: error: unknown argument: -Wl,--initial-memory=10485760
wasm-ld: error: unknown argument: -Wl,--initial-memory=10485760
wasm-ld: error: unknown argument: -Wl,--stack-first
wasm-ld: error: unknown argument: -Wl,--initial-memory=10485760
wasm-ld: error: unknown argument: -Wl,--stack-first
wasm-ld: error: unknown argument: -Wl,--initial-memory=10485760
make: *** [Makefile:3134: Modules/_testimportmultiple.cpython-313d-wasm32-wasi.so] Error 1

if "-Wl" flag removed then clang compiler fails.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

@proman2019 proman2019 added the type-bug An unexpected behavior, bug, or error label Dec 27, 2023
@brettcannon
Copy link
Member

What version of the WASI-SDK did you use?

@brettcannon brettcannon self-assigned this Jan 3, 2024
@proman2019
Copy link
Author

proman2019 commented Jan 3, 2024 via email

@brettcannon
Copy link
Member

It builds fine for me under WASI-SDK 20.

Can you share all 4 commands you used w/ wasi.py? Do you get a different result if you use wasi.py build?

@proman2019
Copy link
Author

proman2019 commented Jan 6, 2024 via email

@brettcannon
Copy link
Member

Unfortunately w/o knowing what WASI-SDK version is having issues I don't know how to help since I don't have these failures under WASI-SDK 20. If it's WASI-SDK 21 (which we have not tried to support yet), then that might be the cause, but then that means they may have broken something.

@brettcannon
Copy link
Member

I opened WebAssembly/wasi-sdk#372 to see if there's an easy way to find this out.

@proman2019
Copy link
Author

proman2019 commented Jan 8, 2024 via email

@proman2019
Copy link
Author

proman2019 commented Jan 8, 2024 via email

@encukou
Copy link
Member

encukou commented Feb 2, 2024

I will close the issue. If you have more information, please comment here or file a new one.

@encukou encukou closed this as completed Feb 2, 2024
@kushaldas
Copy link
Member

Fails to build using wasi-sdk-21.

/opt/wasi-sdk/bin/clang -c -fno-strict-overflow -Wsign-compare -g -Og -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-int-conversion -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I../../Include/internal -I../../Include/internal/mimalloc -IObjects -IInclude -IPython -I. -I../../Include    -DPy_BUILD_CORE -o Python/frozen.o ../../Python/frozen.c
_PYTHON_HOSTRUNNER='/home/kdas/.wasmtime/bin/wasmtime run --wasm max-wasm-stack=8388608 --wasm threads=y --wasi threads=y --dir /home/kdas/code/cpython::/ --env PYTHONPATH=/cross-build/wasm32-wasi/build/lib.wasi-wasm32-3.13-pydebug' _PYTHON_PROJECT_BASE=/home/kdas/code/cpython/cross-build/wasm32-wasi _PYTHON_HOST_PLATFORM=wasi-wasm32 PYTHONPATH=/home/kdas/code/cpython/cross-build/wasm32-wasi/build/lib.wasi-wasm32-3.13-pydebug:../../Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_d_wasi_wasm32-wasi /home/kdas/code/cpython/cross-build/build/python -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))' >platform
/opt/wasi-sdk/bin/wasm-ld   -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760   Modules/_testimportmultiple.o   -o Modules/_testimportmultiple.cpython-313d-wasm32-wasi.so
wasm-ld: error: unknown argument: -Wl,--stack-first
wasm-ld: error: unknown argument: -Wl,--initial-memory=10485760
make: *** [Makefile:3183: Modules/_testimportmultiple.cpython-313d-wasm32-wasi.so] Error 1
make: *** Waiting for unfinished jobs....

@kushaldas kushaldas reopened this Feb 12, 2024
@kushaldas kushaldas changed the title wasi build appears to fail Build fails with wasi-sdk-21 Feb 12, 2024
@kushaldas
Copy link
Member

Filed WebAssembly/wasi-sdk#385 asking for help/input.

@brettcannon
Copy link
Member

There may have been a change in clang 17 (which WASI SDK 21 uses) where LDFLAGS goes straight to the linker, which means -Wl, is unnecessary as that parts meant for the compiler to pass the arg to the linker. So maybe that line in configure.ac just needs the compiler-specific part stripped and the rest left in?

@brettcannon
Copy link
Member

brettcannon commented Feb 15, 2024

OK, I think I have figured it out. 😮‍💨

If you look at the failure it corresponds to trying to build _testimportmultiple. OK, why is that in any way special in how it gets built? Well, it turns out it requires dlopen() which is new in WASI SDK 21:

PY_STDLIB_MOD([_testimportmultiple], [test "$TEST_MODULES" = yes], [test "$ac_cv_func_dlopen" = yes])

So now we know why this problem is only showing up for WASI SDK 21, but why the call to wasm-ld w/ LDFLAGS_NODIST that's only meant for clang?

cpython/configure.ac

Lines 2238 to 2240 in 3e7b7df

dnl increase initial memory and stack size, move stack first
dnl https://github.com/WebAssembly/wasi-libc/issues/233
AS_VAR_APPEND([LDFLAGS_NODIST], [" -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760"])

If you look at the generated Makefile, you will see a line for building _testimportmultiple:

Modules/_testimportmultiple$(EXT_SUFFIX):  Modules/_testimportmultiple.o; $(BLDSHARED)  Modules/_testimportmultiple.o $(MODULE__TESTIMPORTMULTIPLE_LDFLAGS)  -o Modules/_testimportmultiple$(EXT_SUFFIX)

So it seems BLDSHARED is where wasm-ld is suddenly appearing where clang should be. So why is that happening? If it isn't explicitly set it turns out to inherit from LDSHARED:

BLDSHARED=${BLDSHARED-$LDSHARED}

And why does this matter?

"LDSHARED": "wasm-ld", "AR": "llvm-ar", "RANLIB": "ranlib"}

And there's the wasm-ld! This was written this way thanks to where I copied how to set these environment variables:

LDSHARED="${WASI_SDK_PATH}/bin/wasm-ld"

Dropping that environment variable gets compiling to work! I will get a PR pulled together for this.

But then test_importlib fails. ☹️ It probably has to do w/ dlopen() now existing.

brettcannon added a commit to brettcannon/cpython that referenced this issue Feb 15, 2024
@brettcannon brettcannon added 3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes labels Feb 15, 2024
@brettcannon
Copy link
Member

FYI the fix for wasi-env will need to be backported.

@brettcannon brettcannon changed the title Build fails with wasi-sdk-21 Build fails with WASI SDK 21 Feb 15, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 15, 2024
brettcannon added a commit that referenced this issue Feb 15, 2024
…H-115495) (GH-115496) (GH-115497)

[3.12] GH-113516: don't set `LDSHARED` when building for WASI (GH-115495) (GH-115496)
(cherry picked from commit 0e4f73b)

Co-authored-by: Brett Cannon <[email protected]>
@brettcannon
Copy link
Member

The fixes to get the builds to work are now in, so getting test_importlib to pass is next.

@proman2019
Copy link
Author

proman2019 commented Feb 15, 2024 via email

@brettcannon
Copy link
Member

I opened #115979 to track the test_importlib failures. As such, I'm closing this issue as the builds do now succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes OS-wasi type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants