-
Notifications
You must be signed in to change notification settings - Fork 1
Build changes for ARM64 #534
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
base: main
Are you sure you want to change the base?
Changes from all commits
861e6a3
c74d882
57b4dca
828a1de
95011c6
03ce898
f5a0587
c810cc5
5a078d3
be68685
24a7190
cb3089e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[submodule "external/glibc"] | ||
path = external/glibc | ||
url = https://www.sourceware.org/git/glibc.git | ||
url = https://github.com/immunant/IA2-glibc.git | ||
[submodule "external/b63"] | ||
path = external/b63 | ||
url = https://github.com/okuvshynov/b63.git |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ else() | |
endif() | ||
set(QEMU_COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} | ||
"-one-insn-per-tb" | ||
"-L" "${CMAKE_BINARY_DIR}/external/glibc/sysroot/usr/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the sysroot not include the headers anymore? Why are we removing the usr suffix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The COMMAND ${CMAKE_COMMAND} -E copy_directory ${SYSROOT_SRC_DIR}/include ${SYSROOT_BIN_DIR}/usr/include We remove this suffix because the libraries should end up in Arguably it would be cleanest to also store the includes at |
||
"-E" "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/external/glibc/sysroot/usr/lib:/usr/aarch64-linux-gnu/lib:/usr/aarch64-linux-gnu/lib64" | ||
"-L" "${CMAKE_BINARY_DIR}/external/glibc/sysroot/" | ||
"-E" "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/external/glibc/sysroot/lib:/usr/aarch64-linux-gnu/lib:/usr/aarch64-linux-gnu/lib64" | ||
) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,15 +55,18 @@ target_link_options(libia2 INTERFACE | |
set_property(TARGET libia2 PROPERTY INTERFACE_LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/padding.ld ${CMAKE_CURRENT_BINARY_DIR}/dynsym.syms) | ||
|
||
if (LIBIA2_AARCH64) | ||
set(SYSROOT_BIN_DIR ${CMAKE_BINARY_DIR}/external/glibc/sysroot) | ||
set(LIBC_PATH ${SYSROOT_BIN_DIR}/lib/libc.so.6) | ||
set(LD_LINUX_PATH ${SYSROOT_BIN_DIR}/lib/ld-linux-aarch64.so.1) | ||
if (LIBIA2_REBUILD_GLIBC) | ||
ExternalProject_Add(glibc | ||
SOURCE_DIR ${CMAKE_SOURCE_DIR}/external/glibc | ||
BINARY_DIR ${CMAKE_BINARY_DIR}/external/glibc | ||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env | ||
# ffixed-x18 has to be set here instead of CFLAGS for it to apply to all files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: s/ffixed-x18/compiler flags in the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix in a follow-up. |
||
"CC=aarch64-linux-gnu-gcc -ffixed-x18" | ||
"CC=${CMAKE_C_COMPILER} -target aarch64-linux-gnu -ffixed-x18 -march=armv8.5-a+memtag --rtlib=compiler-rt -O3" | ||
# this is needed for some test files built by the build system | ||
"CXX=aarch64-linux-gnu-g++ -ffixed-x18" | ||
"CXX=${CMAKE_CXX_COMPILER} -target aarch64-linux-gnu -ffixed-x18 -march=armv8.5-a+memtag --rtlib=compiler-rt -O3" | ||
${CMAKE_SOURCE_DIR}/external/glibc/configure | ||
"--build=aarch64-linux-gnu" | ||
"--target=aarch64-linux-gnu" | ||
|
@@ -74,14 +77,15 @@ if (LIBIA2_AARCH64) | |
# This is only for the heap tunable | ||
"--enable-memory-tagging" | ||
BUILD_COMMAND make -j8 | ||
# places the built libc.so and ld.so at the locations expected by QEMU's LD_LIBPRARY_PATH | ||
INSTALL_COMMAND make install | ||
USES_TERMINAL_CONFIGURE TRUE | ||
USES_TERMINAL_BUILD TRUE | ||
USES_TERMINAL_INSTALL TRUE | ||
BUILD_BYPRODUCTS ${LIBC_PATH} ${LD_LINUX_PATH} | ||
) | ||
else() | ||
set(SYSROOT_SRC_DIR ${CMAKE_SOURCE_DIR}/external/glibc_sysroot) | ||
set(SYSROOT_BIN_DIR ${CMAKE_BINARY_DIR}/external/glibc/sysroot/usr) | ||
file(GLOB SYSROOT_HEADERS_SRC | ||
${SYSROOT_SRC_DIR}/include/*.h | ||
${SYSROOT_SRC_DIR}/include/*/*.h | ||
|
@@ -94,14 +98,13 @@ if (LIBIA2_AARCH64) | |
${SYSROOT_HEADERS} | ||
COMMAND ${CMAKE_COMMAND} -E copy ${SYSROOT_SRC_DIR}/lib/libc.so.6 ${SYSROOT_BIN_DIR}/lib/ | ||
COMMAND ${CMAKE_COMMAND} -E copy ${SYSROOT_SRC_DIR}/lib/ld-linux-aarch64.so.1 ${SYSROOT_BIN_DIR}/lib/ | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${SYSROOT_SRC_DIR}/include ${SYSROOT_BIN_DIR}/include | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${SYSROOT_SRC_DIR}/include ${SYSROOT_BIN_DIR}/usr/include | ||
COMMENT "Copying glibc prebuilts to sysroot" | ||
) | ||
add_custom_target(glibc | ||
DEPENDS ${SYSROOT_BIN_DIR}/lib/libc.so.6 ${SYSROOT_BIN_DIR}/lib/ld-linux-aarch64.so.1 ${SYSROOT_HEADERS} | ||
) | ||
endif() | ||
set(LIBC_PATH ${SYSROOT_BIN_DIR}/lib/libc.so.6) | ||
else() | ||
# Find libc. We cannot simply do `find_library(LIBC c REQUIRED)` because | ||
# `libc.so` itself is a linker script with glibc, while we need the path of | ||
|
@@ -130,7 +133,29 @@ add_custom_command( | |
COMMENT "Padding TLS segment of libc" | ||
) | ||
|
||
add_custom_target(libc-ia2 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libc.so.6") | ||
# Explicitly depend on ld.so because we must use one built with our toolchain | ||
if(LIBIA2_AARCH64) | ||
if(NOT DEFINED LD_LINUX_PATH) | ||
message(FATAL_ERROR "Could not find ld-linux-aarch64.so.1 in: ${LIBC_PATHS}\n") | ||
endif() | ||
|
||
add_custom_command( | ||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ld-linux-aarch64.so.1 | ||
COMMAND ${CMAKE_COMMAND} -E copy ${LD_LINUX_PATH} ${CMAKE_CURRENT_BINARY_DIR}/ld-linux-aarch64.so.1 | ||
DEPENDS ${LD_LINUX_PATH} | ||
COMMENT "Copying ld-linux-aarch64.so.1" | ||
) | ||
add_library(libc SHARED IMPORTED) | ||
set_property(TARGET libc PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libc.so.6") | ||
target_link_libraries(libia2 PUBLIC libc) | ||
add_library(ld-linux SHARED IMPORTED) | ||
set_property(TARGET ld-linux PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/ld-linux-aarch64.so.1") | ||
target_link_libraries(libia2 PUBLIC ld-linux) | ||
add_custom_target(libc-ia2 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libc.so.6" "${CMAKE_CURRENT_BINARY_DIR}/ld-linux-aarch64.so.1") | ||
else() | ||
add_custom_target(libc-ia2 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libc.so.6") | ||
endif() | ||
|
||
|
||
if (LIBIA2_AARCH64) | ||
add_dependencies(libc-ia2 glibc) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was switching -Wl,-rpath and -Wl,-rpath-link in these two lines intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was intentional and fixed things at the time (see commit message on f5a0587), but may be obviated by other changes in this series. I'll revisit this and see if it's still necessary.