-
Notifications
You must be signed in to change notification settings - Fork 206
Always build wasm32-wasip2 with -fPIC
#564
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,31 +139,32 @@ add_custom_target(compiler-rt DEPENDS compiler-rt-build compiler-rt-post-build) | |
function(define_wasi_libc_sub target target_suffix lto) | ||
set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi-libc-${target}${target_suffix}) | ||
|
||
if(${target} MATCHES threads) | ||
if(lto) | ||
set(extra_make_flags LTO=full THREAD_MODEL=posix) | ||
else() | ||
set(extra_make_flags THREAD_MODEL=posix) | ||
endif() | ||
elseif(${target} MATCHES p2) | ||
if(lto) | ||
set(extra_make_flags LTO=full WASI_SNAPSHOT=p2 default) | ||
else() | ||
set(extra_make_flags WASI_SNAPSHOT=p2 default libc_so) | ||
endif() | ||
else() | ||
if(lto) | ||
set(extra_make_flags LTO=full default) | ||
else() | ||
set(extra_make_flags default libc_so) | ||
endif() | ||
endif() | ||
|
||
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) | ||
get_property(directory_cflags DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS) | ||
list(APPEND directory_cflags -resource-dir ${wasi_resource_dir}) | ||
set(extra_cflags_list | ||
"${WASI_SDK_CPU_CFLAGS} ${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}") | ||
|
||
set(extra_make_flags default) | ||
|
||
# If LTO is enabled then pass that on to wasi-libc, and otherwise make sure to | ||
# build a `libc.so` dynamic library where possible (not compatible with | ||
# threads though) | ||
if(lto) | ||
list(APPEND extra_make_flags LTO=full) | ||
elseif(NOT ${target} MATCHES threads) | ||
list(APPEND extra_make_flags libc_so) | ||
alexcrichton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endif() | ||
|
||
if(${target} MATCHES threads) | ||
list(APPEND extra_make_flags THREAD_MODEL=posix) | ||
elseif(${target} MATCHES p2) | ||
list(APPEND extra_make_flags WASI_SNAPSHOT=p2) | ||
# Always enable `-fPIC` for the `wasm32-wasip2` target. This makes `libc.a` | ||
# more flexible and usable in dynamic linking situations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you want to make p1 and p2 different in this regard? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're using dynamic libraries in p2 for various languages and it's much easier if everything is Short answer: changing only one target makes this I think less controversial. The p2-specific reason is intended use cases and usage scenarios, but it's not a strong argument. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. certain OSes (eg. netbsd) ship pic versions of static libraries for similar purposes. i feel it's a better approach.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you detail why that's a better approach? That still suffers from "align the correct matrix of flags and objects" I'm trying to avoid. |
||
list(APPEND extra_cflags_list -fPIC) | ||
endif() | ||
|
||
list(JOIN extra_cflags_list " " extra_cflags) | ||
|
||
if(${target} MATCHES threads) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and refactored this a bit to reduce the duplication between the various branches to also pass
-fPIC
unconditionally on wasip2