libgccjit fails to link on OS X and Solaris due to jit/,
due to the assumption there that the linker is GNU ld.  Specifically,
jit/ hardcodes the use of two options: --version-script
and -soname.

* on Darwin, --version-script doesn't seem to exist in the linker, and
  it uses -install_name rather than -soname.

* on Solaris, ld doesn't support --version-script.  However, the version
  script used for doesn't use any gld extensions, so one can
  just use -M instead.

This patch fixes these issues by using variables emitted by gcc's "configure"
rather than hardcoding the options in jit/

It's based on the first part of Rainer's patch for PR jit/84288, but I
made the following changes:
* the GNU ld case in wasn't setting ld_version_script_option.
  I set it to "--version-script" for that case.
* I moved the:
    LD_VERSION_SCRIPT_OPTION = @ld_version_script_option@
  from gcc/jit/ to gcc/, as the files
  aren't substituted, only the gcc/
  Rainer: how did this work for you?
* added LD_SONAME_OPTION, done in the same way
* conditionalized the usage of the options in to cope with
  empty LD_VERSION_SCRIPT_OPTION (as is presumably the case on OS X).
  I used ($if condition,then-part[,else-part]) for this.
  I had to add a $(COMMA) since the "then-part" contains commas, which
  need to be treated as part of the "then-part", rather than separators
  for the "else-part".
  Hopefully this is compatible with every "make" implementation that we

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

I lightly tested the not-recognized case by hacking up the
(on x86_64-pc-linux-gnu) and verifying that it links, and that a
smoketest of jit.dg/test-factorial works.

Does this fix the jit linker issues on OS X and Solaris?
(I didn't include the autogenerate configure changes)

        PR jit/64089
        PR jit/84288
        * configure: Regenerate.
        * ("linker --version-script option"): New.
        ("linker soname option"): New.

        PR jit/64089
        PR jit/84288
        * (COMMA): New.
        (jit): Move --version-script and -soname linker options to the
 gcc/      |  4 ++++
 gcc/     | 38 ++++++++++++++++++++++++++++++++++++++
 gcc/jit/ | 17 +++++++++++++++--
 3 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/gcc/ b/gcc/
index 6c37e46..903da58 100644
--- a/gcc/
+++ b/gcc/
@@ -1116,6 +1116,10 @@ endif
 LANG_MAKEFRAGS = @all_lang_makefrags@
+# Used by gcc/jit/
+LD_VERSION_SCRIPT_OPTION = @ld_version_script_option@
+LD_SONAME_OPTION = @ld_soname_option@
 # Flags to pass to recursive makes.
 # CC is set by configure.
 # ??? The choices here will need some experimenting with.
diff --git a/gcc/ b/gcc/
index b7f9728..265920c 100644
--- a/gcc/
+++ b/gcc/
@@ -3640,6 +3640,44 @@ if test x"$gcc_cv_ld_static_dynamic" = xyes; then
+AC_MSG_CHECKING(linker --version-script option)
+if test $in_tree_ld = yes || test x"$gnu_ld" = xyes; then
+  gcc_cv_ld_version_script=yes
+  ld_version_script_option='--version-script'
+elif test x$gcc_cv_ld != x; then
+  case "$target" in
+    # Solaris 2 ld always supports -M.  It also supports a subset of
+    # --version-script since Solaris 11.4, but requires
+    # -z gnu-version-script-compat to activate.
+    *-*-solaris2*)
+      gcc_cv_ld_version_script=yes
+      ld_version_script_option='-M'
+      ;;
+  esac
+# Don't AC_DEFINE result, only used in jit/ so far.
+AC_MSG_CHECKING(linker soname option)
+if test $in_tree_ld = yes || test x"$gnu_ld" = xyes; then
+  gcc_cv_ld_soname=yes
+  ld_soname_option='-soname'
+elif test x$gcc_cv_ld != x; then
+  case "$target" in
+    *-*-darwin*)
+      gcc_cv_ld_soname=yes
+      ld_soname_option='-install_name'
+      ;;
+  esac
+# Don't AC_DEFINE result, only used in jit/ so far.
 if test x"$demangler_in_ld" = xyes; then
   AC_MSG_CHECKING(linker --demangle support)
diff --git a/gcc/jit/ b/gcc/jit/
index d4362a9..ba78f8e 100644
--- a/gcc/jit/
+++ b/gcc/jit/
@@ -51,6 +51,19 @@ LIBGCCJIT_FILENAME = \
+# Conditionalize the use of the LD_VERSION_SCRIPT_OPTION and
+# LD_SONAME_OPTION depending if configure found them, using $(if)
+# We have to define a COMMA here, otherwise the commas in the "true"
+# result are treated as separators by the $(if).
+COMMA := ,
+       $(if $(LD_VERSION_SCRIPT_OPTION),\
+       $(if $(LD_SONAME_OPTION), \
@@ -85,8 +98,8 @@ $(LIBGCCJIT_FILENAME): $(jit_OBJS) \
             $(jit_OBJS) libbackend.a libcommon-target.a libcommon.a \
             $(EXTRA_GCC_OBJS) \
-            -Wl,--version-script=$(srcdir)/jit/ \
-            -Wl,-soname,$(LIBGCCJIT_SONAME)

Reply via email to