Skip to content

Commit 6e36ed8

Browse files
[libc][setjmp] remove naked fn attr
Even though I just added it in 66f968c (and fixed up in 46200fc), while writing the i386 version, I found that simply using "m" constraints allowed for me to avoid offsetof and naked function attribute, while generating the same exact disassembly. Simplify x86_64 setjmp using this style.
1 parent 46200fc commit 6e36ed8

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

libc/src/setjmp/setjmp_impl.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@
1717

1818
namespace LIBC_NAMESPACE_DECL {
1919

20-
// TODO(https://github.com/llvm/llvm-project/issues/112427)
21-
// Some of the architecture-specific definitions are marked `naked`, which in
22-
// GCC implies `nothrow`.
23-
//
24-
// Right now, our aliases aren't marked `nothrow`, so we wind up in a situation
25-
// where clang will emit -Wmissing-exception-spec if we add `nothrow` here, but
26-
// GCC will emit -Wmissing-attributes here without `nothrow`. We need to update
27-
// LLVM_LIBC_FUNCTION to denote when a function throws or not.
28-
29-
#ifdef LIBC_COMPILER_IS_GCC
30-
[[gnu::nothrow]]
31-
#endif
3220
int setjmp(jmp_buf buf);
3321

3422
} // namespace LIBC_NAMESPACE_DECL

libc/src/setjmp/x86_64/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_entrypoint_object(
88
libc.hdr.types.jmp_buf
99
COMPILE_OPTIONS
1010
-O3
11+
-fomit-frame-pointer
1112
)
1213

1314
add_entrypoint_object(

libc/src/setjmp/x86_64/setjmp.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "include/llvm-libc-macros/offsetof-macro.h"
109
#include "src/__support/common.h"
1110
#include "src/__support/macros/config.h"
1211
#include "src/setjmp/setjmp_impl.h"
@@ -17,29 +16,31 @@
1716

1817
namespace LIBC_NAMESPACE_DECL {
1918

20-
[[gnu::naked]]
2119
LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
2220
asm(R"(
23-
mov %%rbx, %c[rbx](%%rdi)
24-
mov %%rbp, %c[rbp](%%rdi)
25-
mov %%r12, %c[r12](%%rdi)
26-
mov %%r13, %c[r13](%%rdi)
27-
mov %%r14, %c[r14](%%rdi)
28-
mov %%r15, %c[r15](%%rdi)
21+
mov %%rbx, %[rbx]
22+
mov %%rbp, %[rbp]
23+
mov %%r12, %[r12]
24+
mov %%r13, %[r13]
25+
mov %%r14, %[r14]
26+
mov %%r15, %[r15]
2927
3028
lea 8(%%rsp), %%rax
31-
mov %%rax, %c[rsp](%%rdi)
29+
mov %%rax, %[rsp]
3230
3331
mov (%%rsp), %%rax
34-
mov %%rax, %c[rip](%%rdi)
35-
36-
xorl %%eax, %%eax
37-
retq)" ::[rbx] "i"(offsetof(__jmp_buf, rbx)),
38-
[rbp] "i"(offsetof(__jmp_buf, rbp)), [r12] "i"(offsetof(__jmp_buf, r12)),
39-
[r13] "i"(offsetof(__jmp_buf, r13)), [r14] "i"(offsetof(__jmp_buf, r14)),
40-
[r15] "i"(offsetof(__jmp_buf, r15)), [rsp] "i"(offsetof(__jmp_buf, rsp)),
41-
[rip] "i"(offsetof(__jmp_buf, rip))
32+
mov %%rax, %[rip]
33+
)" ::
34+
[rbx] "m"(buf->rbx),
35+
[rbp] "m"(buf->rbp),
36+
[r12] "m"(buf->r12),
37+
[r13] "m"(buf->r13),
38+
[r14] "m"(buf->r14),
39+
[r15] "m"(buf->r15),
40+
[rsp] "m"(buf->rsp),
41+
[rip] "m"(buf->rip)
4242
: "rax");
43+
return 0;
4344
}
4445

4546
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)