Skip to content

Conversation

@RossComputerGuy
Copy link
Member

This fixes gnu::naked from being used on aarch64 which GCC does not support. It also uses the unreachable builtin so GCC stops failing with -Werror=return-type.

@llvmbot llvmbot added the libc label Dec 19, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2024

@llvm/pr-subscribers-libc

Author: Tristan Ross (RossComputerGuy)

Changes

This fixes gnu::naked from being used on aarch64 which GCC does not support. It also uses the unreachable builtin so GCC stops failing with -Werror=return-type.


Full diff: https://github.com/llvm/llvm-project/pull/120525.diff

2 Files Affected:

  • (modified) libc/src/setjmp/aarch64/longjmp.cpp (+10-3)
  • (modified) libc/src/setjmp/aarch64/setjmp.cpp (+9-1)
diff --git a/libc/src/setjmp/aarch64/longjmp.cpp b/libc/src/setjmp/aarch64/longjmp.cpp
index 80c97c721cc4f6..3adbd063a0d62b 100644
--- a/libc/src/setjmp/aarch64/longjmp.cpp
+++ b/libc/src/setjmp/aarch64/longjmp.cpp
@@ -22,9 +22,11 @@ namespace LIBC_NAMESPACE_DECL {
 // supports the MTE instructions, not whether the compiler is configured to use
 // them.)
 
-[[gnu::naked]] LLVM_LIBC_FUNCTION(void, longjmp,
-                                  ([[maybe_unused]] jmp_buf buf,
-                                   [[maybe_unused]] int val)) {
+#ifndef __GNUC__
+[[gnu::naked]]
+#endif
+LLVM_LIBC_FUNCTION(void, longjmp,
+                   ([[maybe_unused]] jmp_buf buf, [[maybe_unused]] int val)) {
   // If BTI branch protection is in use, the compiler will automatically insert
   // a BTI here, so we don't need to make any extra effort to do so.
 
@@ -87,6 +89,11 @@ namespace LIBC_NAMESPACE_DECL {
       R"(
         ret
       )");
+
+#ifdef __GNUC__
+  // GCC fails here because it doesn't recognize a value is returned.
+  __builtin_unreachable();
+#endif
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/setjmp/aarch64/setjmp.cpp b/libc/src/setjmp/aarch64/setjmp.cpp
index 8dd1eb342c0973..35f2b34e586ad9 100644
--- a/libc/src/setjmp/aarch64/setjmp.cpp
+++ b/libc/src/setjmp/aarch64/setjmp.cpp
@@ -12,7 +12,10 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-[[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp, ([[maybe_unused]] jmp_buf buf)) {
+#ifndef __GNUC__
+[[gnu::naked]]
+#endif
+LLVM_LIBC_FUNCTION(int, setjmp, ([[maybe_unused]] jmp_buf buf)) {
   // If BTI branch protection is in use, the compiler will automatically insert
   // a BTI here, so we don't need to make any extra effort to do so.
 
@@ -88,6 +91,11 @@ namespace LIBC_NAMESPACE_DECL {
       R"(
         ret
       )");
+
+#ifdef __GNUC__
+  // GCC fails here because it doesn't recognize a value is returned.
+  __builtin_unreachable();
+#endif
 }
 
 } // namespace LIBC_NAMESPACE_DECL

@RossComputerGuy
Copy link
Member Author

Turns out GCC is broken and this is bad.

@RossComputerGuy RossComputerGuy deleted the fix/libc-gnu-naked branch December 19, 2024 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants