https://github.com/googlewalt created 
https://github.com/llvm/llvm-project/pull/235756

Commit fd4113508a64 ("[libunwind] Support extended amd64 segment registers", 
#229176) made libunwind/src/assembly.h include <sys/syscall.h> on x86_64 Linux 
to get SYS_arch_prctl. On Android (Bionic, NDK r29), that header includes 
<sys/cdefs.h> -> <android/api-level.h> -> 
<bits/get_device_api_level_inlines.h>, which contain C declarations guarded 
only by __ASSEMBLY__ (not defined for .S files). As a result, 
UnwindRegistersSave.S and UnwindRegistersRestore.S fail to assemble for x86_64 
Android.

On Linux, use the assembler-safe kernel UAPI header <asm/unistd.h> and 
__NR_arch_prctl alongside the existing <asm/prctl.h>. FreeBSD continues to use 
<sys/syscall.h>.

Fixes fd4113508a64.

Assisted-by: Gemini

>From 3640b2682549f7ed73ddb0db53403eeb36dc88e4 Mon Sep 17 00:00:00 2001
From: Walter Lee <[email protected]>
Date: Mon, 26 Oct 2026 08:40:18 -0400
Subject: [PATCH] [libunwind] Don't include <sys/syscall.h> from assembly on
 Linux

Commit fd4113508a64 ("[libunwind] Support extended amd64 segment
registers", #229176) made libunwind/src/assembly.h include
<sys/syscall.h> on x86_64 Linux to get SYS_arch_prctl. On Android
(Bionic, NDK r29), that header includes <sys/cdefs.h> ->
<android/api-level.h> -> <bits/get_device_api_level_inlines.h>, which
contain C declarations guarded only by __ASSEMBLY__ (not defined for .S
files). As a result, UnwindRegistersSave.S and UnwindRegistersRestore.S
fail to assemble for x86_64 Android.

On Linux, use the assembler-safe kernel UAPI header <asm/unistd.h> and
__NR_arch_prctl alongside the existing <asm/prctl.h>. FreeBSD continues
to use <sys/syscall.h>.

Fixes fd4113508a64.

Assisted-by: Gemini
---
 libunwind/src/assembly.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h
index a36d2669eaa500..cb6a06c53ac19f 100644
--- a/libunwind/src/assembly.h
+++ b/libunwind/src/assembly.h
@@ -17,15 +17,19 @@
 
 #if defined(__x86_64__) && !defined(_LIBUNWIND_IS_BAREMETAL) &&                
\
     (defined(__linux__) || defined(__FreeBSD__))
-#include <sys/syscall.h>
 #if defined(__linux__)
+// Use the kernel UAPI headers, which are safe to include from assembly. The
+// libc <sys/syscall.h> is not: on Android it pulls in <sys/cdefs.h> and
+// <android/api-level.h>, which contain C declarations.
 #include <asm/prctl.h>
+#include <asm/unistd.h>
 #define X86_64_GET_FSBASE ARCH_GET_FS
 #define X86_64_GET_GSBASE ARCH_GET_GS
 #define X86_64_SET_FSBASE ARCH_SET_FS
 #define X86_64_SET_GSBASE ARCH_SET_GS
-#define X86_64_BASE_SYSCALL SYS_arch_prctl
+#define X86_64_BASE_SYSCALL __NR_arch_prctl
 #else
+#include <sys/syscall.h>
 // <machine/sysarch.h> contains C declarations and cannot be included here.
 #define X86_64_GET_FSBASE 128 // AMD64_GET_FSBASE
 #define X86_64_GET_GSBASE 130 // AMD64_GET_GSBASE

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to