[libc-commits] [libc] [libc][i386] setjmp/longjmp (PR #112437)
James Y Knight via libc-commits
libc-commits at lists.llvm.org
Tue Oct 15 15:29:43 PDT 2024
================
@@ -7,15 +7,34 @@
//===----------------------------------------------------------------------===//
#include "src/setjmp/longjmp.h"
+#include "include/llvm-libc-macros/offsetof-macro.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
-#if !defined(LIBC_TARGET_ARCH_IS_X86_64)
+#if !defined(LIBC_TARGET_ARCH_IS_X86)
#error "Invalid file include"
#endif
namespace LIBC_NAMESPACE_DECL {
+#ifdef __i386__
+[[noreturn]]
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
+ asm(R"(
----------------
jyknight wrote:
I believe this asm is wrong: the input values could be referring to the registers you're writing in the asm body. You can add explicit clobber constraints for ebx/esi/edi, but I don't think you can validly clobber ebp/esp, which I believe thus means you can't use an "m" constraint at all, because the address could be an offset to ebp/esp.
You can instead pass the field offsets via "i" constraints, and a specific register that holds buf.
(I know it was already discussed and decided against, but I do want to say that I still do think it'd be safer/clearer/simpler to just use raw asm for these functions -- because being careful to ensure that you're correctly following rules of inline-asm for functions which are explicitly about breaking the typical rules (...in a controlled manner...) is _hard_!)
https://github.com/llvm/llvm-project/pull/112437
More information about the libc-commits
mailing list