[libc-commits] [libc] Reland "[libc] fix aarch64 linux full build (#95358)" (PR #95423)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Thu Jun 13 20:22:35 PDT 2024
https://github.com/SchrodingerZhu updated https://github.com/llvm/llvm-project/pull/95423
>From 91323a6ea8f32a9fe2cec7051e8a99b87157133e Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifzhu at nvidia.com>
Date: Thu, 13 Jun 2024 08:38:05 -0700
Subject: [PATCH 1/2] Revert "Revert "[libc] fix aarch64 linux full build
(#95358)" (#95419)"
This reverts commit 9e5428e6b02c77fb18c4bdf688a216c957fd7a53.
---
libc/config/linux/aarch64/entrypoints.txt | 7 +++++++
libc/src/__support/threads/linux/CMakeLists.txt | 1 +
libc/test/IntegrationTest/test.cpp | 6 ++++++
3 files changed, 14 insertions(+)
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index db96a80051a8d..7ce088689b925 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -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
@@ -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
diff --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt
index 9bf88ccc84557..8e6cd7227b2c8 100644
--- a/libc/src/__support/threads/linux/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/CMakeLists.txt
@@ -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
diff --git a/libc/test/IntegrationTest/test.cpp b/libc/test/IntegrationTest/test.cpp
index 3bdbe89a3fb62..27e7f29efa0f1 100644
--- a/libc/test/IntegrationTest/test.cpp
+++ b/libc/test/IntegrationTest/test.cpp
@@ -79,4 +79,10 @@ 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;
+
+// On some platform (aarch64 fedora tested) full build integration test
+// objects need to link against libgcc, which may expect a __getauxval
+// function. For now, it is fine to provide a weak definition that always
+// returns false.
+[[gnu::weak]] bool __getauxval(uint64_t, uint64_t *) { return false; }
} // extern "C"
>From 4076c3004f09e95d1fcd299452843f99235ff422 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <i at zhuyi.fan>
Date: Thu, 13 Jun 2024 20:22:21 -0700
Subject: [PATCH 2/2] [libc] more fix
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 9 +++++++++
libc/test/IntegrationTest/CMakeLists.txt | 5 +++++
libc/test/IntegrationTest/test.cpp | 14 +++++++++-----
libc/test/UnitTest/CMakeLists.txt | 2 +-
libc/test/UnitTest/HermeticTestUtils.cpp | 16 ++++++++++++++++
5 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index eb6be91b55e26..c8d7c8a2b1c7c 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -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)
diff --git a/libc/test/IntegrationTest/CMakeLists.txt b/libc/test/IntegrationTest/CMakeLists.txt
index 4f31f10b29f0b..4a999407d48d7 100644
--- a/libc/test/IntegrationTest/CMakeLists.txt
+++ b/libc/test/IntegrationTest/CMakeLists.txt
@@ -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
@@ -8,4 +12,5 @@ add_object_library(
test.h
DEPENDS
libc.src.__support.OSUtil.osutil
+ ${arch_specific_deps}
)
diff --git a/libc/test/IntegrationTest/test.cpp b/libc/test/IntegrationTest/test.cpp
index 27e7f29efa0f1..a8b2f2911fd8e 100644
--- a/libc/test/IntegrationTest/test.cpp
+++ b/libc/test/IntegrationTest/test.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#include "src/__support/common.h"
+#include "src/sys/auxv/getauxval.h"
#include <stddef.h>
#include <stdint.h>
@@ -80,9 +82,11 @@ void *realloc(void *ptr, size_t s) {
// __dso_handle when -nostdlib is used.
void *__dso_handle = nullptr;
-// On some platform (aarch64 fedora tested) full build integration test
-// objects need to link against libgcc, which may expect a __getauxval
-// function. For now, it is fine to provide a weak definition that always
-// returns false.
-[[gnu::weak]] bool __getauxval(uint64_t, uint64_t *) { return false; }
+#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"
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 302af3044ca3d..4adc2f5c725f7 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -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()
diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 349c182ff2379..6e815e6c8aab0 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#include "src/__support/common.h"
+#include "src/sys/auxv/getauxval.h"
#include <stddef.h>
#include <stdint.h>
@@ -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 {
@@ -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; }
More information about the libc-commits
mailing list