https://bugs.kde.org/show_bug.cgi?id=369723

            Bug ID: 369723
           Summary: __builtin_longjmp not supported in clang/llvm on
                    Android arm64 target
           Product: valgrind
           Version: 3.11.0
          Platform: Android
                OS: other
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: general
          Assignee: jsew...@acm.org
          Reporter: c...@google.com

Valgrind failed to build on Android for the arm64 target because llvm does not
have __builtin_longjmp like gcc. The following are the error messages.

external/valgrind/coregrind/m_signals.c:2013:7: warning: incompatible pointer
types passing 'jmp_buf' (aka 'long [32]') to parameter of type 'void **'
[-Wincompatible-pointer-types]
      VG_MINIMAL_LONGJMP(tst->sched_jmpbuf);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/valgrind/include/pub_tool_libcsetjmp.h:126:53: note: expanded from
macro 'VG_MINIMAL_LONGJMP'
#define VG_MINIMAL_LONGJMP(_env)  __builtin_longjmp((_env),1)
                                                    ^~~~~~
external/valgrind/coregrind/m_signals.c:2013:7: error: __builtin_longjmp is not
supported for the current target
      VG_MINIMAL_LONGJMP(tst->sched_jmpbuf);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/valgrind/include/pub_tool_libcsetjmp.h:135:35: note: expanded from
macro 'VG_MINIMAL_LONGJMP'
#define VG_MINIMAL_LONGJMP(_env)  __builtin_longjmp((_env),1)
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~



Suggested fix, to add VG_MINIMAL_SETJMP and VG_MINIMAL_LONGJMP for
VGP_arm64_linux:


diff --git a/coregrind/m_libcsetjmp.c b/coregrind/m_libcsetjmp.c
index 81a1a53..fe17819 100644
--- a/coregrind/m_libcsetjmp.c
+++ b/coregrind/m_libcsetjmp.c
@@ -36,11 +36,50 @@

 /* See include/pub_tool_libcsetjmp.h for background and rationale. */

-/* The alternative implementations are for ppc{32,64}-linux and
+/* The alternative implementations are for arm64-linux, ppc{32,64}-linux, and
    {amd64,x86}-{linux,darwin}.  See #259977.  That leaves only
    {arm,s390x}-linux using the gcc builtins now.
 */

+/* ------------ arm64-linux ------------ */
+
+#if defined(VGP_arm64_linux)
+
+__asm__(
+"    .text"                                 "\n"
+"    .align  2"                             "\n"
+"    .global VG_MINIMAL_SETJMP"             "\n"
+"    .type   VG_MINIMAL_SETJMP, @function"  "\n"
+"VG_MINIMAL_SETJMP:"                        "\n"
+".L_BEGIN_SETJMP:"                          "\n"
+"    mov x1, x0"                            "\n"
+"    adrp x3, .L_BEGIN_SETJMP"              "\n"
+"    mov x0, sp"                            "\n"
+"    mov x2, sp"                            "\n"
+"    add x4, x3, :lo12:.L_BEGIN_SETJMP"     "\n"
+"    str x0, [x1,16]"                       "\n"
+"    mov x0, 0"                             "\n"
+"    str x2, [x1]"                          "\n"
+"    str x4, [x1,8]"                        "\n"
+"    ret"                                   "\n"
+"\n"
+"    .text"                                 "\n"
+"    .align 2"                              "\n"
+"    .global VG_MINIMAL_LONGJMP"            "\n"
+"    .type VG_MINIMAL_LONGJMP, @function"   "\n"
+"VG_MINIMAL_LONGJMP:"                       "\n"
+"    stp x29, x30, [sp, -16]!"              "\n"
+"    mov x29, sp"                           "\n"
+"    ldr x1, [x0,8]"                        "\n"
+"    ldr x29, [x0]"                         "\n"
+"    ldr x0, [x0,16]"                       "\n"
+"    mov sp, x0"                            "\n"
+"    br x1"                                 "\n"
+);
+
+#endif /* VGP_arm64_linux */
+
+
 /* ------------ ppc32-linux ------------ */

 #if defined(VGP_ppc32_linux)
diff --git a/include/pub_tool_libcsetjmp.h b/include/pub_tool_libcsetjmp.h
index bb94a59..9045010 100644
--- a/include/pub_tool_libcsetjmp.h
+++ b/include/pub_tool_libcsetjmp.h
@@ -118,6 +118,15 @@ UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
 __attribute__((noreturn))
 void  VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));

+#elif defined(ANDROID) && defined(__clang__) && defined(__aarch64__)
+
+/* Android clang/llvm has no __builtin_{setjmp,longjmp} for aarch64. */
+#define VG_MINIMAL_JMP_BUF(_name) jmp_buf _name
+__attribute__((returns_twice))
+UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
+__attribute__((noreturn))
+void  VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));
+
 #else

 /* The default implementation. */



Reproducible: Always

Steps to Reproduce:
With Android source, make external/valgrind with clang/llvm.


Actual Results:  
Compilation error from source files that use setjmp/longjmp.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to