[libc-commits] [libc] [libc] Fix gnu::naked and return-type errors with gcc on aarch64 (PR #120525)
via libc-commits
libc-commits at lists.llvm.org
Wed Dec 18 22:07:51 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Tristan Ross (RossComputerGuy)
<details>
<summary>Changes</summary>
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/120525
More information about the libc-commits
mailing list