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
This commit is contained in:
peter-tatrai 2025-03-20 07:24:30 +01:00 committed by GitHub
parent efa8019bdb
commit 1f14f4ec0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 19 deletions

View File

@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "aot_reloc.h"
SymbolMap *
get_target_symbol_map(uint32 *sym_num)
{
abort();
}
uint32
get_plt_table_size(void)
{
abort();
}
void
init_plt_table(uint8 *plt)
{
abort();
}
void
get_current_target(char *target_buf, uint32 target_buf_size)
{
abort();
}
bool
apply_relocation(AOTModule *module, uint8 *target_section_addr,
uint32 target_section_size, uint64 reloc_offset,
int64 reloc_addend, uint32 reloc_type, void *symbol_addr,
int32 symbol_index, char *error_buf, uint32 error_buf_size)
{
abort();
}

View File

@ -21,7 +21,10 @@ if (WAMR_BUILD_AOT_VALIDATOR EQUAL 1)
list (APPEND c_source_all ${IWASM_AOT_DIR}/aot_validator.c)
endif ()
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
if (WAMR_BUILD_WAMR_COMPILER EQUAL 1)
# AOT reloc functions are not used during AOT compilation
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_dummy.c)
elseif (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_64.c)
elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_32.c)

View File

@ -31,6 +31,13 @@ endif()
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# Turn on SIMD by default, can be turned off by setting WAMR_BUILD_SIMD to 0
if (WAMR_BUILD_SIMD EQUAL 0)
add_definitions(-DWASM_ENABLE_SIMD=0)
else()
add_definitions(-DWASM_ENABLE_SIMD=1)
endif()
add_definitions(-DWASM_ENABLE_INTERP=1)
add_definitions(-DWASM_ENABLE_WAMR_COMPILER=1)
add_definitions(-DWASM_ENABLE_BULK_MEMORY=1)
@ -38,7 +45,6 @@ add_definitions(-DWASM_DISABLE_HW_BOUND_CHECK=1)
add_definitions(-DWASM_ENABLE_SHARED_MEMORY=1)
add_definitions(-DWASM_ENABLE_THREAD_MGR=1)
add_definitions(-DWASM_ENABLE_TAIL_CALL=1)
add_definitions(-DWASM_ENABLE_SIMD=1)
add_definitions(-DWASM_ENABLE_REF_TYPES=1)
add_definitions(-DWASM_ENABLE_CUSTOM_NAME_SECTION=1)
add_definitions(-DWASM_ENABLE_AOT_STACK_FRAME=1)
@ -132,21 +138,11 @@ endif ()
message ("-- Build as target ${WAMR_BUILD_TARGET}")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64"
OR WAMR_BUILD_TARGET MATCHES "AARCH64.*" OR WAMR_BUILD_TARGET MATCHES "RISCV64.*")
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
# Add -fPIC flag if build as 64-bit
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -fPIC")
endif ()
else ()
# Add -m32 flag if compiling on 64-bit system for 32-bit x86 target
if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND WAMR_BUILD_TARGET STREQUAL "X86_32")
add_definitions (-m32)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
endif ()
endif ()
if (NOT CMAKE_BUILD_TYPE)
@ -275,6 +271,8 @@ else ()
message ("-- Lib wasi-threads disabled")
endif ()
set (WAMR_BUILD_WAMR_COMPILER 1)
include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
include (${SHARED_DIR}/utils/shared_utils.cmake)
@ -376,7 +374,7 @@ add_library (aotclib ${IWASM_COMPL_SOURCE})
add_executable (wamrc main.c)
check_pie_supported()
set_target_properties (wamrc PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties (wamrc vmlib aotclib PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_version_info (wamrc)
if (LLVM_LINK_LLVM_DYLIB)
@ -398,4 +396,5 @@ else()
${UV_A_LIBS})
endif()
install (TARGETS wamrc DESTINATION bin)
include (GNUInstallDirs)
install (TARGETS wamrc)