<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>200033</bug_id>
          
          <creation_ts>2019-07-23 08:58:47 -0700</creation_ts>
          <short_desc>[WPE] Unable to use jsc_weak_xxxx APIs in WPE web-extensions</short_desc>
          <delta_ts>2020-12-08 06:23:27 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WPE WebKit</component>
          <version>Other</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>219457</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=210366</see_also>
          <bug_file_loc>https://lists.webkit.org/pipermail/webkit-wpe/2019-July/000211.html</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Critical</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="munezbn.dev@gmail.com">munezbn.dev</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>agomez</cc>
    
    <cc>aperez</cc>
    
    <cc>berto</cc>
    
    <cc>bugs-noreply</cc>
    
    <cc>don.olmstead</cc>
    
    <cc>dpino</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>mrobinson</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1555048</commentid>
    <comment_count>0</comment_count>
    <who name="munezbn.dev@gmail.com">munezbn.dev</who>
    <bug_when>2019-07-23 08:58:47 -0700</bug_when>
    <thetext>Component: Javascriptcore

OS:  Cross Compiling WPEWebkit-2.24.x for Raspberry Pi3 on Fedora 28 using Wpe-buildroot

Overview: 

        jsc_weak_xxx symbols are not exported in ibwpewebkit.so . So if we try to build a web-extension which uses any jsc_weak_xxx APIs then build will fail with error *undefined reference to `jsc_weak_value_new&apos;*

Steps to Reproduce: 

        1) Create any simple web-extension : https://github.com/munezbn/sample_webkit_extension

        2) Add a few code which will use any jsc_weak_xxx API. Try to build the code.
        *  JSCValue             *js_function;
           JSCWeakValue *weak_value;
           weak_value = jsc_weak_value_new (js_function);*

Actual Results: Compilation failed with error *undefined reference to `jsc_weak_value_new&apos;*

Expected Results: Compile without any linking error


Additional Information: Output of readelf can be found at https://lists.webkit.org/pipermail/webkit-wpe/2019-July/000211.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1555049</commentid>
    <comment_count>1</comment_count>
    <who name="munezbn.dev@gmail.com">munezbn.dev</who>
    <bug_when>2019-07-23 09:01:42 -0700</bug_when>
    <thetext>---------------------------- readelf -------------------------------
readelf -a wpebuild/build/wpewebkit-2.24.1/lib/libJavaScriptCore.a | grep
jsc_value_function_call
   425: 0000158d   268 FUNC    GLOBAL DEFAULT   22 jsc_value_function_callv
   462: 00002355   144 FUNC    GLOBAL DEFAULT   22 jsc_value_function_call
readelf -a wpebuild/build/wpewebkit-2.24.1/lib/libWPEWebKit-1.0.so.2.4.2 |
grep jsc_value_function_call
   620: 00c38bad   268 FUNC    GLOBAL DEFAULT   10 jsc_value_function_callv
   759: 00c39975   144 FUNC    GLOBAL DEFAULT   10 jsc_value_function_call
315311: 00c38bad   268 FUNC    GLOBAL DEFAULT   10 jsc_value_function_callv
315450: 00c39975   144 FUNC    GLOBAL DEFAULT   10 jsc_value_function_call

readelf -a wpebuild/build/wpewebkit-2.24.1/lib/libJavaScriptCore.a | grep
jsc_weak_value_new
    54: 00000000    44 OBJECT  LOCAL  DEFAULT   25 _ZZ18jsc_weak_value_newE1
    99: 00000157    94 FUNC    GLOBAL DEFAULT    7 jsc_weak_value_new
readelf -a wpebuild/build/wpewebkit-2.24.1/lib/libWPEWebKit-1.0.so.2.4.2 |
grep jsc_weak_value_new
*&lt;NothinG&gt;*
-------------------------- grep ---------------------------
grep *jsc_value_function_call* -r wpebuild/build/wpewebkit-2.24.1/lib/
Binary file wpebuild/build/wpewebkit-2.24.1/lib/libJavaScriptCore.a matches
Binary file wpebuild/build/wpewebkit-2.24.1/lib/libWPEWebKit-1.0.so.2.4.2
matches

grep *jsc_weak* -r wpebuild/build/wpewebkit-2.24.1/lib/
Binary file wpebuild/build/wpewebkit-2.24.1/lib/libJavaScriptCore.a matches</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1556362</commentid>
    <comment_count>2</comment_count>
    <who name="munezbn.dev@gmail.com">munezbn.dev</who>
    <bug_when>2019-07-27 00:45:05 -0700</bug_when>
    <thetext>I figured out the issue but not sure how to fix it.

The compiler by default uses &quot;--no-undefined&quot; linker flag,
Even though extension is not linked to any program during build time ( but loaded in web process at run-time) , it is expected that extension library throwing this error due to &quot;--no-undefined&quot;
But the main problem is that libwebkit doesnt have jsc_weak_xxx API. I suspect that this is because linker doesn&apos;t link JSCWeakValue.o to libWPEwebkit which is because there is no code in webkit which uses jsc_weak_xxx API internally.
This usually happens when we use &quot;--as-needed&quot; linker option. But this is not the case for jsc_value_xxxx API which is used internally in webkit ( webview, jsccontext, jscexception etc).

Just to confirm above theory I added a jsc_weak_xxxx call in JSCContext.cpp and recompiled libWPEwebkit, and indeed now libWPEWebkit has all jsc_weak_xxxx symbols and was able to compile my web extension.

can someone suggest how to fix this. may be I can create a patch and submit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1556389</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2019-07-27 08:21:05 -0700</bug_when>
    <thetext>I agree we should support --no-undefined.

I recall talking to Don a few weeks ago about CMake object libraries, which I don&apos;t fully understand. But I guess the proper solution is to turn JSC into an object library rather than a static library. That only needs to be done for WPE port because only WPE port exports public API from JSC built as a static library:

https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#object-libraries

But I don&apos;t know how to actually make all the CMake changes required to do that. There is an ADD_WHOLE_ARCHIVE_TO_LIBRARIES macro in OptionsGTK.cmake that we could use here as a really big hammer for a quick fix. We could copy that into Source/WebKit/PlatformWPE.cmake and then use for the WebKit target. (That actually adds --whole-archive to all libraries, but we only need it for JavaScriptCore, so it could be refined a bit.) Either way, this wouldn&apos;t be great as it will bloat the installed library with useless code, but I think it should work.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1597986</commentid>
    <comment_count>4</comment_count>
    <who name="Andres Gomez Garcia">agomez</who>
    <bug_when>2019-12-12 07:15:34 -0800</bug_when>
    <thetext>The ADD_WHOLE_ARCHIVE_TO_LIBRARIES macro was added by Martin, so maybe he can come with valuable input.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1712716</commentid>
    <comment_count>5</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2020-12-08 01:57:04 -0800</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 219457 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1712725</commentid>
    <comment_count>6</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2020-12-08 02:29:03 -0800</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #3)
&gt; I agree we should support --no-undefined.
&gt; 
&gt; I recall talking to Don a few weeks ago about CMake object libraries, which
&gt; I don&apos;t fully understand. But I guess the proper solution is to turn JSC
&gt; into an object library rather than a static library. That only needs to be
&gt; done for WPE port because only WPE port exports public API from JSC built as
&gt; a static library:
&gt; 
&gt; https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#object-
&gt; libraries
&gt; 
&gt; But I don&apos;t know how to actually make all the CMake changes required to do
&gt; that. There is an ADD_WHOLE_ARCHIVE_TO_LIBRARIES macro in OptionsGTK.cmake
&gt; that we could use here as a really big hammer for a quick fix. We could copy
&gt; that into Source/WebKit/PlatformWPE.cmake and then use for the WebKit
&gt; target. (That actually adds --whole-archive to all libraries, but we only
&gt; need it for JavaScriptCore, so it could be refined a bit.) Either way, this
&gt; wouldn&apos;t be great as it will bloat the installed library with useless code,
&gt; but I think it should work.

The ADD_WHOLE_ARCHIVE_TO_LIBRARIES() macro is flawed because it won&apos;t
resolve target names to their file names, for example printing a before
and after using it on “TestWebCore_LIBRARIES” (the only use at the moment)
results in:

 -- BEFORE: WebKit::WebCore;gtest;GTK::GTK
 -- AFTER: -Wl,--whole-archive;WebKit::WebCore;-Wl,--no-whole-archive;-Wl,--whole-archive;gtest;-Wl,--no-whole-archive;-Wl,--whole-archive;GTK::GTK;-Wl,--no-whole-archive

…which somewhat wrong because the list contains CMake target names
(like WebKit::WebCore), while the linker expects either “-lWebCore” or
“path/to/libWebCore.a” as arguments in between the “-Wl,--whole-archive”
and the “-Wl,--no-whole-archive” flags.

I *think_ that it somewhat works because CMake realizes that “-Wl,…” is not
a valid target name nor an actual file and it passes the flags as-is to the
linker command line. This looks very finicky to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1712759</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2020-12-08 06:23:27 -0800</bug_when>
    <thetext>Wow. Everything about this bug... wow.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>