emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.62k stars 3.28k forks source link

ndefined symbol: sysctl #18858

Open VamCriss opened 1 year ago

VamCriss commented 1 year ago

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.32 (eab98adf462c39f3c31d348331c4830bcaa36949)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Failing command line in full: Source Code

#include <stdio.h>
#include <sys/sysctl.h>
#include <unistd.h>

int main()
{
    int mib[4] = {1, 14, 0 ,0};
    size_t miblen = 4;
    size_t size;
    int st = sysctl(mib, miblen, NULL, &size, NULL, 0);

    printf("sysctl ret: %d\n", st);
    return 1;
}

Command: emcc hello.c -s WASM=0 -o hello.html

Full link command and output with -v appended: Output with -v

 "/Users/aaaa/Code/emsdk/upstream/bin/clang" --version
 "/Users/aaaa/Code/emsdk/upstream/bin/clang" -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN -Werror=implicit-function-declaration --sysroot=/Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v hello.c -c -o /var/folders/_1/mtcgn5fx3xdfgxqbww8m06p00000gn/T/emscripten_temp_4o8oo_6i/hello_0.o
clang version 17.0.0 (https://github.com/llvm/llvm-project df82394e7a2d06506718cafa347bf7827c79fc4f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/aaaa/Code/emsdk/upstream/bin
 (in-process)
 "/Users/aaaa/Code/emsdk/upstream/bin/clang-17" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/Users/aaaa/Code/emsdkDemo/WebAssembly -resource-dir /Users/aaaa/Code/emsdk/upstream/lib/clang/17 -D EMSCRIPTEN -isysroot /Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /Users/aaaa/Code/emsdk/upstream/lib/clang/17/include -internal-isystem /Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot/include -Werror=implicit-function-declaration -fdebug-compilation-dir=/Users/aaaa/Code/emsdkDemo/WebAssembly -ferror-limit 19 -fvisibility=default -fgnuc-version=4.2.1 -fignore-exceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /var/folders/_1/mtcgn5fx3xdfgxqbww8m06p00000gn/T/emscripten_temp_4o8oo_6i/hello_0.o -x c hello.c
clang -cc1 version 17.0.0 based upon LLVM 17.0.0git default target x86_64-apple-darwin21.6.0
ignoring nonexistent directory "/Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 /Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
 /Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot/include/compat
 /Users/aaaa/Code/emsdk/upstream/lib/clang/17/include
 /Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
 "/Users/aaaa/Code/emsdk/upstream/bin/wasm-ld" -o hello.wasm /var/folders/_1/mtcgn5fx3xdfgxqbww8m06p00000gn/T/emscripten_temp_4o8oo_6i/hello_0.o -L/Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/var/folders/_1/mtcgn5fx3xdfgxqbww8m06p00000gn/T/tmpkxj4qa6j.undefined --import-memory --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=getTempRet0 --export=setTempRet0 --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=16777216 --stack-first
wasm-ld: error: /var/folders/_1/mtcgn5fx3xdfgxqbww8m06p00000gn/T/emscripten_temp_4o8oo_6i/hello_0.o: undefined symbol: sysctl
emcc: error: '/Users/aaaa/Code/emsdk/upstream/bin/wasm-ld -o hello.wasm /var/folders/_1/mtcgn5fx3xdfgxqbww8m06p00000gn/T/emscripten_temp_4o8oo_6i/hello_0.o -L/Users/aaaa/Code/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/var/folders/_1/mtcgn5fx3xdfgxqbww8m06p00000gn/T/tmpkxj4qa6j.undefined --import-memory --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=getTempRet0 --export=setTempRet0 --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=16777216 --stack-first' failed (returned 1)

Besides,if this is the right system library path, I found the definition of sysctl in system/include/compat/sys/sysctl.h. But I'm confused why this function is undefined.

kripken commented 1 year ago

sysctl is used to adjust Linux kernel params, I think? I don't believe we support that level of Linux compatibility. Does your project actually need this, or perhaps just avoiding those calls will work?

(I was confused for a moment when I read this, because I thought we do support it, but I was thinking of ioctl.)

sbc100 commented 1 year ago

Hmm, we should probably remove that header, since I don't think we have ever supported that function.

The header was added back in 06b2dd819a8cf2f0605e22f40449524f32f8e32b