[libc] [libunwind] [WIP] Enough to get `libc` to build `clang` on `aarch64` (PR #97231)

Izaak Schroeder via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 30 16:17:38 PDT 2024


https://github.com/izaakschroeder updated https://github.com/llvm/llvm-project/pull/97231

>From 31dc769c1866a4a0100dde0a3743c215a9a5f5eb Mon Sep 17 00:00:00 2001
From: Izaak Schroeder <izaak.schroeder at gmail.com>
Date: Sun, 30 Jun 2024 13:33:16 -0700
Subject: [PATCH 1/5] [libc]: add missing aarch64 headers

---
 libc/config/linux/aarch64/entrypoints.txt | 3 +++
 libc/config/linux/aarch64/headers.txt     | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 8a26536cea9a0..b59400db81fed 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -308,6 +308,9 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.unistd.unlink
     libc.src.unistd.unlinkat
     libc.src.unistd.write
+
+    # XXX
+    libc.src.assert.__assert_fail
 )
 
 set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 7d25877cefcc8..ed126d6128871 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -31,4 +31,10 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.sys_ioctl
     # Disabled due to epoll_wait syscalls not being available on this platform.
     # libc.include.sys_epoll
+
+    # XXX
+    libc.include.sys_auxv
+    libc.include.fcntl
+    libc.include.sched
+    libc.include.sys_stat
 )

>From a5f8ee220c088a39d9b4bf60986166e83ffafffa Mon Sep 17 00:00:00 2001
From: Izaak Schroeder <izaak.schroeder at gmail.com>
Date: Sun, 30 Jun 2024 13:33:38 -0700
Subject: [PATCH 2/5] [libunwind]: remove needless `sys/uio.h`

No reference to `readv` or `writev`.
---
 libunwind/src/UnwindCursor.hpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 66fe8e2a32cca..677e842d8a22b 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -36,7 +36,6 @@
 #include <errno.h>
 #include <signal.h>
 #include <sys/syscall.h>
-#include <sys/uio.h>
 #include <unistd.h>
 #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1
 #endif

>From 1083aecfe1be3c1cf427d4ffd2b4fad3d5129d4c Mon Sep 17 00:00:00 2001
From: Izaak Schroeder <izaak.schroeder at gmail.com>
Date: Sun, 30 Jun 2024 13:44:52 -0700
Subject: [PATCH 3/5] [libc]: function spec for `getauxval`

---
 libc/spec/gnu_ext.td | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libc/spec/gnu_ext.td b/libc/spec/gnu_ext.td
index 161bb4e4a0d9d..e360c766c5c54 100644
--- a/libc/spec/gnu_ext.td
+++ b/libc/spec/gnu_ext.td
@@ -237,7 +237,11 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
       [], // Types
       [], // Enumerations
       [
-        //TODO: Add getauxval here
+          FunctionSpec<
+              "getauxval",
+              RetValSpec<UnsignedLongType>,
+              [ArgSpec<UnsignedLongType>]
+          >,
       ]  // Functions
   >;
 

>From e9628ce037c225c3769cec2589745f7978e7edc4 Mon Sep 17 00:00:00 2001
From: Izaak Schroeder <izaak.schroeder at gmail.com>
Date: Sun, 30 Jun 2024 14:06:19 -0700
Subject: [PATCH 4/5] [libc]: hack `ExitCallbackList` always public

---
 libc/src/stdlib/exit_handler.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libc/src/stdlib/exit_handler.h b/libc/src/stdlib/exit_handler.h
index 8494c2f2e526e..db731a46f44c9 100644
--- a/libc/src/stdlib/exit_handler.h
+++ b/libc/src/stdlib/exit_handler.h
@@ -31,10 +31,8 @@ struct AtExitUnit {
 
 #if defined(LIBC_TARGET_ARCH_IS_GPU)
 using ExitCallbackList = FixedVector<AtExitUnit, 64>;
-#elif defined(LIBC_COPT_PUBLIC_PACKAGING)
-using ExitCallbackList = ReverseOrderBlockStore<AtExitUnit, 32>;
 #else
-using ExitCallbackList = FixedVector<AtExitUnit, CALLBACK_LIST_SIZE_FOR_TESTS>;
+using ExitCallbackList = ReverseOrderBlockStore<AtExitUnit, 32>;
 #endif
 
 extern ExitCallbackList atexit_callbacks;

>From e3ed9aac99ede8be5d6d228f43c652423206e67c Mon Sep 17 00:00:00 2001
From: Izaak Schroeder <izaak.schroeder at gmail.com>
Date: Sun, 30 Jun 2024 14:15:21 -0700
Subject: [PATCH 5/5] [libc]: add `Scrt1.o`

---
 libc/startup/linux/CMakeLists.txt | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libc/startup/linux/CMakeLists.txt b/libc/startup/linux/CMakeLists.txt
index 336c5d0f6bfa2..b721d15091227 100644
--- a/libc/startup/linux/CMakeLists.txt
+++ b/libc/startup/linux/CMakeLists.txt
@@ -118,6 +118,15 @@ merge_relocatable_object(
   .do_start
 )
 
+# HACK: Is this even ok?
+# For reference: `Scrt1` is used when `-fpie` vs `crt1` for `-fno-pie`
+merge_relocatable_object(
+  Scrt1
+  .${LIBC_TARGET_ARCHITECTURE}.start
+  .${LIBC_TARGET_ARCHITECTURE}.tls
+  .do_start
+)
+
 add_startup_object(
   crti
   SRC
@@ -131,7 +140,7 @@ add_startup_object(
 )
 
 add_custom_target(libc-startup)
-set(startup_components crt1 crti crtn)
+set(startup_components Scrt1 crt1 crti crtn)
 foreach(target IN LISTS startup_components)
   set(fq_target_name libc.startup.linux.${target})
   add_dependencies(libc-startup ${fq_target_name})



More information about the cfe-commits mailing list