Skip to content

Commit 3179b10

Browse files
committed
shared heap create from preallocated buffer and use as a single memory region
1 parent 85dabad commit 3179b10

5 files changed

Lines changed: 594 additions & 0 deletions

File tree

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
cmake_minimum_required (VERSION 3.14)
5+
6+
include(CheckPIESupported)
7+
8+
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
9+
project (shared_heap_test)
10+
else()
11+
project (shared_heap_test C ASM)
12+
endif()
13+
14+
################ runtime settings ################
15+
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
16+
if (APPLE)
17+
add_definitions(-DBH_PLATFORM_DARWIN)
18+
endif ()
19+
20+
# Reset default linker flags
21+
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
22+
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
23+
24+
# WAMR features switch
25+
26+
# Set WAMR_BUILD_TARGET, currently values supported:
27+
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
28+
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
29+
30+
if (NOT DEFINED WAMR_BUILD_TARGET)
31+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
32+
set (WAMR_BUILD_TARGET "AARCH64")
33+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
34+
set (WAMR_BUILD_TARGET "RISCV64")
35+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
36+
# Build as X86_64 by default in 64-bit platform
37+
set (WAMR_BUILD_TARGET "X86_64")
38+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
39+
# Build as X86_32 by default in 32-bit platform
40+
set (WAMR_BUILD_TARGET "X86_32")
41+
else ()
42+
message(SEND_ERROR "Unsupported build target platform!")
43+
endif ()
44+
endif ()
45+
46+
if (NOT CMAKE_BUILD_TYPE)
47+
set (CMAKE_BUILD_TYPE Debug)
48+
endif ()
49+
50+
set (WAMR_BUILD_INTERP 1)
51+
set (WAMR_BUILD_FAST_INTERP 1)
52+
set (WAMR_BUILD_AOT 1)
53+
set (WAMR_BUILD_JIT 0)
54+
set (WAMR_BUILD_LIBC_BUILTIN 1)
55+
set (WAMR_BUILD_LIBC_WASI 0)
56+
set (WAMR_BUILD_SHARED_HEAP 1)
57+
set (WAMR_BUILD_GC_HEAP_VERIFY 1)
58+
59+
if (NOT MSVC)
60+
# linker flags
61+
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
62+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
63+
endif ()
64+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
65+
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
66+
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
67+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
68+
endif ()
69+
endif ()
70+
endif ()
71+
72+
# build out vmlib
73+
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
74+
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
75+
76+
add_library(vmlib STATIC ${WAMR_RUNTIME_LIB_SOURCE})
77+
if (MSVC)
78+
target_compile_definitions(vmlib PRIVATE WASM_API_EXTERN=)
79+
endif()
80+
target_link_libraries(vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
81+
82+
################ application related ################
83+
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
84+
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
85+
86+
add_executable (shared_heap_test src/main.c ${UNCOMMON_SHARED_SOURCE})
87+
88+
check_pie_supported()
89+
set_target_properties (shared_heap_test PROPERTIES POSITION_INDEPENDENT_CODE ON)
90+
91+
if (APPLE)
92+
target_link_libraries (shared_heap_test vmlib -lm -ldl -lpthread)
93+
else ()
94+
target_link_libraries (shared_heap_test vmlib -lm -ldl -lpthread -lrt)
95+
endif ()
96+
97+
add_subdirectory(wasm-apps)
98+
99+
if (WAMR_BUILD_AOT EQUAL 1)
100+
set (WAMR_COMPILER_DIR ${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build)
101+
message (CHECK_START "Detecting WAMR_COMPILER at ${WAMR_COMPILER_DIR}")
102+
find_file (WAMR_COMPILER
103+
wamrc
104+
PATHS "${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build"
105+
NO_DEFAULT_PATH
106+
NO_CMAKE_FIND_ROOT_PATH
107+
)
108+
if (WAMR_COMPILER)
109+
message (CHECK_PASS "found")
110+
else()
111+
message (CHECK_FAIL "not found")
112+
endif()
113+
if (NOT EXISTS ${WAMR_COMPILER})
114+
message (FATAL_ERROR "Please build wamrc under ${WAMR_ROOT_DIR}/wamr-compiler")
115+
else()
116+
message (STATUS "WAMR_COMPILER is ${WAMR_COMPILER}")
117+
endif()
118+
119+
add_custom_target(
120+
wasm_to_aot
121+
ALL
122+
DEPENDS wasm-apps/test1.wasm wasm-apps/test2.wasm ${WAMR_COMPILER}
123+
COMMAND ${WAMR_COMPILER} --enable-shared-heap -o wasm-apps/test1.aot wasm-apps/test1.wasm
124+
COMMAND ${WAMR_COMPILER} --enable-shared-heap -o wasm-apps/test2.aot wasm-apps/test2.wasm
125+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
126+
)
127+
endif()

0 commit comments

Comments
 (0)