Skip to content

Commit d7cbeea

Browse files
[libc] make uefi tests build
1 parent e082649 commit d7cbeea

File tree

32 files changed

+389
-238
lines changed

32 files changed

+389
-238
lines changed

libc/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ else()
257257
set(LIBC_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX})
258258
endif()
259259

260-
if(LIBC_TARGET_OS_IS_GPU)
261-
include(prepare_libc_gpu_build)
260+
if(LIBC_TARGET_OS_IS_GPU OR LIBC_TARGET_OS_IS_UEFI)
261+
if(LIBC_TARGET_OS_IS_GPU)
262+
include(prepare_libc_gpu_build)
263+
endif()
262264
set(LIBC_ENABLE_UNITTESTS OFF)
263265
endif()
264266

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ function(add_libc_hermetic test_name)
673673
libc.src.string.memset
674674
libc.src.strings.bcmp
675675
libc.src.strings.bzero
676+
libc.src.stdlib.atexit
676677
)
677678

678679
if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
@@ -743,6 +744,11 @@ function(add_libc_hermetic test_name)
743744
endif()
744745
endforeach()
745746

747+
if(LIBC_TARGET_OS_IS_UEFI)
748+
target_link_options(${fq_build_target_name} PRIVATE
749+
${LIBC_COMPILE_OPTIONS_DEFAULT} "-Wl,/lldmingw")
750+
endif()
751+
746752
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
747753
target_link_options(${fq_build_target_name} PRIVATE
748754
${LIBC_COMPILE_OPTIONS_DEFAULT} -Wno-multi-gpu
@@ -778,7 +784,7 @@ function(add_libc_hermetic test_name)
778784
${fq_deps_list})
779785
# TODO: currently the dependency chain is broken such that getauxval cannot properly
780786
# propagate to hermetic tests. This is a temporary workaround.
781-
if (LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
787+
if (LIBC_TARGET_ARCHITECTURE_IS_AARCH64 AND NOT LIBC_TARGET_OS_IS_UEFI)
782788
target_link_libraries(
783789
${fq_build_target_name}
784790
PRIVATE

libc/config/uefi/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"value": true
1616
},
1717
"LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE": {
18-
"value": false
18+
"value": true
1919
},
2020
"LIBC_CONF_PRINTF_DISABLE_STRERROR": {
2121
"value": true

libc/config/uefi/entrypoints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ set(TARGET_LIBC_ENTRYPOINTS
172172
libc.src.stdlib.atoi
173173
libc.src.stdlib.atol
174174
libc.src.stdlib.atoll
175+
libc.src.stdlib.atexit
175176
libc.src.stdlib.bsearch
176177
libc.src.stdlib.calloc
177178
libc.src.stdlib.div
@@ -188,7 +189,6 @@ set(TARGET_LIBC_ENTRYPOINTS
188189
libc.src.stdlib.strtod
189190
libc.src.stdlib.strtof
190191
libc.src.stdlib.strtol
191-
libc.src.stdlib.strtold
192192
libc.src.stdlib.strtoll
193193
libc.src.stdlib.strtoul
194194
libc.src.stdlib.strtoull

libc/docs/uefi/support.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ qsort_r |check|
198198
strtod |check|
199199
strtof |check|
200200
strtol |check|
201-
strtold |check|
202201
strtoll |check|
203202
strtoul |check|
204203
strtoull |check|

libc/include/llvm-libc-macros/signal-macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "linux/signal-macros.h"
1414
#elif defined(__NVPTX__) || defined(__AMDGPU__)
1515
#include "gpu/signal-macros.h"
16+
#elif defined(__UEFI__)
17+
#include "uefi/signal-macros.h"
1618
#endif
1719

1820
#endif // LLVM_LIBC_MACROS_SIGNAL_MACROS_H
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_header(
2+
signal_macros
3+
HDR
4+
signal-macros.h
5+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- Definition of GPU signal number macros ----------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_MACROS_GPU_SIGNAL_MACROS_H
10+
#define LLVM_LIBC_MACROS_GPU_SIGNAL_MACROS_H
11+
12+
#define SIGINT 2
13+
#define SIGILL 4
14+
#define SIGABRT 6
15+
#define SIGFPE 8
16+
#define SIGSEGV 11
17+
#define SIGTERM 15
18+
19+
#define SIG_DFL ((__sighandler_t)(0))
20+
#define SIG_IGN ((__sighandler_t)(1))
21+
#define SIG_ERR ((__sighandler_t)(-1))
22+
23+
// Max signal number
24+
#define NSIG 64
25+
26+
#define __NSIGSET_WORDS NSIG
27+
28+
#endif // LLVM_LIBC_MACROS_GPU_SIGNAL_MACROS_H

libc/src/__support/OSUtil/uefi/io.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ ssize_t read_from_stdin(char *buf, size_t size) {
2222

2323
void write_to_stdout(cpp::string_view msg) {
2424
// TODO: use mbstowcs once implemented
25-
efi_system_table->ConOut->OutputString(
26-
efi_system_table->ConOut, reinterpret_cast<const char16_t *>(msg.data()));
25+
for (size_t i = 0; i < msg.size(); i++) {
26+
char16_t e[2] = {msg[i], 0};
27+
efi_system_table->ConOut->OutputString(
28+
efi_system_table->ConOut, reinterpret_cast<const char16_t *>(&e));
29+
}
2730
}
2831

2932
void write_to_stderr(cpp::string_view msg) {
3033
// TODO: use mbstowcs once implemented
31-
efi_system_table->StdErr->OutputString(
32-
efi_system_table->StdErr, reinterpret_cast<const char16_t *>(msg.data()));
34+
for (size_t i = 0; i < msg.size(); i++) {
35+
char16_t e[2] = {msg[i], 0};
36+
efi_system_table->StdErr->OutputString(
37+
efi_system_table->StdErr, reinterpret_cast<const char16_t *>(&e));
38+
}
3339
}
3440

3541
} // namespace LIBC_NAMESPACE_DECL

libc/src/__support/UEFI/file.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ size_t File::write(const void *data, size_t data_len) {
4444
reset();
4545

4646
if (handle_type == FileHandleSimpleTextOutput) {
47-
handle.simple_text_output->OutputString(
48-
handle.simple_text_output, reinterpret_cast<const char16_t *>(data));
47+
for (size_t i = 0; i < data_len; i++) {
48+
char16_t e[2] = {((const char *)data)[i], 0};
49+
handle.simple_text_output->OutputString(
50+
handle.simple_text_output, reinterpret_cast<const char16_t *>(&e));
51+
}
4952
return data_len;
5053
}
5154
return 0;

0 commit comments

Comments
 (0)