Title: [276482] trunk/Source/WebKit
Revision
276482
Author
[email protected]
Date
2021-04-22 20:23:14 -0700 (Thu, 22 Apr 2021)

Log Message

[Mac] CMBaseClass object pointers can become unaligned on x86
https://bugs.webkit.org/show_bug.cgi?id=224950
<rdar://77020922>

Reviewed by Eric Carlson.

CMBaseClass has a 4-byte version member before its 8-byte pointers on x86. Deal with this
the same way we do with other pointer-bearing, static, CM-type objects: enforce a 4-byte
packing, and prepend the struct with another 4-byte object in order to force the pointers
into 8-byte alignment.

* Shared/mac/MediaFormatReader/CoreMediaWrapped.h:
(WebKit::CoreMediaWrapped<Wrapped>::vTable):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (276481 => 276482)


--- trunk/Source/WebKit/ChangeLog	2021-04-23 02:52:19 UTC (rev 276481)
+++ trunk/Source/WebKit/ChangeLog	2021-04-23 03:23:14 UTC (rev 276482)
@@ -1,3 +1,19 @@
+2021-04-22  Jer Noble  <[email protected]>
+
+        [Mac] CMBaseClass object pointers can become unaligned on x86
+        https://bugs.webkit.org/show_bug.cgi?id=224950
+        <rdar://77020922>
+
+        Reviewed by Eric Carlson.
+
+        CMBaseClass has a 4-byte version member before its 8-byte pointers on x86. Deal with this
+        the same way we do with other pointer-bearing, static, CM-type objects: enforce a 4-byte
+        packing, and prepend the struct with another 4-byte object in order to force the pointers
+        into 8-byte alignment.
+
+        * Shared/mac/MediaFormatReader/CoreMediaWrapped.h:
+        (WebKit::CoreMediaWrapped<Wrapped>::vTable):
+
 2021-04-22  Wenson Hsieh  <[email protected]>
 
         Followup to r276397

Modified: trunk/Source/WebKit/Shared/mac/MediaFormatReader/CoreMediaWrapped.h (276481 => 276482)


--- trunk/Source/WebKit/Shared/mac/MediaFormatReader/CoreMediaWrapped.h	2021-04-23 02:52:19 UTC (rev 276481)
+++ trunk/Source/WebKit/Shared/mac/MediaFormatReader/CoreMediaWrapped.h	2021-04-23 03:23:14 UTC (rev 276482)
@@ -142,12 +142,23 @@
 template<typename Wrapped>
 const typename CoreMediaWrapped<Wrapped>::WrapperVTable& CoreMediaWrapped<Wrapped>::vTable()
 {
-    static constexpr CMBaseClass baseClass = wrapperClass<sizeof(Wrapped)>();
-    static constexpr WrapperClass derivedClass = Wrapped::wrapperClass();
+    // CMBaseClass contains 64-bit pointers that aren't 8-byte aligned. To suppress the linker
+    // warning about this, we prepend 4 bytes of padding when building.
+#if CPU(X86_64)
+    constexpr size_t padSize = 4;
+#else
+    constexpr size_t padSize = 0;
+#endif
+
+#pragma pack(push, 4)
+    static constexpr struct { uint8_t pad[padSize]; CMBaseClass baseClass; } baseClass { { }, wrapperClass<sizeof(Wrapped)>() };
+    static constexpr struct { uint8_t pad[padSize]; WrapperClass derivedClass; } derivedClass { { }, Wrapped::wrapperClass() };
+#pragma pack(pop)
+
 IGNORE_WARNINGS_BEGIN("missing-field-initializers")
     static constexpr WrapperVTable vTable {
-        { nullptr, &baseClass },
-        &derivedClass,
+        { nullptr, &baseClass.baseClass },
+        &derivedClass.derivedClass,
     };
 IGNORE_WARNINGS_END
     return vTable;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to