Skip to content
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

Fix build issues when compiling WAMRC as a cross-compiler #4112

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

peter-tatrai
Copy link
Contributor

Description

This pull request addresses issues encountered when compiling WAMRC to be a cross-compiler—running on a PC while targeting an embedded ARM platform. The key fixes include:

Fixes in This PR

  • -m32 compiler flag

    • The -m32 flag was previously added unconditionally for 32-bit targets, causing issues for non-x86 platforms.
    • Now, -m32 is only added when targeting a 32-bit x86 platform (X86_32), ensuring it is only applied where supported.
  • Improved PIC Flag Handling:

    • The logic for setting PIC (-fPIC) based on WAMR_BUILD_PLATFORM was overly complex.
    • This is now handled in CMake instead of using platform-specific conditions.
  • AOT Relocation Functions:

    • WAMRC previously included platform-specific headers (e.g., <arm_neon.h>) that are not available on a PC.
    • Since these AOT relocation functions are only used when executing AOT-compiled code (not by WAMRC itself), dummy versions have been introduced.
    • A more complete solution would be to split the code to avoid linking these functions altogether, but that would require more extensive changes.
  • SIMD Compilation Issues:

    • WAMRC attempted to include target platform-specific SIMD headers (e.g., ARM headers) when compiling on a different host platform (e.g., x86).
    • To address this, an option has been added to disable SIMD in WAMRC when cross-compiling.

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.
@calvin2021y
Copy link

hi @peter-tatrai

<arm_neon.h> is required at runtime ? if so maybe allow user set sysroot and triple by args will fix the problem.

@peter-tatrai
Copy link
Contributor Author

The header file is required at compile-time, but this is not about cross-compiling wamrc—rather, it's about building a cross-compiler. In this scenario, we have both a host and a target architecture (e.g., host: x86_64, target: armv7). However, the CMake files currently use a single variable, WAMR_BUILD_PLATFORM, for both, even though it should only define the target platform. This causes issues, such as the one mentioned above.

With these commits and -DWAMR_BUILD_INVOKE_NATIVE_GENERAL=1 -DWAMR_BUILD_SIMD=0 -DWAMR_BUILD_TARGET=ARMv7, it is possible to build wamrc as a runnable binary on a PC while cross-compiling AOT modules for armv7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants