Skip to content

Commit

Permalink
move dyld logic into a separate library
Browse files Browse the repository at this point in the history
for now, the dylink.0 custom section support is left in the main library.

ideally it would be nicer to have some api to allow users like dyld
to parse and validate their own custom sections.
  • Loading branch information
yamt committed Jul 22, 2023
1 parent 583eb07 commit 54f9fcb
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 8 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ add_subdirectory(lib)
if(TOYWASM_ENABLE_WASI)
add_subdirectory(libwasi)
endif()
if(TOYWASM_ENABLE_DYLD)
add_subdirectory(libdyld)
endif()

if(CMAKE_C_COMPILER_TARGET MATCHES "wasm")
set(TOYWASM_CLI "${CMAKE_CURRENT_SOURCE_DIR}/test/toywasm-on-toywasm.py")
Expand All @@ -48,7 +51,10 @@ set(cli_sources
)

add_executable(toywasm-cli ${cli_sources})
target_link_libraries(toywasm-cli toywasm-lib-core $<$<BOOL:${TOYWASM_ENABLE_WASI}>:toywasm-lib-wasi> m)
target_link_libraries(toywasm-cli toywasm-lib-core
$<$<BOOL:${TOYWASM_ENABLE_WASI}>:toywasm-lib-wasi>
$<$<BOOL:${TOYWASM_ENABLE_DYLD}>:toywasm-lib-dyld>
m)
set_target_properties(toywasm-cli PROPERTIES OUTPUT_NAME toywasm)

add_test(NAME toywasm-cli-simple-module COMMAND
Expand Down
3 changes: 3 additions & 0 deletions cli/repl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <stdbool.h>

#include "toywasm_config.h"
#if defined(TOYWASM_ENABLE_DYLD)
#include "dyld.h"
#endif
#include "options.h"
#include "type.h"

Expand Down
7 changes: 0 additions & 7 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ list(APPEND lib_core_sources
endif()
endif()

if(TOYWASM_ENABLE_DYLD)
list(APPEND lib_core_sources
"dyld.c"
"dyld_plt.c")
endif()

if(TOYWASM_ENABLE_WRITER)
set(lib_core_sources_writer
"module_writer.c"
Expand All @@ -61,7 +55,6 @@ set(lib_core_headers
"bitmap.h"
"cell.h"
"context.h"
"dyld.h"
"dylink_type.h"
"exec_context.h"
"fileio.h"
Expand Down
32 changes: 32 additions & 0 deletions libdyld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# lib-dyld

set(lib_dyld_sources
"dyld.c"
"dyld_plt.c"
)

set(lib_dyld_headers
"dyld.h"
)

add_library(toywasm-lib-dyld STATIC ${lib_dyld_sources})
set_target_properties(toywasm-lib-dyld PROPERTIES OUTPUT_NAME toywasm-dyld)
if (USE_IPO)
# Note: -flto=full seems to produce considerably faster code
# than -flto=thin for us. However, cmake INTERPROCEDURAL_OPTIMIZATION
# always use -flto=thin for clang.
# cf. https://gitlab.kitware.com/cmake/cmake/-/issues/16808
set_property(TARGET toywasm-lib-dyld PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
set_property(TARGET toywasm-lib-dyld PROPERTY PUBLIC_HEADER ${lib_dyld_headers})
target_link_libraries(toywasm-lib-dyld toywasm-lib-core)
target_include_directories(toywasm-lib-dyld
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)

install(TARGETS toywasm-lib-dyld
EXPORT toywasm-lib-dyld-config
PUBLIC_HEADER DESTINATION include/toywasm)
install(EXPORT toywasm-lib-dyld-config
DESTINATION lib/cmake/toywasm-lib-dyld)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 54f9fcb

Please sign in to comment.