From 104602234dd074936e992e446eb389f4925bc263 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net>
Date: Tue, 24 Sep 2024 22:55:13 -0400
Subject: [PATCH] Fix config test for va_copy() on darwin.

Because the appropriate header wasn't included, there was no
prototype.  Not having a prototype is an error in C99, which caused
the test to indicate that there was no va_copy() on darwin.

This in turn caused jsprf.cpp to try to copy a va_list using
assignment.

This is invalid, so the compiler would normally return an error.

Somwhere in here, that error became a clang crash (not trivially
reproducable).

At the end of the day, ancient broken tests in config caused the
darwin Spidermonkey builds to fail.  The new patch fixes up the
configure tests, and darwin Synchronet builds are re-enabled.
---
 .gitlab-ci.yml                      |  1 -
 3rdp/build/GNUmakefile              |  3 +-
 3rdp/build/js-include-headers.patch | 95 +++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 2 deletions(-)
 create mode 100644 3rdp/build/js-include-headers.patch

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a966eb0bd3..69705b2782 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -72,7 +72,6 @@ include:
       platform: 'x86'
       tagname: 'macOS'
       gnu_make: 'make'
-      no_javascript: 'yes'
       build_flags: 'CC="ccache cc" CXX="ccache c++" RELEASE=1'
 
 smoketest-jsexec-linux:
diff --git a/3rdp/build/GNUmakefile b/3rdp/build/GNUmakefile
index 67a7324547..36cd3a81df 100644
--- a/3rdp/build/GNUmakefile
+++ b/3rdp/build/GNUmakefile
@@ -66,7 +66,7 @@ $(JS_SRC): | $(3RDPSRCDIR)
 $(JS_IDIR): | $(3RDPODIR)
 	$(QUIET)$(IFNOTEXIST) mkdir $(JS_IDIR)
 
-$(JSLIB_BUILD): $(3RDP_ROOT)/dist/libmozjs.tgz $(3RDP_ROOT)/build/js_src_jsnativestack_cpp.patch $(3RDP_ROOT)/build/js-configure.patch $(3RDP_ROOT)/build/js-configure.in.patch $(3RDP_ROOT)/build/imacro-asm-fix.patch $(3RDP_ROOT)/build/js-volatile-outside-functions.patch $(3RDP_ROOT)/build/js-Wno-misleading-indentation.patch $(3RDP_ROOT)/build/js-allow-python3.patch $(3RDP_ROOT)/build/js-no-rwx-pages.patch $(3RDP_ROOT)/build/js-disable-shell.patch $(3RDP_ROOT)/build/js-darwin-configure.patch $(3RDP_ROOT)/build/js-keep-ffi-cache.patch $(3RDP_ROOT)/build/js-config.guess-libffi.patch $(3RDP_ROOT)/build/js-support-mingw-cross.patch $(3RDP_ROOT)/build/js-int-main-conf.patch | $(JS_SRC) $(JS_IDIR)
+$(JSLIB_BUILD): $(3RDP_ROOT)/dist/libmozjs.tgz $(3RDP_ROOT)/build/js_src_jsnativestack_cpp.patch $(3RDP_ROOT)/build/js-configure.patch $(3RDP_ROOT)/build/js-configure.in.patch $(3RDP_ROOT)/build/imacro-asm-fix.patch $(3RDP_ROOT)/build/js-volatile-outside-functions.patch $(3RDP_ROOT)/build/js-Wno-misleading-indentation.patch $(3RDP_ROOT)/build/js-allow-python3.patch $(3RDP_ROOT)/build/js-no-rwx-pages.patch $(3RDP_ROOT)/build/js-disable-shell.patch $(3RDP_ROOT)/build/js-darwin-configure.patch $(3RDP_ROOT)/build/js-keep-ffi-cache.patch $(3RDP_ROOT)/build/js-config.guess-libffi.patch $(3RDP_ROOT)/build/js-support-mingw-cross.patch $(3RDP_ROOT)/build/js-int-main-conf.patch $(3RDP_ROOT)/build/js-include-headers.patch | $(JS_SRC) $(JS_IDIR)
 	@echo Creating $@ ...
 	$(QUIET)-rm -rf $(JS_SRC)/*
 	$(QUIET)tar -xzpC $(JS_SRC) -f $(3RDPDISTDIR)/libmozjs.tgz
@@ -88,6 +88,7 @@ $(JSLIB_BUILD): $(3RDP_ROOT)/dist/libmozjs.tgz $(3RDP_ROOT)/build/js_src_jsnativ
 	$(QUIET)patch -b -p0 -d $(JS_SRC) < js-config.guess-libffi.patch
 	$(QUIET)patch -b -p0 -d $(JS_SRC) < js-support-mingw-cross.patch
 	$(QUIET)patch -b -p0 -d $(JS_SRC) < js-int-main-conf.patch
+	$(QUIET)patch -b -p0 -d $(JS_SRC) < js-include-headers.patch
 	-$(QUIET)cd $(JS_SRC)/js-1.8.5/js/src && autoconf-2.13
 	-$(QUIET)cd $(JS_SRC)/js-1.8.5/js/src && autoconf2.13
 	$(QUIET)chmod 0755 $(JS_SRC)/js-1.8.5/js/src/build/hcc
diff --git a/3rdp/build/js-include-headers.patch b/3rdp/build/js-include-headers.patch
new file mode 100644
index 0000000000..f2446e7282
--- /dev/null
+++ b/3rdp/build/js-include-headers.patch
@@ -0,0 +1,95 @@
+diff -u js-1.8.5/js/src/configure.in.orig js-1.8.5/js/src/configure.in
+--- js-1.8.5/js/src/configure.in.orig	2024-09-24 22:14:12
++++ js-1.8.5/js/src/configure.in	2024-09-24 22:17:58
+@@ -3939,6 +3939,7 @@
+ AC_CACHE_VAL(ac_cv_va_copy,[
+     AC_TRY_RUN([
+         #include <stdarg.h>
++        #include <stdlib.h>
+         void f (int i, ...) {
+             va_list args1, args2;
+             va_start (args1, i);
+@@ -3958,6 +3959,7 @@
+ AC_CACHE_VAL(ac_cv___va_copy,[
+     AC_TRY_RUN([
+         #include <stdarg.h>
++        #include <stdlib.h>
+         void f (int i, ...) {
+             va_list args1, args2;
+             va_start (args1, i);
+@@ -3977,6 +3979,7 @@
+ AC_CACHE_VAL(ac_cv_va_val_copy,[
+     AC_TRY_RUN([
+         #include <stdarg.h>
++        #include <stdlib.h>
+         void f (int i, ...) {
+             va_list args1, args2;
+             va_start (args1, i);
+@@ -5271,6 +5274,7 @@
+ AC_MSG_CHECKING([for gcc -pipe support])
+ if test -n "$GNU_CC" -a -n "$GNU_CXX" -a -n "$GNU_AS"; then
+     echo '#include <stdio.h>' > dummy-hello.c
++    echo '#include <stdlib.h>' >> dummy-hello.c
+     echo 'int main() { printf("Hello World\n"); exit(0); }' >> dummy-hello.c
+     ${CC} -S dummy-hello.c -o dummy-hello.s 2>&5
+     cat dummy-hello.s 2> /dev/null | ${AS_BIN} -o dummy-hello.S - 2>&5
+diff -u js-1.8.5/js/src/configure.orig js-1.8.5/js/src/configure
+--- js-1.8.5/js/src/configure.orig	2024-09-24 22:33:47.275117000 -0400
++++ js-1.8.5/js/src/configure	2024-09-24 22:39:16.459457000 -0400
+@@ -8194,6 +8194,7 @@
+ #line 8195 "configure"
+ #include "confdefs.h"
+ #include <ctype.h>
++#include <stdlib.h>
+ #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+ #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+ #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+@@ -11045,6 +11046,8 @@
+ else
+   cat > conftest.$ac_ext <<EOF
+ #line 11048 "configure"
++#include <stdlib.h>
++#include <string.h>
+ #include "confdefs.h"
+ 
+ int main()
+@@ -11638,6 +11641,7 @@
+ #include "confdefs.h"
+ 
+         #include <stdarg.h>
++        #include <stdlib.h>
+         void f (int i, ...) {
+             va_list args1, args2;
+             va_start (args1, i);
+@@ -11679,6 +11683,7 @@
+ #include "confdefs.h"
+ 
+         #include <stdarg.h>
++        #include <stdlib.h>
+         void f (int i, ...) {
+             va_list args1, args2;
+             va_start (args1, i);
+@@ -11720,6 +11725,7 @@
+ #include "confdefs.h"
+ 
+         #include <stdarg.h>
++        #include <stdlib.h>
+         void f (int i, ...) {
+             va_list args1, args2;
+             va_start (args1, i);
+@@ -13592,6 +13598,7 @@
+ #line 13593 "configure"
+ #include "confdefs.h"
+ #include <stdio.h>
++#include <stdlib.h>
+ int main()
+ {
+   FILE *f=fopen("conftestval", "w");
+@@ -14351,6 +14358,7 @@
+ echo "configure:14352: checking for gcc -pipe support" >&5
+ if test -n "$GNU_CC" -a -n "$GNU_CXX" -a -n "$GNU_AS"; then
+     echo '#include <stdio.h>' > dummy-hello.c
++    echo '#include <stdlib.h>' >> dummy-hello.c
+     echo 'int main() { printf("Hello World\n"); exit(0); }' >> dummy-hello.c
+     ${CC} -S dummy-hello.c -o dummy-hello.s 2>&5
+     cat dummy-hello.s 2> /dev/null | ${AS_BIN} -o dummy-hello.S - 2>&5
-- 
GitLab