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

add x86_64-w64-windows-gnu/aarch64-w64-windows-gnu/i686-w64-windows-gnu aot triple support #4103

Open
calvin2021y opened this issue Feb 24, 2025 · 8 comments

Comments

@calvin2021y
Copy link

current wamrc only support mscv triple, can not made it work with x86_64-w64-windows-gnu. (you can get this from https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-msvcrt-ubuntu-20.04-x86_64.tar.xz)

@calvin2021y calvin2021y changed the title add x86_64-w64-windows-gnu aot triple support add x86_64-w64-windows-gnu/aarch64-w64-windows-gnu/i686-w64-windows-gnu aot triple support Feb 24, 2025
@calvin2021y
Copy link
Author

I guess allow pass triple from arguments for wamrc will be a lot easy, and support all future arch & target.

if pass triple, then arch and target can be infered.

@TianlongLiang
Copy link
Collaborator

You can use option --target-abit=gnu to change target abi, should it be sufficient for your usage?

./wamrc.exe --target-abi=help
Supported ABI: gnu eabi eabihf gnueabihf msvc ilp32 ilp32f ilp32d lp64 lp64f lp64d

@calvin2021y
Copy link
Author

I guess it must be x86_64-w64-windows-gnu, with --target-abit=gnu I get x86_64-pc-linux-gnu

./wamrc.exe --target-abi=gnu --target=x86_64 --enable-tail-call --format=aot -o fib.win fib.wasm
Create AoT compiler with:           
 target:        x86_64             
 target cpu:                       
 target triple: x86_64-pc-linux-gnu
 cpu features:                     
 opt level:     3                  
 size level:    3                  
 output format: AoT file           
Compile success, file fib.win was generated.

crashed when load aot

./tests_wamr.exe             
=================================================================
==3320==ERROR: AddressSanitizer: access-violation on unknown address 0x01cf501c0004 (pc 0x7ff8f68f4678 bp 0x006411efb8b0 sp 0x006411efb828 T0)
==3320==The signal is caused by a WRITE memory access.                                                                                        
    #0 0x7ff8f68f4677 in memset+0x77 (C:\Windows\SYSTEM32\ntdll.dll+0x1800a4677)                                                              
    #1 0x7ff8b3ff2cc0 in _asan_memset+0x90 (C:\Users\admin\libclang_rt.asan_dynamic-x86_64.dll+0x180042cc0)                                   
    #2 0x7ff7f0b34206  (C:\Users\admin\tests_wamr.exe+0x140214206)                                                                            
    #3 0x7ff7f0b34c67  (C:\Users\admin\tests_wamr.exe+0x140214c67)                                                                            
    #4 0x7ff7f0ac02ec  (C:\Users\admin\tests_wamr.exe+0x1401a02ec)                                                                            
    #5 0x7ff7f0a5f2d5  (C:\Users\admin\tests_wamr.exe+0x14013f2d5)                                                                            
    #6 0x7ff7f0a5303a  (C:\Users\admin\tests_wamr.exe+0x14013303a)
    #7 0x7ff7f0a5033a  (C:\Users\admin\tests_wamr.exe+0x14013033a)
    #8 0x7ff7f0999403  (C:\Users\admin\tests_wamr.exe+0x140079403)
    #9 0x7ff7f0999493  (C:\Users\admin\tests_wamr.exe+0x140079493)
    #10 0x7ff7f097a5e7  (C:\Users\admin\tests_wamr.exe+0x14005a5e7)
    #11 0x7ff7f092133b  (C:\Users\admin\tests_wamr.exe+0x14000133b)
    #12 0x7ff7f0921395  (C:\Users\admin\tests_wamr.exe+0x140001395)
    #13 0x7ff8f5597373 in BaseThreadInitThunk+0x13 (C:\Windows\System32\KERNEL32.DLL+0x180017373)
    #14 0x7ff8f689cc90 in RtlUserThreadStart+0x20 (C:\Windows\SYSTEM32\ntdll.dll+0x18004cc90)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: access-violation (C:\Windows\SYSTEM32\ntdll.dll+0x1800a4677) in memset+0x77
==3320==ABORTING

@TianlongLiang
Copy link
Collaborator

This is due to vendor_sys using the one defined in LLVMGetDefaultTargetTriple, it seems that the default LLVM build for vendor_sys is Linux. Is building wamrc with the llvm library link you provided an option for you? If so, you can try whether it solves your problem

@calvin2021y
Copy link
Author

calvin2021y commented Feb 26, 2025

The wamrc.exec default is x86_64-pc-windows-msvc ( without pass target-abi and target), use x86_64-pc-windows-msvc crash for me too.

./wamrc.exe --target-abi=msvc --enable-tail-call --format=aot -o fib.win fib.wasm
Create AoT compiler with:
  target:        x86_64
  target cpu:
  target triple: x86_64-pc-windows-msvc
  cpu features:
  opt level:     3
  size level:    1
  output format: AoT file
Compile success, file fib.win was generated.

I guess problem is from here, allow user set vendor_sys|triple from arguments will be much simple and prevent more questions(like require android/ios/musl triple).

            /**
             * Set <vendor>-<sys> according to abi to generate the object file
             * with the correct file format which might be different from the
             * default object file format of the host, e.g., generating AOT file
             * for Windows/MacOS under Linux host, or generating AOT file for
             * Linux/MacOS under Windows host.
             */

            if (!strcmp(abi, "msvc")) {
                if (!strcmp(arch1, "i386"))
                    vendor_sys = "-pc-win32-";
                else
                    vendor_sys = "-pc-windows-";
            }
            else {
                if (is_baremetal_target(arch, cpu, abi))
                    vendor_sys = "-unknown-none-";
                else
                    vendor_sys = "-pc-linux-";
            }

@TianlongLiang
Copy link
Collaborator

You are right, the correct way is to add the command line option to control vendor_sys(add some extra check to make sure triple is compatible too)

@calvin2021y
Copy link
Author

calvin2021y commented Feb 26, 2025

use wamrc.exec --target-abi=gnu --target=x86_64 --enable-indirect-mode --format=aot -o fib.win fib.wasm, get this error

* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x1647bf83edc: User-mode data execution prevention (DEP) violation at location 0x1647bf83edc
  * frame #0: 0x000001647bf83edc
    frame #1: 0x00007ff7de9a64ea tests_wamr.exe`invoke_ii_i
    frame #2: 0x00007ff7de9ede12 tests_wamr.exe`invoke_native_internal
    frame #3: 0x00007ff7de9ed762 tests_wamr.exe`aot_call_function
    frame #4: 0x00007ff7de92d495 tests_wamr.exe`wasm_runtime_call_wasm
    frame #5: 0x00007ff7de92f77b tests_wamr.exe`wasm_runtime_call_wasm_a
    frame #6: 0x00007ff7de90aab2 tests_wamr.exe`main
    frame #7: 0x00007ff7de8b133c tests_wamr.exe`__tmainCRTStartup at crtexe.c:266:15
    frame #8: 0x00007ff7de8b1396 tests_wamr.exe`mainCRTStartup at crtexe.c:186:9
    frame #9: 0x00007ff8f5597374 kernel32.dll`BaseThreadInitThunk + 20
    frame #10: 0x00007ff8f689cc91 ntdll.dll`RtlUserThreadStart + 33

@calvin2021y
Copy link
Author

and armv7a-unknown-linux-android will not work for any target, report expect arm32, but get armv7. also try thumbv7 not work

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

No branches or pull requests

2 participants