[JavaScriptCore] os_script_config_storage is not available when back-deploying
https://bugs.webkit.org/show_bug.cgi?id=303933
rdar://166241210

Unreviewed, reland of 304386@main with an AllowedSPI cleanup:

    Reviewed by Mark Lam.

    Fix two issues related to back-deploying from recent SDKs to Sonoma and
    Sequoia downlevels:

    1. We were using the presence of a macro in <os/script_config_private.h>
       to determine whether to compile with os_script_config_storage runtime
       support. When back deploying, that macro may exist even when the
       system being targeted does not have runtime support.

       Replace the HAVE_OS_SCRIPT_CONFIG_SPI check with one from
       WebKitAdditions based on deployment target version.

    2. When we are in the fallback configuration where we allocate our own
       buffer, JSC was redeclaring a `os_script_config_storage` using the
       same name as the declaration from the system header. This confused
       the compiler into thinking that we are attempting to use a
       declaration from the SDK that is marked unavailable.

       Work around this by giving the declaration a different name
       (os_script_config_storage_stub) and manually renaming its symbol so
       that LLInt can still bind to it.

    Also, do not export the stub symbol; it's only used within JSC.

Because the stub symbol is no longer exported, and because libSystem is
implicitly treated as API, audit-spi now flags the
os_script_config_storage entry, so remove it.

* Source/JavaScriptCore/Configurations/AllowedSPI.toml:
* Source/JavaScriptCore/llint/LLIntData.h:

Canonical link: https://commits.webkit.org/304431@main
diff --git a/Source/JavaScriptCore/Configurations/AllowedSPI.toml b/Source/JavaScriptCore/Configurations/AllowedSPI.toml
index 90dc3f9..e542b78 100644
--- a/Source/JavaScriptCore/Configurations/AllowedSPI.toml
+++ b/Source/JavaScriptCore/Configurations/AllowedSPI.toml
@@ -5,9 +5,3 @@
 request = "rdar://157890653"
 symbols = ["dyld_program_sdk_at_least"]
 requires = ["USE_APPLE_INTERNAL_SDK"]
-
-[[not-web-essential]]
-request = "rdar://163506174"
-symbols = ["os_script_config_storage"]
-requires = ["HAVE_OS_SCRIPT_CONFIG_SPI"]
-allow-unused = true
diff --git a/Source/JavaScriptCore/llint/LLIntData.h b/Source/JavaScriptCore/llint/LLIntData.h
index a234597..e6884e7 100644
--- a/Source/JavaScriptCore/llint/LLIntData.h
+++ b/Source/JavaScriptCore/llint/LLIntData.h
@@ -43,10 +43,6 @@
 
 class VM;
 
-#if USE(APPLE_INTERNAL_SDK) && defined(OS_SCRIPT_CONFIG_SPI_VERSION) && !PLATFORM(IOS_FAMILY_SIMULATOR)
-#define HAVE_OS_SCRIPT_CONFIG_SPI 1
-#endif
-
 #if ENABLE(C_LOOP)
 typedef OpcodeID LLIntCode;
 #else
@@ -71,8 +67,15 @@
 
 #if HAVE(OS_SCRIPT_CONFIG_SPI)
 static_assert(OS_SCRIPT_CONFIG_STORAGE_SIZE == OpcodeConfigSizeToProtect);
+#elif PLATFORM(COCOA)
+// When targeting older versions of macOS that do not have
+// os_script_config_storage runtime support, this redeclaration clashes with
+// the declaration in the SDK that is marked as unavailable. Use a different
+// name to work around the availability diagnostic.
+extern "C" uint8_t os_script_config_storage_stub[] __asm__("_os_script_config_storage");
+#define os_script_config_storage os_script_config_storage_stub
 #else
-extern "C" WTF_EXPORT_PRIVATE uint8_t os_script_config_storage[];
+extern "C" uint8_t os_script_config_storage[];
 #endif
 
 WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN