-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc][setjmp][x86] implement setjmp in terms of out of line asm #88157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
a449c60
fa3e817
913e955
ea7f70c
327e64b
8d48548
9182f1c
221ef63
81a2396
e39c288
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //===-- Implementation of setjmp --------------------------------*- ASM -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #define paste(ns) _ZN22 ## ns ## 6setjmpEP9__jmp_buf | ||
| #define expand(x) paste(x) | ||
| #define LIBC_NAMESPACE_setjump expand(LIBC_NAMESPACE) | ||
| // aka _ZN22__llvm_libc_19_0_0_git6setjmpEP9__jmp_buf | ||
| // aka __llvm_libc_19_0_0_git::setjmp(__jmp_buf*) | ||
|
|
||
| // Brittle! Changing the layout of __jmp_buf will break this! | ||
|
||
| #define RBX_OFFSET 0 | ||
| #define RBP_OFFSET 8 | ||
| #define R12_OFFSET 16 | ||
| #define R13_OFFSET 24 | ||
| #define R14_OFFSET 32 | ||
| #define R15_OFFSET 40 | ||
| #define RSP_OFFSET 48 | ||
| #define RIP_OFFSET 56 | ||
|
|
||
| .global setjump | ||
nickdesaulniers marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .global LIBC_NAMESPACE_setjump | ||
|
|
||
| .type setjump, @function | ||
| .type LIBC_NAMESPACE_setjump, @function | ||
|
|
||
| setjump: | ||
|
||
| LIBC_NAMESPACE_setjump: | ||
|
|
||
| mov %rbx, RBX_OFFSET(%rdi) | ||
| mov %rbp, RBP_OFFSET(%rdi) | ||
| mov %r12, R12_OFFSET(%rdi) | ||
| mov %r13, R13_OFFSET(%rdi) | ||
| mov %r14, R14_OFFSET(%rdi) | ||
| mov %r15, R15_OFFSET(%rdi) | ||
| lea 8(%rsp), %rax | ||
| mov %rax, RSP_OFFSET(%rdi) | ||
| mov (%rsp), %rax | ||
| mov %rax, RIP_OFFSET(%rdi) | ||
| xor %eax, %eax | ||
| ret | ||
|
|
||
| .size setjump, . - setjump | ||
| .size LIBC_NAMESPACE_setjump, . - LIBC_NAMESPACE_setjump | ||
|
|
||
| .section .note.GNU-stack, "", @progbits | ||
nickdesaulniers marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| //===-- Unittests for setjmp ----------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "include/llvm-libc-macros/offsetof-macro.h" | ||
| #include "include/llvm-libc-types/jmp_buf.h" | ||
| #include "test/UnitTest/Test.h" | ||
|
|
||
| // If this test fails, then *_OFFSET macro definitions in | ||
| // libc/src/setjmp/x86_64/setjmp.S need to be fixed. This is a simple change | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. libc/src/setjmp/x86_64/setjmp.h is the updated source location |
||
| // detector. | ||
| TEST(LlvmLibcSetjmpTest, JmpBufLayout) { | ||
| #ifdef __x86_64__ | ||
| ASSERT_EQ(offsetof(__jmp_buf, rbx), 0UL); | ||
| ASSERT_EQ(offsetof(__jmp_buf, rbp), 8UL); | ||
| ASSERT_EQ(offsetof(__jmp_buf, r12), 16UL); | ||
| ASSERT_EQ(offsetof(__jmp_buf, r13), 24UL); | ||
| ASSERT_EQ(offsetof(__jmp_buf, r14), 32UL); | ||
| ASSERT_EQ(offsetof(__jmp_buf, r15), 40UL); | ||
| ASSERT_EQ(offsetof(__jmp_buf, rsp), 48UL); | ||
| ASSERT_EQ(offsetof(__jmp_buf, rip), 56UL); | ||
| ASSERT_EQ(sizeof(__jmp_buf), 64UL); | ||
| ASSERT_EQ(alignof(__jmp_buf), 8UL); | ||
| #endif // __x86_64__ | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest an extern C name which includes the expansion of LIBC_NAMESPACE in the name, rather than manual C++ name-mangling. If you want to do C++ name-mangling you'll need to figure out how to generate the "22" since that needs to be the length of the namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry I don't follow the suggestion. Can you please "break out the crayons" for me?