Skip to content

Reland "[libc] fix aarch64 linux full build (#95358)" #95423

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

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,15 @@ function(add_libc_hermetic_test test_name)
LibcTest.hermetic
libc.test.UnitTest.ErrnoSetterMatcher
${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)
target_link_libraries(
${fq_build_target_name}
PRIVATE
libc.src.sys.auxv.getauxval
)
endif()

# Tests on the GPU require an external loader utility to launch the kernel.
if(TARGET libc.utils.gpu.loader)
Expand Down
7 changes: 7 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,12 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.pthread.pthread_mutexattr_setrobust
libc.src.pthread.pthread_mutexattr_settype
libc.src.pthread.pthread_once
libc.src.pthread.pthread_rwlockattr_destroy
libc.src.pthread.pthread_rwlockattr_getkind_np
libc.src.pthread.pthread_rwlockattr_getpshared
libc.src.pthread.pthread_rwlockattr_init
libc.src.pthread.pthread_rwlockattr_setkind_np
libc.src.pthread.pthread_rwlockattr_setpshared
libc.src.pthread.pthread_setspecific

# sched.h entrypoints
Expand Down Expand Up @@ -753,6 +759,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.unistd._exit
libc.src.unistd.environ
libc.src.unistd.execv
libc.src.unistd.fork
libc.src.unistd.getopt
libc.src.unistd.optarg
libc.src.unistd.optind
Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/threads/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ add_object_library(
.futex_utils
libc.config.linux.app_h
libc.include.sys_syscall
libc.include.fcntl
libc.src.errno.errno
libc.src.__support.CPP.atomic
libc.src.__support.CPP.stringstream
Expand Down
5 changes: 5 additions & 0 deletions libc/test/IntegrationTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
set(arch_specific_deps)
if(LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
set(arch_specific_deps libc.src.sys.auxv.getauxval)
endif()
add_object_library(
test
SRCS
Expand All @@ -8,4 +12,5 @@ add_object_library(
test.h
DEPENDS
libc.src.__support.OSUtil.osutil
${arch_specific_deps}
)
10 changes: 10 additions & 0 deletions libc/test/IntegrationTest/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/common.h"
#include "src/sys/auxv/getauxval.h"
#include <stddef.h>
#include <stdint.h>

Expand Down Expand Up @@ -79,4 +81,12 @@ void *realloc(void *ptr, size_t s) {
// Integration tests are linked with -nostdlib. BFD linker expects
// __dso_handle when -nostdlib is used.
void *__dso_handle = nullptr;

#ifdef LIBC_TARGET_ARCH_IS_AARCH64
// Due to historical reasons, libgcc on aarch64 may expect __getauxval to be
// defined. See also https://gcc.gnu.org/pipermail/gcc-cvs/2020-June/300635.html
unsigned long __getauxval(unsigned long id) {
return LIBC_NAMESPACE::getauxval(id);
}
#endif
} // extern "C"
2 changes: 1 addition & 1 deletion libc/test/UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function(add_unittest_framework_library name)
target_compile_options(${name}.hermetic PRIVATE ${compile_options})

if(TEST_LIB_DEPENDS)
foreach(dep IN LISTS ${TEST_LIB_DEPENDS})
foreach(dep IN ITEMS ${TEST_LIB_DEPENDS})
if(TARGET ${dep}.unit)
add_dependencies(${name}.unit ${dep}.unit)
else()
Expand Down
16 changes: 16 additions & 0 deletions libc/test/UnitTest/HermeticTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/common.h"
#include "src/sys/auxv/getauxval.h"
#include <stddef.h>
#include <stdint.h>

Expand All @@ -19,6 +21,12 @@ void *memmove(void *dst, const void *src, size_t count);
void *memset(void *ptr, int value, size_t count);
int atexit(void (*func)(void));

// TODO: It seems that some old test frameworks does not use
// add_libc_hermetic_test properly. Such that they won't get correct linkage
// against the object containing this function. We create a dummy function that
// always returns 0 to indicate a failure.
[[gnu::weak]] unsigned long getauxval(unsigned long id) { return 0; }

} // namespace LIBC_NAMESPACE

namespace {
Expand Down Expand Up @@ -102,6 +110,14 @@ void __cxa_pure_virtual() {
// __dso_handle when -nostdlib is used.
void *__dso_handle = nullptr;

#ifdef LIBC_TARGET_ARCH_IS_AARCH64
// Due to historical reasons, libgcc on aarch64 may expect __getauxval to be
// defined. See also https://gcc.gnu.org/pipermail/gcc-cvs/2020-June/300635.html
unsigned long __getauxval(unsigned long id) {
return LIBC_NAMESPACE::getauxval(id);
}
#endif

} // extern "C"

void *operator new(unsigned long size, void *ptr) { return ptr; }
Expand Down
Loading