Closed allsey87 closed 1 week ago
Can I ask why are you trying to build with -sRELOCATABLE
? Obviously we should fix this, but using that flag directly not common/recommended.
The reason that _emscripten_thread_exit_joinable
is not available is that that symbol is only defined when -sMAIN_MODULE
is used:
Unfortunetly at the callsite we protect that call with -DEMSCRIPTEN_DYNAMIC_LINKING
which I believe is set whenever -sRELOCTABLE
is used.. so there is a mismatch there:
Can I ask why are you trying to build with
-sRELOCATABLE
? Obviously we should fix this, but using that flag directly not common/recommended.
I am probably a bit confused here, but I am trying to compile a set of static libraries that will be linked into either the main module or the side module. Now these libraries are built via Autoconf and Automake so the build process also includes compiling small test programs to see what features emcc has.
Initially I was just using -fPIC
since I thought that neither -sMAIN_MODULE
or -sSIDE_MODULE
made sense here, but just using -fPIC
alone is not enough to get PIC variants of system libraries from the cache. In order to get the PIC variants, -sRELOCATABLE
has to be set (or set indirectly via -sMAIN_MODULE
or -sSIDE_MODULE
in emcc) to get the correct cache path.
Since I am compiling static libraries, I guess the version of the cache in use doesn't really matter since the static library will never actually be linked against anything in there, but I thought for the configure script compiler tests it would be more correct for those tests to use the system libraries coming from the correct cache path.
If you are building static libraries that you don't need -fPIC
or MAIN_MODULE
. For autoconf and automake and would recommend disabling dynamic linking completely using --disable-shared
.
Huh, I thought the code would still need to be compiled with -fPIC
if it is going to be linked into a relocatable module at some point...
Sure, yes, if you the final output is a MAIN_MODULE or a SIDE_MODULE than yes you would want to build with -fPIC
. Is your final output of those?
In any case #22110 should fix this particular bug. In the long run I'm still hoping we can remove -sRELOCATBLE
as a link flag since we don't test that mode fully, and I'm not sure what its usefulness is these days.
Sure, yes, if you the final output is a MAIN_MODULE or a SIDE_MODULE than yes you would want to build with
-fPIC
. Is your final output of those?
Yes, the final output will be either a MAIN_MODULE or SIDE_MODULE, the reason for adding -sRELOCATBLE
is because I want the configure tests to link against the -fPIC
variants of the system libraries since those are the only ones available when using emscripten_cache(flags = ["--pic"])
.
In that case I would recommend using -sMAIN_MODULE=2
rather then -sRELOCTABLE
Sure, yes, if you the final output is a MAIN_MODULE or a SIDE_MODULE than yes you would want to build with
-fPIC
. Is your final output of those?Yes, the final output will be either a MAIN_MODULE or SIDE_MODULE, the reason for adding
-sRELOCATBLE
is because I want the configure tests to link against the-fPIC
variants of the system libraries since those are the only ones available when usingemscripten_cache(flags = ["--pic"])
.
Can't you setup the cache to contains both types of libraries? What if you have a statically linked binary and a dynamically linked binary in the same project?
Yeah, I was thinking that. Once I get some initial feedback on the direction of that PR, I will investigate calling embuilder multiple times with the different configurations.
In that case I would recommend using
-sMAIN_MODULE=2
rather then-sRELOCTABLE
This is a decent workaround, but it seems incorrect that by default, if I compile code with -fPIC
, it will link against non--fPIC
system libraries. Perhaps the cache should be checking these flags directly instead of relying on the higher level Emscripten arguments like -sRELOCATABLE
?
I'm proposing that we drop -sRELOCATABLE
completely... unless you can think of a good use case for it.
When building with both
-pthread
and-sRELOCATABLE
, I get an error saying that_emscripten_thread_exit_joinable
needs to be added toEXPORTED_FUNCTIONS
. However, while addingEXPORTED_FUNCTIONS=__emscripten_thread_exit_joinable
shows that--export=_emscripten_thread_exit_joinable
is now passed towasm-ld
, I get the exact same error.This issue is related to #21844, but I would like to focus here on why
EXPORTED_FUNCTIONS
is not working.Version of emscripten/emsdk:
Failing command line in full:
Test.c source
Full link command and output with
-v
appended: