]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
m4/libtool.m4: fix emscripten CXX postdeps using non-PIC sysroot
authorAlexandre Janniaux <alexandre.janniaux@gmail.com>
Tue, 10 Mar 2026 17:46:58 +0000 (18:46 +0100)
committerIleana Dumitrescu <ileanadumitrescu95@gmail.com>
Wed, 22 Apr 2026 17:15:25 +0000 (20:15 +0300)
Commit d8a934458b251b465b7d31da9ba9148a128a146d introduced shared
libraries support for emscripten, using -sSIDE_MODULE=1, but the CXX
dependency detection in _LT_SYS_HIDDEN_LIBDEPS will only try to use
`-shared` link option to discover implicit dependencies.

The libraries and search paths reported by em++ differ depending on
whether -sSIDE_MODULE=2 is passed:

  em++ -shared -v conftest.o:
    -L<sysroot>/lib/wasm32-emscripten  (<-- non-PIC)
       -lhtml5... (other -l flags)

  em++ -sSIDE_MODULE=2 -shared -v conftest.o
    -L<sysroot>/lib/wasm32-emscripten/pic  (<-- PIC)
       (no -l flags)

Without -sSIDE_MODULE=2, the detected postdeps contain the non-PIC
sysroot path and system libraries. These get injected into the CXX
shared library link line before emcc can append the PIC sysroot,
causing wasm-ld to resolve system libraries from non-PIC archives,
typically in VLC build system:

    error: R_WASM_MEMORY_ADDR_LEB cannot be used against symbol;
           recompile with -fPIC

We resolved the issue in VLC by patching the postdeps but they were not
generated properly in the first place.

Fix by overriding output_verbose_link_cmd for emscripten in
_LT_LANG_CXX_CONFIG. The override passes -sSIDE_MODULE=2, matching what
archive_cmds actually uses at link time so that the detected paths point
to the PIC sysroot.

* NEWS: Update.

NEWS
m4/libtool.m4

diff --git a/NEWS b/NEWS
index 091b99b60559902065e10da31daaf495d2ff0b57..813eb1a4f17d4ab3d1c56bb0b353cccfe27f0f00 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,8 @@ NEWS - list of user-visible changes between releases of GNU Libtool
 
   - Recognise more static linking options for Clang.
 
+  - Fix emscripten CXX postdeps using non-PIC sysroot.
+
 ** Changes in supported systems or compilers:
 
   - Add support for SlimCC compiler.
index d8627ba26b192cbd758651f10bcbcbbef947be13..84a34a1281d799f3871825c418cba17c2f14fdbd 100644 (file)
@@ -7704,6 +7704,14 @@ if test yes != "$_lt_caught_CXX_error"; then
         _LT_TAGVAR(ld_shlibs, $1)=no
         ;;
 
+      emscripten*)
+        # Emscripten side modules (-sSIDE_MODULE=2) use a separate PIC sysroot
+        # and do not link system libraries (they are imported from the main module
+        # at runtime).  Re-run the verbose link with -sSIDE_MODULE=2 so that the
+        # detected paths point to the PIC sysroot instead of the non-PIC one.
+        output_verbose_link_cmd='$CC -sSIDE_MODULE=2 -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP " [[-]]L"'
+        ;;
+
       *)
         # FIXME: insert proper C++ library support
         _LT_TAGVAR(ld_shlibs, $1)=no