Title: [294786] trunk/Source/_javascript_Core/llint/LowLevelInterpreter.cpp
Revision
294786
Author
[email protected]
Date
2022-05-24 20:30:54 -0700 (Tue, 24 May 2022)

Log Message

[Clang only] Make every LLInt asm global label an alt entry.
https://bugs.webkit.org/show_bug.cgi?id=240890

Reviewed by Yusuke Suzuki.

This is needed to keep Clang from moving these labels around.  For correctness, the AfterGate
labels rely on themselves not being move from where they are declared in source asm code.  We
should enforce this with the .alt_entry directive.

* Source/_javascript_Core/llint/LowLevelInterpreter.cpp:

Canonical link: https://commits.webkit.org/250945@main

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/llint/LowLevelInterpreter.cpp (294785 => 294786)


--- trunk/Source/_javascript_Core/llint/LowLevelInterpreter.cpp	2022-05-25 02:53:56 UTC (rev 294785)
+++ trunk/Source/_javascript_Core/llint/LowLevelInterpreter.cpp	2022-05-25 03:30:54 UTC (rev 294786)
@@ -478,8 +478,37 @@
 // Define the opcode dispatch mechanism when using an ASM loop:
 //
 
+#if COMPILER(CLANG)
+
+// We need an OFFLINE_ASM_BEGIN_SPACER because we'll be declaring every OFFLINE_ASM_GLOBAL_LABEL
+// as an alt entry. However, Clang will error out if the first global label is also an alt entry.
+// To work around this, we'll make OFFLINE_ASM_BEGIN emit an unused global label (which will now
+// be the first) that is not an alt entry, and insert a spacer instruction between it and the
+// actual first global label emitted by the offlineasm. Clang also requires that these 2 labels
+// not point to the same spot in memory; hence, the need for the spacer.
+//
+// For the spacer instruction, we'll choose a breakpoint instruction. However, we can
+// also just emit an unused piece of data. A breakpoint instruction is preferable.
+
+#if CPU(ARM_THUMB2)
+#define OFFLINE_ASM_BEGIN_SPACER "bkpt #0\n"
+#elif CPU(ARM64)
+#define OFFLINE_ASM_BEGIN_SPACER "brk #0xc471\n"
+#elif CPU(X86_64)
+#define OFFLINE_ASM_BEGIN_SPACER "int3\n"
+#else
+#define OFFLINE_ASM_BEGIN_SPACER ".int 0xbadbeef0\n"
+#endif
+
+#else
+#define OFFLINE_ASM_BEGIN_SPACER
+#endif // COMPILER(CLANG)
+
 // These are for building an interpreter from generated assembly code:
-#define OFFLINE_ASM_BEGIN   asm (
+#define OFFLINE_ASM_BEGIN   asm ( \
+    OFFLINE_ASM_GLOBAL_LABEL_IMPL(jsc_llint_begin, OFFLINE_ASM_NO_ALT_ENTRY_DIRECTIVE) \
+    OFFLINE_ASM_BEGIN_SPACER
+
 #define OFFLINE_ASM_END     );
 
 #if ENABLE(LLINT_EMBEDDED_OPCODE_ID)
@@ -497,10 +526,20 @@
     OFFLINE_ASM_OPCODE_DEBUG_LABEL(__opcode) \
     OFFLINE_ASM_LOCAL_LABEL(__opcode)
 
+#define OFFLINE_ASM_NO_ALT_ENTRY_DIRECTIVE(label)
+
+#if COMPILER(CLANG)
+#define OFFLINE_ASM_ALT_ENTRY_DIRECTIVE(label) \
+    ".alt_entry " SYMBOL_STRING(label) "\n"
+#else
+#define OFFLINE_ASM_ALT_ENTRY_DIRECTIVE(label)
+#endif
+
 #if CPU(ARM_THUMB2)
-#define OFFLINE_ASM_GLOBAL_LABEL(label)          \
+#define OFFLINE_ASM_GLOBAL_LABEL_IMPL(label, ALT_ENTRY) \
     ".text\n"                                    \
-    ".balign 4\n"                                 \
+    ".balign 4\n"                                \
+    ALT_ENTRY(label)                             \
     ".globl " SYMBOL_STRING(label) "\n"          \
     HIDE_SYMBOL(label) "\n"                      \
     ".thumb\n"                                   \
@@ -507,24 +546,27 @@
     ".thumb_func " THUMB_FUNC_PARAM(label) "\n"  \
     SYMBOL_STRING(label) ":\n"
 #elif CPU(ARM64)
-#define OFFLINE_ASM_GLOBAL_LABEL(label)         \
+#define OFFLINE_ASM_GLOBAL_LABEL_IMPL(label, ALT_ENTRY) \
     ".text\n"                                   \
-    ".balign 4\n"                                \
+    ".balign 4\n"                               \
+    ALT_ENTRY(label)                            \
     ".globl " SYMBOL_STRING(label) "\n"         \
     HIDE_SYMBOL(label) "\n"                     \
     SYMBOL_STRING(label) ":\n"
 #else
-#define OFFLINE_ASM_GLOBAL_LABEL(label)         \
+#define OFFLINE_ASM_GLOBAL_LABEL_IMPL(label, ALT_ENTRY) \
     ".text\n"                                   \
+    ALT_ENTRY(label)                            \
     ".globl " SYMBOL_STRING(label) "\n"         \
     HIDE_SYMBOL(label) "\n"                     \
     SYMBOL_STRING(label) ":\n"
 #endif
 
+#define OFFLINE_ASM_GLOBAL_LABEL(label) \
+    OFFLINE_ASM_GLOBAL_LABEL_IMPL(label, OFFLINE_ASM_ALT_ENTRY_DIRECTIVE)
+
 #if COMPILER(CLANG)
-#define OFFLINE_ASM_ALT_GLOBAL_LABEL(label) \
-    ".alt_entry " SYMBOL_STRING(label) "\n" \
-    OFFLINE_ASM_GLOBAL_LABEL(label)
+#define OFFLINE_ASM_ALT_GLOBAL_LABEL(label) OFFLINE_ASM_GLOBAL_LABEL(label)
 #else
 #define OFFLINE_ASM_ALT_GLOBAL_LABEL(label)
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to