Blame SOURCES/enddianness.patch

e43f4b
From f66d410f3ba767efb91c6b9545d373267cd975f2 Mon Sep 17 00:00:00 2001
e43f4b
From: rpm-build <rpm-build>
e43f4b
Date: Sat, 7 Sep 2019 20:43:40 +0200
e43f4b
Subject: [PATCH] enddianness.patch
e43f4b
e43f4b
Bug 1488552 - Ensure proper running on 64-bit and 32-bit BE platforms.
e43f4b
---
e43f4b
 js/src/gc/Marking-inl.h       | 16 ++++++++++++++++
e43f4b
 js/src/gc/RelocationOverlay.h | 13 ++++++++++++-
e43f4b
 js/src/jsfriendapi.h          |  8 ++++++++
e43f4b
 js/src/vm/StringType.h        | 13 +++++++++++++
e43f4b
 4 files changed, 49 insertions(+), 1 deletion(-)
e43f4b
4062d7
Index: firefox-60.9.0/js/src/gc/Marking-inl.h
4062d7
===================================================================
4062d7
--- firefox-60.9.0.orig/js/src/gc/Marking-inl.h	2019-09-01 15:09:17.000000000 +0200
4062d7
+++ firefox-60.9.0/js/src/gc/Marking-inl.h	2019-12-09 11:42:31.024301901 +0100
4062d7
@@ -82,12 +82,28 @@
e43f4b
   MOZ_ASSERT(!isForwarded());
e43f4b
   // The location of magic_ is important because it must never be valid to see
e43f4b
   // the value Relocated there in a GC thing that has not been moved.
e43f4b
+#if MOZ_LITTLE_ENDIAN || JS_BITS_PER_WORD == 32
e43f4b
+  // On 32-bit, the magic_ aliases with whatever comes after the first
e43f4b
+  // pointer; on little-endian 64-bit, the magic_ aliases with the
e43f4b
+  // 32 most significant bits of the pointer, which are the second half.
e43f4b
   static_assert(offsetof(RelocationOverlay, magic_) ==
e43f4b
                     offsetof(JSObject, group_) + sizeof(uint32_t),
e43f4b
                 "RelocationOverlay::magic_ is in the wrong location");
e43f4b
   static_assert(offsetof(RelocationOverlay, magic_) ==
e43f4b
                     offsetof(js::Shape, base_) + sizeof(uint32_t),
e43f4b
                 "RelocationOverlay::magic_ is in the wrong location");
e43f4b
+#elif JS_BITS_PER_WORD == 64
e43f4b
+  // On big-endian 64-bit, the magic_ aliases with the 32 most
e43f4b
+  // significant bits of the pointer, but now that's the first half.
e43f4b
+  static_assert(offsetof(RelocationOverlay, magic_) ==
e43f4b
+                    offsetof(JSObject, group_),
e43f4b
+                "RelocationOverlay::magic_ is in the wrong location");
e43f4b
+  static_assert(offsetof(RelocationOverlay, magic_) ==
e43f4b
+                    offsetof(js::Shape, base_),
e43f4b
+                "RelocationOverlay::magic_ is in the wrong location");
e43f4b
+#else
e43f4b
+#  error "Unknown endianness or word size"
e43f4b
+#endif
e43f4b
   static_assert(
e43f4b
       offsetof(RelocationOverlay, magic_) == offsetof(JSString, d.u1.length),
e43f4b
       "RelocationOverlay::magic_ is in the wrong location");
4062d7
Index: firefox-60.9.0/js/src/gc/RelocationOverlay.h
4062d7
===================================================================
4062d7
--- firefox-60.9.0.orig/js/src/gc/RelocationOverlay.h	2019-09-01 15:09:17.000000000 +0200
4062d7
+++ firefox-60.9.0/js/src/gc/RelocationOverlay.h	2019-12-09 11:42:31.024301901 +0100
4062d7
@@ -33,14 +33,25 @@
e43f4b
   /* See comment in js/public/HeapAPI.h. */
e43f4b
   static const uint32_t Relocated = js::gc::Relocated;
e43f4b
 
e43f4b
+#if MOZ_LITTLE_ENDIAN || JS_BITS_PER_WORD == 32
e43f4b
   /*
e43f4b
-   * Keep the low 32 bits untouched. Use them to distinguish strings from
e43f4b
+   * Keep the first 32 bits untouched. Use them to distinguish strings from
e43f4b
    * objects in the nursery.
e43f4b
    */
e43f4b
   uint32_t preserve_;
e43f4b
 
e43f4b
   /* Set to Relocated when moved. */
e43f4b
   uint32_t magic_;
e43f4b
+#elif JS_BITS_PER_WORD == 64
e43f4b
+  /*
e43f4b
+   * On big-endian, we need to reorder to keep preserve_ lined up with the
e43f4b
+   * low 32 bits of the aligned group_ pointer in JSObject.
e43f4b
+   */
e43f4b
+  uint32_t magic_;
e43f4b
+  uint32_t preserve_;
e43f4b
+#else
e43f4b
+#  error "Unknown endianness or word size"
e43f4b
+#endif
e43f4b
 
e43f4b
   /* The location |this| was moved to. */
e43f4b
   Cell* newLocation_;
4062d7
Index: firefox-60.9.0/js/src/jsfriendapi.h
4062d7
===================================================================
4062d7
--- firefox-60.9.0.orig/js/src/jsfriendapi.h	2019-09-01 15:09:18.000000000 +0200
4062d7
+++ firefox-60.9.0/js/src/jsfriendapi.h	2019-12-09 11:42:31.024301901 +0100
e43f4b
@@ -9,6 +9,7 @@
e43f4b
 
e43f4b
 #include "mozilla/Atomics.h"
e43f4b
 #include "mozilla/Casting.h"
e43f4b
+#include "mozilla/EndianUtils.h"
e43f4b
 #include "mozilla/Maybe.h"
e43f4b
 #include "mozilla/MemoryReporting.h"
e43f4b
 #include "mozilla/UniquePtr.h"
4062d7
@@ -609,8 +610,15 @@
e43f4b
   static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6);
e43f4b
   static const uint32_t EXTERNAL_FLAGS = LINEAR_BIT | NON_ATOM_BIT | JS_BIT(5);
e43f4b
   static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1;
e43f4b
+#if MOZ_LITTLE_ENDIAN || JS_BITS_PER_WORD == 32
e43f4b
   uint32_t flags;
e43f4b
   uint32_t length;
e43f4b
+#elif JS_BITS_PER_WORD == 64
e43f4b
+  uint32_t length;
e43f4b
+  uint32_t flags;
e43f4b
+#else
e43f4b
+#  error "Unknown endianness or word size"
e43f4b
+#endif
e43f4b
   union {
e43f4b
     const JS::Latin1Char* nonInlineCharsLatin1;
e43f4b
     const char16_t* nonInlineCharsTwoByte;
4062d7
Index: firefox-60.9.0/js/src/vm/StringType.h
4062d7
===================================================================
4062d7
--- firefox-60.9.0.orig/js/src/vm/StringType.h	2019-09-01 15:09:39.000000000 +0200
4062d7
+++ firefox-60.9.0/js/src/vm/StringType.h	2019-12-09 11:42:31.028301901 +0100
e43f4b
@@ -7,6 +7,7 @@
e43f4b
 #ifndef vm_StringType_h
e43f4b
 #define vm_StringType_h
e43f4b
 
e43f4b
+#include "mozilla/EndianUtils.h"
e43f4b
 #include "mozilla/MemoryReporting.h"
e43f4b
 #include "mozilla/PodOperations.h"
e43f4b
 #include "mozilla/Range.h"
4062d7
@@ -168,8 +169,20 @@
e43f4b
   struct Data {
e43f4b
     union {
e43f4b
       struct {
e43f4b
+#if MOZ_LITTLE_ENDIAN || JS_BITS_PER_WORD == 32
e43f4b
         uint32_t flags;  /* JSString */
e43f4b
         uint32_t length; /* JSString */
e43f4b
+#elif JS_BITS_PER_WORD == 64
e43f4b
+        /*
e43f4b
+         * On big-endian, we need to reorder to keep flags lined up
e43f4b
+         * with the low 32 bits of the aligned group_ pointer in
e43f4b
+         * JSObject.
e43f4b
+         */
e43f4b
+        uint32_t length; /* JSString */
e43f4b
+        uint32_t flags;  /* JSString */
e43f4b
+#else
e43f4b
+#  error "Unknown endianness or word size"
e43f4b
+#endif
e43f4b
       };
e43f4b
       uintptr_t flattenData; /* JSRope (temporary while flattening) */
e43f4b
     } u1;
4062d7
Index: firefox-60.9.0/js/src/js-config.h.in
4062d7
===================================================================
4062d7
--- firefox-60.9.0.orig/js/src/js-config.h.in	2019-09-01 15:09:18.000000000 +0200
4062d7
+++ firefox-60.9.0/js/src/js-config.h.in	2019-12-09 11:43:13.052302975 +0100
4062d7
@@ -38,6 +38,13 @@
4062d7
 /* Define to 1 if SpiderMonkey should include ctypes support.  */
4062d7
 #undef JS_HAS_CTYPES
4062d7
 
4062d7
+/* Define to 1 if SpiderMonkey should include trace logging support. */
4062d7
+#undef JS_TRACE_LOGGING
4062d7
+
4062d7
+/* Define to 1 if SpiderMonkey should include a breakpoint function for
4062d7
+ * artificial OOMs. */
4062d7
+#undef JS_OOM_BREAKPOINT
4062d7
+
4062d7
 /* Define to 1 if SpiderMonkey should support the ability to perform
4062d7
    entirely too much GC.  */
4062d7
 #undef JS_GC_ZEAL
4062d7
@@ -48,12 +55,25 @@
4062d7
 /* Define to 1 to perform extra assertions and heap poisoning. */
4062d7
 #undef JS_CRASH_DIAGNOSTICS
4062d7
 
4062d7
+/* Define to 1 if SpiderMonkey is compiled with support for private values at
4062d7
+ * odd-numbered memory addresses. */
4062d7
+#undef JS_UNALIGNED_PRIVATE_VALUES
4062d7
+
4062d7
 /* Define to 1 if SpiderMonkey is in NUNBOX32 mode. */
4062d7
 #undef JS_NUNBOX32
4062d7
 
4062d7
 /* Define to 1 if SpiderMonkey is in PUNBOX64 mode. */
4062d7
 #undef JS_PUNBOX64
4062d7
 
4062d7
+/* Define exactly one of these to 1 to indicate JIT code generation mode. */
4062d7
+#undef JS_CODEGEN_NONE
4062d7
+#undef JS_CODEGEN_ARM
4062d7
+#undef JS_CODEGEN_ARM64
4062d7
+#undef JS_CODEGEN_MIPS32
4062d7
+#undef JS_CODEGEN_MIPS64
4062d7
+#undef JS_CODEGEN_X86
4062d7
+#undef JS_CODEGEN_X64
4062d7
+
4062d7
 /* MOZILLA JSAPI version number components */
4062d7
 #undef MOZJS_MAJOR_VERSION
4062d7
 #undef MOZJS_MINOR_VERSION
4062d7
Index: firefox-60.9.0/js/src/jsapi.cpp
4062d7
===================================================================
4062d7
--- firefox-60.9.0.orig/js/src/jsapi.cpp	2019-09-01 15:09:18.000000000 +0200
4062d7
+++ firefox-60.9.0/js/src/jsapi.cpp	2019-12-09 11:43:13.052302975 +0100
4062d7
@@ -115,6 +115,14 @@
4062d7
 #define JS_ADDRESSOF_VA_LIST(ap) (&(ap))
4062d7
 #endif
4062d7
 
4062d7
+// See preprocessor definition of JS_BITS_PER_WORD in jstypes.h; make sure
4062d7
+// JS_64BIT (used internally) agrees with it
4062d7
+#ifdef JS_64BIT
4062d7
+static_assert(JS_BITS_PER_WORD == 64, "values must be in sync");
4062d7
+#else
4062d7
+static_assert(JS_BITS_PER_WORD == 32, "values must be in sync");
4062d7
+#endif
4062d7
+
4062d7
 JS_PUBLIC_API bool JS::CallArgs::requireAtLeast(JSContext* cx,
4062d7
                                                 const char* fnname,
4062d7
                                                 unsigned required) const {
4062d7
Index: firefox-60.9.0/js/src/jstypes.h
4062d7
===================================================================
4062d7
--- firefox-60.9.0.orig/js/src/jstypes.h	2019-09-01 15:09:18.000000000 +0200
4062d7
+++ firefox-60.9.0/js/src/jstypes.h	2019-12-09 11:43:13.052302975 +0100
4062d7
@@ -141,12 +141,17 @@
4062d7
 #define JS_BITS_PER_BYTE 8
4062d7
 #define JS_BITS_PER_BYTE_LOG2 3
4062d7
 
4062d7
-#if defined(JS_64BIT)
4062d7
+#if (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8) || \
4062d7
+    (defined(UINTPTR_MAX) && UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFu)
4062d7
 #define JS_BITS_PER_WORD 64
4062d7
 #else
4062d7
 #define JS_BITS_PER_WORD 32
4062d7
 #endif
4062d7
 
4062d7
+static_assert(sizeof(void*) == 8 ? JS_BITS_PER_WORD == 64
4062d7
+                                 : JS_BITS_PER_WORD == 32,
4062d7
+              "preprocessor and compiler must agree");
4062d7
+
4062d7
 /***********************************************************************
4062d7
 ** MACROS:      JS_FUNC_TO_DATA_PTR
4062d7
 **              JS_DATA_TO_FUNC_PTR
e43f4b