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

Library Forwarding: Make building on weak cross-compiling setups easier #3597

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

neobrain
Copy link
Member

ARM64 Ubuntu provides both an x86 cross-compiler and corresponding glibc/stdlibc++ libraries, which makes cross-compiling FEX's guest library wrappers very easy. Sadly most other distributions only ship the compiler without any libraries/headers at all. In such environments, it can be easier to compile only the host-side libraries while offloading builds of the guest libraries to another machine / VM.

This PR adds two main features to make such fallback setups possible:

  • Guest wrappers may now be built separately from the main project by running cmake ../ThunkLibs/CMakeLists.txt -DX86_32_TOOLCHAIN_FILE=`realpath ../toolchain_x86_32.cmake` -DX86_64_TOOLCHAIN_FILE=`realpath ../toolchain_x86_64.cmake` -DX86_DEV_ROOTFS=/ from a dedicated build folder.
  • The new X86_DEV_ROOTFS CMake setting can be used to provide a development x86 rootfs, from which standard headers will be read. (Specifically, Ubuntu requires these packages: libstdc++-12-dev-amd64-cross libstdc++-12-dev-i386-cross libstdc++-12-dev libc6-dev-amd64-cross libc6-dev-i386-cross linux-libc-dev-amd64-cross linux-libc-dev-i386-cross)

@alyssarosenzweig
Copy link
Collaborator

In the case where we have a working x86 cross compiler when building on arm64, and can procure a x86 rootfs but without the proper multilib integration, does X86_DEV_ROOTFS provide the necessary glue to build thunks without needing a separate machine/VM? If so, I think that sounds like a decent approach for Fedora. It would be great to get some documentation (either in-tree or contributed to wiki) about how to use these new options to build fex on such weak setups.

@neobrain
Copy link
Member Author

In the case where we have a working x86 cross compiler when building on arm64, and can procure a x86 rootfs but without the proper multilib integration, does X86_DEV_ROOTFS provide the necessary glue to build thunks without needing a separate machine/VM? If so, I think that sounds like a decent approach for Fedora. It would be great to get some documentation (either in-tree or contributed to wiki) about how to use these new options to build fex on such weak setups.

It might work without a VM, but I haven't tested it. You'd have to add the dev rootfs paths to the CMake toolchain files in our project root so that the CMake targets in GuestLibs/CMakeLists.txt can also find the headers/libraries. Definitely interested to see someone try that out!

ThunkLibs/CMakeLists.txt Outdated Show resolved Hide resolved
@neobrain neobrain force-pushed the feature_libfwd_build branch 2 times, most recently from afb9526 to ba6c175 Compare April 25, 2024 13:28
@neobrain neobrain force-pushed the feature_libfwd_build branch 2 times, most recently from 749cc9c to 98d3de8 Compare April 25, 2024 13:38
@neobrain
Copy link
Member Author

Realized we can achieve the same effect by using --sysroot and re-adding the global /usr/include directory for library headers, which is much cleaner than adding hardcoded include directories manually.

@neobrain neobrain force-pushed the feature_libfwd_build branch from 98d3de8 to 68b9bab Compare April 25, 2024 13:59
@neobrain neobrain marked this pull request as draft April 25, 2024 14:32
ExternalProject_Add(guest-libs
PREFIX Guest/guest-libs
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/GuestLibs"
BINARY_DIR "../Guest"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something's off about this. I'm getting weird RPATH errors without ../, but with ../ it's clearly putting the data in the wrong folder.

Copy link
Contributor

@asahilina asahilina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this out on Fedora and successfully got thunks to work with a hacked up GCC sysroot and custom target files (because Fedora's x86 cross compilers aren't built the same as the native ones so they need a bunch of overrides).

I think if this is merged as-is with just these two fixes, we're basically good for the x86 sysroot approach!

"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DBUILD_FEX_LINUX_TESTS=${BUILD_FEX_LINUX_TESTS}"
"-DENABLE_CLANG_THUNKS=${ENABLE_CLANG_THUNKS}"
"-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${FEX_PROJECT_SOURCE_DIR}/toolchain_x86_32.cmake"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ${X86_32_TOOLCHAIN_FILE}

"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DBUILD_FEX_LINUX_TESTS=${BUILD_FEX_LINUX_TESTS}"
"-DENABLE_CLANG_THUNKS=${ENABLE_CLANG_THUNKS}"
"-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${FEX_PROJECT_SOURCE_DIR}/toolchain_x86_64.cmake"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ${X86_64_TOOLCHAIN_FILE}

@asahilina
Copy link
Contributor

That said, the first two commits on their own are fairly useless right now. The issue is that the host thunks build relies on having the guest environment available in order to do the data_layout comparison. To make that work, we'd have to modify thunkgen to make it able to serialize the guest data_layout, generate that on the guest builder, and use those serialized files to build the host thinks.

I'll try to extract just the rootfs change and verify that it's sufficient for a Fedora build if the right sysroot is available, so we can merge that now and leave the rest for later.

@asahilina
Copy link
Contributor

asahilina commented Dec 20, 2024

Submitted just the last commit as #4230 (rebased).

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.

3 participants