Skip to content

Commit 2efe3d7

Browse files
Reland "[libc] fix aarch64 linux full build (#95358)" (#95423)
Reverts #95419 and Reland #95358. This PR is full of temporal fixes. After a discussion with @lntue, it is better to avoid further changes to the cmake infrastructure for now as a rework to the cmake utilities will be landed in the future.
1 parent 43bd7ae commit 2efe3d7

File tree

7 files changed

+49
-1
lines changed

7 files changed

+49
-1
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,15 @@ function(add_libc_hermetic_test test_name)
686686
LibcTest.hermetic
687687
libc.test.UnitTest.ErrnoSetterMatcher
688688
${fq_deps_list})
689+
# TODO: currently the dependency chain is broken such that getauxval cannot properly
690+
# propagate to hermetic tests. This is a temporary workaround.
691+
if (LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
692+
target_link_libraries(
693+
${fq_build_target_name}
694+
PRIVATE
695+
libc.src.sys.auxv.getauxval
696+
)
697+
endif()
689698

690699
# Tests on the GPU require an external loader utility to launch the kernel.
691700
if(TARGET libc.utils.gpu.loader)

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,12 @@ if(LLVM_LIBC_FULL_BUILD)
644644
libc.src.pthread.pthread_mutexattr_setrobust
645645
libc.src.pthread.pthread_mutexattr_settype
646646
libc.src.pthread.pthread_once
647+
libc.src.pthread.pthread_rwlockattr_destroy
648+
libc.src.pthread.pthread_rwlockattr_getkind_np
649+
libc.src.pthread.pthread_rwlockattr_getpshared
650+
libc.src.pthread.pthread_rwlockattr_init
651+
libc.src.pthread.pthread_rwlockattr_setkind_np
652+
libc.src.pthread.pthread_rwlockattr_setpshared
647653
libc.src.pthread.pthread_setspecific
648654

649655
# sched.h entrypoints
@@ -754,6 +760,7 @@ if(LLVM_LIBC_FULL_BUILD)
754760
libc.src.unistd._exit
755761
libc.src.unistd.environ
756762
libc.src.unistd.execv
763+
libc.src.unistd.fork
757764
libc.src.unistd.getopt
758765
libc.src.unistd.optarg
759766
libc.src.unistd.optind

libc/src/__support/threads/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ add_object_library(
6464
.futex_utils
6565
libc.config.linux.app_h
6666
libc.include.sys_syscall
67+
libc.include.fcntl
6768
libc.src.errno.errno
6869
libc.src.__support.CPP.atomic
6970
libc.src.__support.CPP.stringstream

libc/test/IntegrationTest/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
set(arch_specific_deps)
2+
if(LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
3+
set(arch_specific_deps libc.src.sys.auxv.getauxval)
4+
endif()
15
add_object_library(
26
test
37
SRCS
@@ -8,4 +12,5 @@ add_object_library(
812
test.h
913
DEPENDS
1014
libc.src.__support.OSUtil.osutil
15+
${arch_specific_deps}
1116
)

libc/test/IntegrationTest/test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "src/__support/common.h"
10+
#include "src/sys/auxv/getauxval.h"
911
#include <stddef.h>
1012
#include <stdint.h>
1113

@@ -79,4 +81,12 @@ void *realloc(void *ptr, size_t s) {
7981
// Integration tests are linked with -nostdlib. BFD linker expects
8082
// __dso_handle when -nostdlib is used.
8183
void *__dso_handle = nullptr;
84+
85+
#ifdef LIBC_TARGET_ARCH_IS_AARCH64
86+
// Due to historical reasons, libgcc on aarch64 may expect __getauxval to be
87+
// defined. See also https://gcc.gnu.org/pipermail/gcc-cvs/2020-June/300635.html
88+
unsigned long __getauxval(unsigned long id) {
89+
return LIBC_NAMESPACE::getauxval(id);
90+
}
91+
#endif
8292
} // extern "C"

libc/test/UnitTest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function(add_unittest_framework_library name)
4141
target_compile_options(${name}.hermetic PRIVATE ${compile_options})
4242

4343
if(TEST_LIB_DEPENDS)
44-
foreach(dep IN LISTS ${TEST_LIB_DEPENDS})
44+
foreach(dep IN ITEMS ${TEST_LIB_DEPENDS})
4545
if(TARGET ${dep}.unit)
4646
add_dependencies(${name}.unit ${dep}.unit)
4747
else()

libc/test/UnitTest/HermeticTestUtils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "src/__support/common.h"
10+
#include "src/sys/auxv/getauxval.h"
911
#include <stddef.h>
1012
#include <stdint.h>
1113

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

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

2432
namespace {
@@ -102,6 +110,14 @@ void __cxa_pure_virtual() {
102110
// __dso_handle when -nostdlib is used.
103111
void *__dso_handle = nullptr;
104112

113+
#ifdef LIBC_TARGET_ARCH_IS_AARCH64
114+
// Due to historical reasons, libgcc on aarch64 may expect __getauxval to be
115+
// defined. See also https://gcc.gnu.org/pipermail/gcc-cvs/2020-June/300635.html
116+
unsigned long __getauxval(unsigned long id) {
117+
return LIBC_NAMESPACE::getauxval(id);
118+
}
119+
#endif
120+
105121
} // extern "C"
106122

107123
void *operator new(unsigned long size, void *ptr) { return ptr; }

0 commit comments

Comments
 (0)