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

__movsb not defined when cross compiling with clang #116

Closed
apple1417 opened this issue May 11, 2023 · 0 comments · Fixed by #117
Closed

__movsb not defined when cross compiling with clang #116

apple1417 opened this issue May 11, 2023 · 0 comments · Fixed by #117

Comments

@apple1417
Copy link
Contributor

I am trying to compile this from a linux host, using clang with the x86_64-pc-windows-msvc target (and manually pointing it at the msvc headers/libs). When clang's compiling for windows, it also defines _MSC_VER, which means trampoline.c will try use __movsb instead of memcpy. Unfortunately, it seems msvc implicitly defines intrinsics, so it's header only has forward declarations, while clang normally defines inline assembly functions it's their headers, so I get a linker error. When compiling for windows, clang's intrinsics header just redirects to msvc's, so there's no way for me to be clever with includes, I need to modify code somewhere.

#51 would fix this, though it isn't the most comprehensive solution. I haven't debugged why, but I know from experience that clang on a windows host does link properly. Additionally, you can run mingw through clang, in which case _MSC_VER, __clang__ and __MINGW32__ are all defined at once, and under which once again it links properly. You could try something messing around with __has_builtin to be more accurate - though honestly I think it's a bit overkill, imo better to just keep the simple _MSC_VER check and just add a MINHOOK_NO_INTRINSICS override. I'm happy to contribute the code, just figured I'd post the issue first to get guidance on what solution's preferred.

For replication, download the msvc files using xwin, then here's a cmake toolchain file (may need to use absolute paths).

Expand
set(CMAKE_SYSTEM_NAME Windows)

set(triple x86_64-pc-windows-msvc)

set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})

add_compile_options(
    -ffreestanding
    -isystemxwin/sdk/include/um
    -isystemxwin/sdk/include/ucrt
    -isystemxwin/sdk/include/shared
    -isystemxwin/crt/include
)
add_link_options(
    -Lxwin/sdk/lib/um/x86_64
    -Lxwin/crt/lib/x86_64
    -Lxwin/sdk/lib/ucrt/x86_64
)
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 a pull request may close this issue.

1 participant