Bug 223684 - [WPE] Build error in ARMv7 invalid 'static_cast' for GLNativeWindowType
Summary: [WPE] Build error in ARMv7 invalid 'static_cast' for GLNativeWindowType
Alias: None
Product: WebKit
Classification: Unclassified
Component: WPE WebKit (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Pablo Saavedra
Depends on:
Reported: 2021-03-24 02:43 PDT by Pablo Saavedra
Modified: 2021-03-24 04:02 PDT (History)
13 users (show)

See Also:

patch (1.82 KB, patch)
2021-03-24 02:46 PDT, Pablo Saavedra
no flags Details | Formatted Diff | Diff
patch (3.28 KB, patch)
2021-03-24 03:04 PDT, Pablo Saavedra
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pablo Saavedra 2021-03-24 02:43:16 PDT
I'm getting the a similar issue building wpewebkit (main) for ARMv7 than the one reported in https://bugs.webkit.org/show_bug.cgi?id=223577#c2:

/home/bot/yocto-rpi3-manual/builds/raspberrypi3-mesa-wpe-nightly/tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/wpewebkit/trunk+gitAUTOINC+e90a458604-r0/git/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:93:23: error: invalid 'static_cast' from type 'uintptr_t' {aka 'unsigned int'} to type 'GLNativeWindowType' {aka 'void*'}

GLNativeWindowType is defined in Source/WebCore/platform/graphics/GLContext.h like this:

// FIXME: For now default to the GBM EGL platform, but this should really be
// somehow deducible from the build configuration.
#define __GBM__ 1
#endif // PLATFORM(WPE)
#include <EGL/eglplatform.h>
typedef EGLNativeWindowType GLNativeWindowType;
#else // !USE(EGL) || PLATFORM(GTK)
typedef uint64_t GLNativeWindowType;

From https://bug-178090-attachments.webkit.org/attachment.cgi?id=323356:

+        EGLNativeWindowType can be aliased to a different type depending (at least) on the EGL
+        implementation, its build options, and the libepoxy build options.  Using "static_cast"
+        works when it is a numeric value and the width of the value needs to be optionally
+        extended to 64 bits (e.g. the EGL type is "int" in a 32-bit CPU) but not for pointers,
+        and using "reinterpret_cast" works when the size of a pointer is 64 bits but not in other
+        cases. Therefore it seems reasonable to use a plain C cast expression to solve this
+        particular situation.
+    // EGLNativeWindowType changes depending on the EGL implementation: reinterpret_cast works
+    // for pointers (only if they are 64-bit wide and not for other cases), and static_cast for
+    // numeric types (and when needed they get extended to 64-bit) but not for pointers. Using
+    // a plain C cast expression in this one instance works in all cases.
+    static_assert(sizeof(EGLNativeWindowType) <= sizeof(uint64_t), "EGLNativeWindowType must not be longer than 64 bits.");
+    return (uint64_t) wpe_renderer_backend_egl_target_get_native_window(m_backend);

The build has not problems by replicating the solution from 178090:
diff --git a/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp b/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp
index f56cb9ce80f9..92d2f8476355 100644
--- a/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp
+++ b/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp
@@ -90,7 +90,8 @@ void ThreadedCompositor::createGLContext()
     auto windowType = reinterpret_cast<GLNativeWindowType>(m_nativeSurfaceHandle);
     // On 32-bit platforms GLNativeWindowType is an integer type, which cannot be casted with reinterpret_cast.
-    auto windowType = static_cast<GLNativeWindowType>(m_nativeSurfaceHandle);
+    static_assert(sizeof(GLNativeWindowType) <= sizeof(uint64_t), "GLNativeWindowType must not be longer than 64 bits.");
+    auto windowType = (GLNativeWindowType) m_nativeSurfaceHandle;
     m_context = GLContext::createContextForWindow(windowType, &PlatformDisplay::sharedDisplayForCompositing());
     if (m_context)
Comment 1 Pablo Saavedra 2021-03-24 02:46:18 PDT
Created attachment 424116 [details]
Comment 2 Pablo Saavedra 2021-03-24 03:04:42 PDT
Created attachment 424117 [details]
Comment 3 EWS 2021-03-24 04:02:15 PDT
Committed r274937: <https://commits.webkit.org/r274937>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 424117 [details].