Skip to content

Commit 1f14f4e

Browse files
authored
Fix build issues when compiling WAMRC as a cross-compiler (#4112)
* Use CMAKE_INSTALL_BINDIR for wamrc installation * Fix wamrc build failure for 32bit non-x86 targets * Handle PIC flags by cmake in wamrc * Use dummy AOT reloc functions when building wamrc AOT reloc functions are used only when loading AOT WebAssembly modules on target, not during AOT compilation. Original code led to build issues when building wamrc as cross-compiler, using arm header on x86 build. * Add option to turn off SIMD support in wamrc
1 parent efa8019 commit 1f14f4e

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

core/iwasm/aot/arch/aot_reloc_dummy.c

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include "aot_reloc.h"
7+
8+
SymbolMap *
9+
get_target_symbol_map(uint32 *sym_num)
10+
{
11+
abort();
12+
}
13+
14+
uint32
15+
get_plt_table_size(void)
16+
{
17+
abort();
18+
}
19+
20+
void
21+
init_plt_table(uint8 *plt)
22+
{
23+
abort();
24+
}
25+
26+
void
27+
get_current_target(char *target_buf, uint32 target_buf_size)
28+
{
29+
abort();
30+
}
31+
32+
bool
33+
apply_relocation(AOTModule *module, uint8 *target_section_addr,
34+
uint32 target_section_size, uint64 reloc_offset,
35+
int64 reloc_addend, uint32 reloc_type, void *symbol_addr,
36+
int32 symbol_index, char *error_buf, uint32 error_buf_size)
37+
{
38+
abort();
39+
}

core/iwasm/aot/iwasm_aot.cmake

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ if (WAMR_BUILD_AOT_VALIDATOR EQUAL 1)
2121
list (APPEND c_source_all ${IWASM_AOT_DIR}/aot_validator.c)
2222
endif ()
2323

24-
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
24+
if (WAMR_BUILD_WAMR_COMPILER EQUAL 1)
25+
# AOT reloc functions are not used during AOT compilation
26+
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_dummy.c)
27+
elseif (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
2528
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_64.c)
2629
elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
2730
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_32.c)

wamr-compiler/CMakeLists.txt

+17-18
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ endif()
3131
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
3232
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
3333

34+
# Turn on SIMD by default, can be turned off by setting WAMR_BUILD_SIMD to 0
35+
if (WAMR_BUILD_SIMD EQUAL 0)
36+
add_definitions(-DWASM_ENABLE_SIMD=0)
37+
else()
38+
add_definitions(-DWASM_ENABLE_SIMD=1)
39+
endif()
40+
3441
add_definitions(-DWASM_ENABLE_INTERP=1)
3542
add_definitions(-DWASM_ENABLE_WAMR_COMPILER=1)
3643
add_definitions(-DWASM_ENABLE_BULK_MEMORY=1)
3744
add_definitions(-DWASM_DISABLE_HW_BOUND_CHECK=1)
3845
add_definitions(-DWASM_ENABLE_SHARED_MEMORY=1)
3946
add_definitions(-DWASM_ENABLE_THREAD_MGR=1)
4047
add_definitions(-DWASM_ENABLE_TAIL_CALL=1)
41-
add_definitions(-DWASM_ENABLE_SIMD=1)
4248
add_definitions(-DWASM_ENABLE_REF_TYPES=1)
4349
add_definitions(-DWASM_ENABLE_CUSTOM_NAME_SECTION=1)
4450
add_definitions(-DWASM_ENABLE_AOT_STACK_FRAME=1)
@@ -132,21 +138,11 @@ endif ()
132138

133139
message ("-- Build as target ${WAMR_BUILD_TARGET}")
134140

135-
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
136-
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64"
137-
OR WAMR_BUILD_TARGET MATCHES "AARCH64.*" OR WAMR_BUILD_TARGET MATCHES "RISCV64.*")
138-
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
139-
# Add -fPIC flag if build as 64-bit
140-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
141-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
142-
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
143-
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -fPIC")
144-
endif ()
145-
else ()
146-
add_definitions (-m32)
147-
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
148-
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
149-
endif ()
141+
# Add -m32 flag if compiling on 64-bit system for 32-bit x86 target
142+
if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND WAMR_BUILD_TARGET STREQUAL "X86_32")
143+
add_definitions (-m32)
144+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
145+
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
150146
endif ()
151147

152148
if (NOT CMAKE_BUILD_TYPE)
@@ -275,6 +271,8 @@ else ()
275271
message ("-- Lib wasi-threads disabled")
276272
endif ()
277273

274+
set (WAMR_BUILD_WAMR_COMPILER 1)
275+
278276
include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
279277
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
280278
include (${SHARED_DIR}/utils/shared_utils.cmake)
@@ -376,7 +374,7 @@ add_library (aotclib ${IWASM_COMPL_SOURCE})
376374

377375
add_executable (wamrc main.c)
378376
check_pie_supported()
379-
set_target_properties (wamrc PROPERTIES POSITION_INDEPENDENT_CODE ON)
377+
set_target_properties (wamrc vmlib aotclib PROPERTIES POSITION_INDEPENDENT_CODE ON)
380378
set_version_info (wamrc)
381379

382380
if (LLVM_LINK_LLVM_DYLIB)
@@ -398,4 +396,5 @@ else()
398396
${UV_A_LIBS})
399397
endif()
400398

401-
install (TARGETS wamrc DESTINATION bin)
399+
include (GNUInstallDirs)
400+
install (TARGETS wamrc)

0 commit comments

Comments
 (0)