Skip to content

Commit 2706355

Browse files
[libc] Fix gnu::naked and return-type errors with gcc on aarch64
1 parent f0dcf32 commit 2706355

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

libc/src/setjmp/aarch64/longjmp.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ namespace LIBC_NAMESPACE_DECL {
2222
// supports the MTE instructions, not whether the compiler is configured to use
2323
// them.)
2424

25-
[[gnu::naked]] LLVM_LIBC_FUNCTION(void, longjmp,
26-
([[maybe_unused]] jmp_buf buf,
27-
[[maybe_unused]] int val)) {
25+
#ifndef __GNUC__
26+
[[gnu::naked]]
27+
#endif
28+
LLVM_LIBC_FUNCTION(void, longjmp,
29+
([[maybe_unused]] jmp_buf buf, [[maybe_unused]] int val)) {
2830
// If BTI branch protection is in use, the compiler will automatically insert
2931
// a BTI here, so we don't need to make any extra effort to do so.
3032

@@ -87,6 +89,11 @@ namespace LIBC_NAMESPACE_DECL {
8789
R"(
8890
ret
8991
)");
92+
93+
#ifdef __GNUC__
94+
// GCC fails here because it doesn't recognize a value is returned.
95+
__builtin_unreachable();
96+
#endif
9097
}
9198

9299
} // namespace LIBC_NAMESPACE_DECL

libc/src/setjmp/aarch64/setjmp.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
namespace LIBC_NAMESPACE_DECL {
1414

15-
[[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp, ([[maybe_unused]] jmp_buf buf)) {
15+
#ifndef __GNUC__
16+
[[gnu::naked]]
17+
#endif
18+
LLVM_LIBC_FUNCTION(int, setjmp, ([[maybe_unused]] jmp_buf buf)) {
1619
// If BTI branch protection is in use, the compiler will automatically insert
1720
// a BTI here, so we don't need to make any extra effort to do so.
1821

@@ -88,6 +91,11 @@ namespace LIBC_NAMESPACE_DECL {
8891
R"(
8992
ret
9093
)");
94+
95+
#ifdef __GNUC__
96+
// GCC fails here because it doesn't recognize a value is returned.
97+
__builtin_unreachable();
98+
#endif
9199
}
92100

93101
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)