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

[libc] init uefi os target #120687

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
756a121
[libc] init uefi os target
RossComputerGuy Dec 20, 2024
9150a62
[libc] save efi image handle and system table in crt1
RossComputerGuy Dec 20, 2024
52abff6
[libc] implement uefi exit()
RossComputerGuy Dec 20, 2024
d21c902
[libc] add __stack_chk_fail and abort to uefi
RossComputerGuy Dec 20, 2024
6ba52a4
[libc] support scudo in uefi
RossComputerGuy Dec 20, 2024
3a72dae
[libc] work on puts in uefi
RossComputerGuy Dec 20, 2024
91f554d
[libc] add os util out and err writes for uefi
RossComputerGuy Dec 21, 2024
c7093ea
[libc] revert target triple hack
RossComputerGuy Dec 24, 2024
ac12e60
[libc] add uefi to docs
RossComputerGuy Dec 24, 2024
5ae9b03
[libc] replace __uefi__ macro with __UEFI__
RossComputerGuy Dec 24, 2024
2c17e66
[libc] add uefi timespec
RossComputerGuy Dec 24, 2024
99e4e9f
[libc] working on uefi tests
RossComputerGuy Dec 24, 2024
e082649
[libc] add ctor and dtor to uefi
RossComputerGuy Dec 24, 2024
d7cbeea
[libc] make uefi tests build
RossComputerGuy Dec 25, 2024
778c66c
[libc] add python test runner for uefi
RossComputerGuy Dec 25, 2024
332c399
[libc] remove param names from unused uefi functions
RossComputerGuy Jan 8, 2025
0d12108
[libc] fix uefi code formatting
RossComputerGuy Jan 8, 2025
8960508
[libc] add copyright to EFIAPI macro
RossComputerGuy Jan 22, 2025
c0211ab
[libc] fix uefi signal-macros header
RossComputerGuy Jan 22, 2025
c57b248
[libc] fix uefi nitpicks
RossComputerGuy Feb 8, 2025
41a17d3
[libc] make uefi exit unreachable past exit call
RossComputerGuy Feb 8, 2025
a6e47de
[libc] fix uefi puts formatting
RossComputerGuy Feb 8, 2025
61cad73
[libc] adjust testing for uefi
RossComputerGuy Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ endif()

if(LIBC_TARGET_OS_IS_GPU)
include(prepare_libc_gpu_build)
endif()

if(LIBC_TARGET_OS_IS_GPU OR LIBC_TARGET_OS_IS_UEFI)
set(LIBC_ENABLE_UNITTESTS OFF)
endif()

Expand Down
2 changes: 2 additions & 0 deletions libc/cmake/modules/LLVMLibCArchitectures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ elseif(LIBC_TARGET_OS STREQUAL "windows")
set(LIBC_TARGET_OS_IS_WINDOWS TRUE)
elseif(LIBC_TARGET_OS STREQUAL "gpu")
set(LIBC_TARGET_OS_IS_GPU TRUE)
elseif(LIBC_TARGET_OS STREQUAL "uefi")
set(LIBC_TARGET_OS_IS_UEFI TRUE)
else()
message(FATAL_ERROR
"Unsupported libc target operating system ${LIBC_TARGET_OS}")
Expand Down
13 changes: 11 additions & 2 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ function(add_integration_test test_name)
${INTEGRATION_TEST_ENV}
$<$<BOOL:${LIBC_TARGET_OS_IS_GPU}>:${gpu_loader_exe}>
${CMAKE_CROSSCOMPILING_EMULATOR}
$<$<BOOL:${LIBC_TARGET_OS_IS_UEFI}>:${LIBC_TARGET_TRIPLE}>
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this doing? This line is supposed to define the 'emulator, so I'm guessing intentionally that this will run x86_64-unknown-uefi-gnu test.exe`?

Copy link
Member Author

Choose a reason for hiding this comment

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

It adds the target triplet for the test runner.

${INTEGRATION_TEST_LOADER_ARGS}
$<TARGET_FILE:${fq_build_target_name}> ${INTEGRATION_TEST_ARGS})
add_custom_target(
Expand Down Expand Up @@ -673,6 +674,7 @@ function(add_libc_hermetic test_name)
libc.src.string.memset
libc.src.strings.bcmp
libc.src.strings.bzero
libc.src.stdlib.atexit
Copy link
Contributor

Choose a reason for hiding this comment

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

The list here is for libcalls that the compiler specifically exports, however we do need atexit. Normally this is a dependency on the startup object so it gets picked up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, for whatever reason that I can't remember I needed to add it for the tests to compile.

)

if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
Expand Down Expand Up @@ -743,6 +745,11 @@ function(add_libc_hermetic test_name)
endif()
endforeach()

if(LIBC_TARGET_OS_IS_UEFI)
target_link_options(${fq_build_target_name} PRIVATE
${LIBC_COMPILE_OPTIONS_DEFAULT} "-Wl,/lldmingw")
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for switching to lldmingw? We should be using lld-link which is already the default in the Clang UEFI driver:

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this was to fix archive libraries not linking all the symbols.

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like that's not the proper solution, though I don't know off the top of my head why symbols would be missing. I'd think that lld-link wouldn't have the static library ordering thing that GNU linkers have. IF that's the case then it would be easier to just prepend the linker arguments with --whole-archive or whatever the lld-link equivalent is. (I think there's a per-static library version we could use when building the test list.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I did remember trying --whole-archive but that didn't work either. It seems only lldmingw works or explicitly putting the object files needed.

endif()

if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
target_link_options(${fq_build_target_name} PRIVATE
${LIBC_COMPILE_OPTIONS_DEFAULT} -Wno-multi-gpu
Expand Down Expand Up @@ -778,7 +785,8 @@ function(add_libc_hermetic test_name)
${fq_deps_list})
# TODO: currently the dependency chain is broken such that getauxval cannot properly
# propagate to hermetic tests. This is a temporary workaround.
if (LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
# getauxval does not exist on UEFI.
if (LIBC_TARGET_ARCHITECTURE_IS_AARCH64 AND NOT LIBC_TARGET_OS_IS_UEFI)
Copy link
Member

Choose a reason for hiding this comment

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

There should be a TODO comment explaining why this is disabled for UEFI.

Copy link
Member Author

Choose a reason for hiding this comment

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

TODO shouldn't be needed since there's no AUX vector in UEFI.

target_link_libraries(
${fq_build_target_name}
PRIVATE
Expand All @@ -793,7 +801,8 @@ function(add_libc_hermetic test_name)
endif()

set(test_cmd ${HERMETIC_TEST_ENV}
$<$<BOOL:${LIBC_TARGET_OS_IS_GPU}>:${gpu_loader_exe}> ${CMAKE_CROSSCOMPILING_EMULATOR} ${HERMETIC_TEST_LOADER_ARGS}
$<$<BOOL:${LIBC_TARGET_OS_IS_GPU}>:${gpu_loader_exe}> ${CMAKE_CROSSCOMPILING_EMULATOR}
$<$<BOOL:${LIBC_TARGET_OS_IS_UEFI}>:${LIBC_TARGET_TRIPLE}> ${HERMETIC_TEST_LOADER_ARGS}
$<TARGET_FILE:${fq_build_target_name}> ${HERMETIC_TEST_ARGS})
add_custom_target(
${fq_target_name}
Expand Down
29 changes: 29 additions & 0 deletions libc/config/uefi/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"errno": {
"LIBC_CONF_ERRNO_MODE": {
"value": "LIBC_ERRNO_MODE_SHARED"
}
},
"printf": {
"LIBC_CONF_PRINTF_DISABLE_FLOAT": {
"value": true
},
"LIBC_CONF_PRINTF_DISABLE_INDEX_MODE": {
"value": true
},
"LIBC_CONF_PRINTF_DISABLE_WRITE_INT": {
"value": true
},
"LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE": {
"value": true
},
"LIBC_CONF_PRINTF_DISABLE_STRERROR": {
"value": true
}
},
"qsort": {
"LIBC_CONF_QSORT_IMPL": {
"value": "LIBC_QSORT_HEAP_SORT"
}
}
}
Loading