-
Notifications
You must be signed in to change notification settings - Fork 237
disable custom page size support when using -fPIC
#779
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
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 |
|---|---|---|
|
|
@@ -52,21 +52,47 @@ function(add_wasilibc_flags target) | |
| endif() | ||
| endfunction() | ||
|
|
||
| add_library(libc_test_support STATIC | ||
| function(add_wasilibc_shared_flags target) | ||
| add_dependencies(${target} sysroot builtins) | ||
| # Using an `INTERFACE` looks to get what we want here which is to rebuild this | ||
| # if the library changes but not actually add any arguments to the link-line. | ||
| target_link_libraries(${target} INTERFACE c) | ||
| endfunction() | ||
|
|
||
| function(add_library_pair name) | ||
| add_library(${name} STATIC ${ARGN}) | ||
|
|
||
| if (NOT TARGET_TRIPLE MATCHES "-threads") | ||
| add_library(${name}_shared SHARED ${ARGN}) | ||
| set_pic(${name}_shared) | ||
| endif() | ||
| endfunction() | ||
|
|
||
| add_library_pair(libc_test_support | ||
| "${LIBC_TEST}/src/common/path.c" | ||
| "${LIBC_TEST}/src/common/print.c" | ||
| "${LIBC_TEST}/src/common/rand.c" | ||
| "${LIBC_TEST}/src/common/utf8.c" | ||
| ) | ||
| target_include_directories(libc_test_support PUBLIC "${LIBC_TEST}/src/common") | ||
| add_wasilibc_flags(libc_test_support) | ||
| # Disable some warnings in this third-party code | ||
| target_compile_options(libc_test_support PRIVATE | ||
| -Wno-unused-variable | ||
| -Wno-unused-parameter | ||
| -Wno-unused-function | ||
| -Wno-sign-compare | ||
| ) | ||
|
|
||
| function(configure_libc_test_support suffix) | ||
| # Disable some warnings in this third-party code | ||
| target_include_directories(libc_test_support${suffix} PUBLIC "${LIBC_TEST}/src/common") | ||
| cmake_language(CALL add_wasilibc${suffix}_flags libc_test_support${suffix}) | ||
| target_compile_options(libc_test_support${suffix} PRIVATE | ||
| -Wno-unused-variable | ||
| -Wno-unused-parameter | ||
| -Wno-unused-function | ||
| -Wno-sign-compare | ||
| ) | ||
| endfunction() | ||
|
|
||
| configure_libc_test_support("") | ||
|
|
||
| if (NOT TARGET_TRIPLE MATCHES "-threads") | ||
| configure_libc_test_support("_shared") | ||
| target_compile_options(libc_test_support_shared PRIVATE -fvisibility=default) | ||
| endif() | ||
|
|
||
| # Adds a new test executable to build | ||
| # | ||
|
|
@@ -83,7 +109,7 @@ function(add_test_executable executable_name src) | |
| set(multiValueArgs LDFLAGS CFLAGS) | ||
| cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${oneValueArgs}" "${multiValueArgs}") | ||
|
|
||
| # Build the test exeutable itself and apply all custom options as applicable. | ||
| # Build the test executable itself and apply all custom options as applicable. | ||
| add_executable(${executable_name} ${src}) | ||
| clang_format_target(${executable_name}) | ||
| add_wasilibc_flags(${executable_name}) | ||
|
|
@@ -352,6 +378,38 @@ if (TARGET_TRIPLE MATCHES "-threads") | |
| target_compile_options(pthread_mutex_busywait.wasm PRIVATE -Wno-unused-variable) | ||
| endif() | ||
|
|
||
| # ========= shared library tests ================================ | ||
|
|
||
| function(add_wasilibc_shared_test test_file) | ||
| cmake_path(REPLACE_EXTENSION test_file so OUTPUT_VARIABLE test_library) | ||
| cmake_path(REPLACE_EXTENSION test_file wasm OUTPUT_VARIABLE test_name) | ||
| set(test_file "${CMAKE_CURRENT_SOURCE_DIR}/src/${test_file}") | ||
|
|
||
| add_library(${test_library} SHARED ${test_file}) | ||
| set_pic(${test_library}) | ||
| target_link_libraries(${test_library} PRIVATE libc_test_support_shared) | ||
| # Here we embed the component type custom section into `${test_library}` using | ||
| # `wasm-tools component embed`, then generate the `${test_name}` file by | ||
| # linking `${test_library}`, `liblibc_test_support_shared.so`, and `libc.so` | ||
| # together using `wasm-tools component link`. | ||
| add_custom_command( | ||
| TARGET ${test_library} | ||
| POST_BUILD | ||
| COMMAND ${wasm_tools} component embed --world wasi:cli/command "${CMAKE_CURRENT_SOURCE_DIR}/../wasi/p2/wit" $<TARGET_FILE:${test_library}> -o $<TARGET_FILE:${test_library}> | ||
| COMMAND ${wasm_tools} component link $<TARGET_FILE:${test_library}> "${SYSROOT_LIB}/libc.so" $<TARGET_FILE:libc_test_support_shared> -o ${test_name} | ||
| DEPENDS wasm_tools engine | ||
| ) | ||
|
Comment on lines
+388
to
+401
Collaborator
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. Compilation-wise it might be easier to compile an executable with
Collaborator
Author
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. Per your later comment it sounds like it's okay to leave this as-is and just remove the TODO part, correct? |
||
|
|
||
| add_test( | ||
| NAME "${test_name}" | ||
| COMMAND ${ENGINE} ${test_name} | ||
| ) | ||
| endfunction() | ||
|
|
||
| if (WASI STREQUAL "p2") | ||
| add_wasilibc_shared_test(malloc-shared.c) | ||
| endif() | ||
|
|
||
| # ========= sockets-related tests =============================== | ||
|
|
||
| if (NOT (WASI STREQUAL "p1")) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "test.h" | ||
| #include <stdbool.h> | ||
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
| #include <__macro_PAGESIZE.h> | ||
|
|
||
| __attribute__((__export_name__("wasi:cli/run@0.2.0#run"))) | ||
|
Contributor
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. does this mean to bypass crt startup? if so, it seems like too much assumptions on malloc implementation.
Collaborator
Author
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. It wasn't intended to do that, no. Functions such as This is just a way to build an executable component from shared libraries, since
Contributor
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. ok. thank you for explanation. |
||
| bool exports_wasi_cli_run_run(void) { | ||
| void* p = malloc(7777777); | ||
| if (p == NULL) { | ||
| t_error("malloc failed\n"); | ||
| } else { | ||
| free(p); | ||
| } | ||
|
|
||
| return t_status != 0; | ||
| } | ||
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.
To avoid duplicating the above here I might recommend poking around
add_internal_library_pairand doing something similar here. Basically building two libraries, one with-fPICone without, and then linking to the "right one". A small loop could handle defining options for both of those targets.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've pushed an update; let me know if you think more needs to be done with this.