view src/link.sh @ 33060:897f3ed27be2 v9.0.1818

patch 9.0.1818: dynamically linking perl is broken Commit: https://github.com/vim/vim/commit/55460da26c2756ec057c03c7d8641eda861bfcd2 Author: Christian Brabandt <cb@256bit.org> Date: Tue Aug 29 21:31:28 2023 +0200 patch 9.0.1818: dynamically linking perl is broken Problem: dynamically linking perl is broken Solution: Fix all issues This is a combination of several commits: 1) Fix if_perl.xs not being able to build on all versions of Perl (5.30) This fixes the dynamic builds of Perl interface. The Perl interface file previously had to manually copy and paste misc inline functions verbatim from the Perl headers, because we defined `PERL_NO_INLINE_FUNCTIONS` which prevents us form getting some function definitions. The original reason we defined it was because those inline functions would reference Perl functions that would cause linkage errors. This is a little fragile as every time a new version of Perl comes out, we inevitably have to copy over new versions of inline functions to our file, and it's also easy to miss updates to existing functions. Instead, remove the `PERL_NO_INLINE_FUNCTIONS` define, remove the manual copy-pasted inline functions. Simply add stub implementations of the missing linked functions like `Perl_sv_free2` and forward them to the DLL version of the function at runtime. There are only a few functions that need this treatment, and it's a simple stub so there is very low upkeep compared to copying whole implementations to the file. Also, fix the configure script so that if we are using dynamic linkage, we don't pass `-lperl` to the build flags, to avoid accidental external linkage while using dynamic builds. This is similar to how Python integration works. 2) Fix GIMME_V deprecation warnings in Perl 5.38 Just use GIMME_V, and only use GIMME when using 5.30 to avoid needing to link Perl_block_gimme. We could provide a stub like the other linked functions like Perl_sv_free2, but simply using GIMME is the simplest and it has always worked before. 3) Fix Perl 5.38 issues Fix two issues: 3.1. Perl 5.38 links against more functions in their inline headers, so we need to stub them too. 3.2. Perl 5.38 made Perl_get_context an inline function, but *only* for non-Windows build. Fix that. Note that this was happening in Vim currently, as it would build, but fail to run Perl code at runtime. 4) Fix Perl 5.36/5.38 when thread local is used Perl 5.36 introduced using `_Thread_local` for the current context, which causes inline functions to fail. Create a stub `PL_current_context` thread local variable to satisfy the linker for inlined functions. Note that this is going to result in a different `PL_current_context` being used than the one used in the library, but so far from testing it seems to work. 5) Add docs for how to build Perl for dynamic linking to work closes: #12827 closes: #12914 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Tue, 29 Aug 2023 22:15:03 +0200
parents 1ccc1ace9e5b
children e1e3805fcd96
line wrap: on
line source

#! /bin/sh
#
# link.sh -- try linking Vim with different sets of libraries, finding the
# minimal set for fastest startup.  The problem is that configure adds a few
# libraries when they exist, but this doesn't mean they are needed for Vim.
#
#      Author: Bram Moolenaar
# Last change: 2010 Nov 03
#     License: Public domain
#
# Warning: This fails miserably if the linker doesn't return an error code!
#
# Otherwise this script is fail-safe, falling back to the original full link
# command if anything fails.

echo "$LINK " >link.cmd
exit_value=0

if test "$LINK_AS_NEEDED" = yes; then
  echo "link.sh: \$LINK_AS_NEEDED set to 'yes': invoking linker directly."
  cat link.cmd
  if sh link.cmd; then
    exit_value=0
    echo "link.sh: Linked fine"
  else
    exit_value=$?
    echo "link.sh: Linking failed"
  fi
else
  if test -f auto/link.sed; then

#
# If auto/link.sed already exists, use it.  We assume a previous run of
# link.sh has found the correct set of libraries.
#
  echo "link.sh: The file 'auto/link.sed' exists, which is going to be used now."
  echo "link.sh: If linking fails, try deleting the auto/link.sed file."
  echo "link.sh: If this fails too, try creating an empty auto/link.sed file."
else

# If linking works with the full link command, try removing some libraries,
# that are known not to be needed on at least one system.
# Remove auto/pathdef.c if there is a new link command and compile it again.
# There is a loop to remove libraries that appear several times.
#
# Notes:
# - Can't remove Xext; It links fine but will give an error when running gvim
#   with Motif.
# - Don't remove the last -lm: On HP-UX Vim links OK but crashes when the GTK
#   GUI is started, because the "floor" symbol could not be resolved.
#
  cat link.cmd
  if sh link.cmd; then
    touch auto/link.sed
    cp link.cmd linkit.sh
    for libname in SM ICE nsl dnet dnet_stub inet socket dir elf iconv Xt Xmu Xp Xpm X11 Xdmcp x w perl dl pthread thread readline m crypt attr; do
      cont=yes
      while test -n "$cont"; do
        if grep "l$libname " linkit.sh >/dev/null; then
          if test ! -f link1.sed; then
            echo "link.sh: OK, linking works, let's try omitting a few libraries."
            echo "link.sh: See auto/link.log for details."
            rm -f auto/link.log
          fi
          echo "s/-l$libname  *//" >link1.sed
          sed -f auto/link.sed <link.cmd >linkit2.sh
          sed -f link1.sed <linkit2.sh >linkit.sh
          # keep the last -lm
          if test $libname != "m" || grep "lm " linkit.sh >/dev/null; then
            echo "link.sh: Trying to omit the $libname library..."
            cat linkit.sh >>auto/link.log
            # Redirect this link output, it may contain error messages which
            # should be ignored.
            if sh linkit.sh >>auto/link.log 2>&1; then
              echo "link.sh: Vim doesn't need the $libname library!"
              cat link1.sed >>auto/link.sed
              rm -f auto/pathdef.c
            else
              echo "link.sh: Vim DOES need the $libname library."
              cont=
              cp link.cmd linkit.sh
            fi
          else
            cont=
            cp link.cmd linkit.sh
          fi
        else
          cont=
          cp link.cmd linkit.sh
        fi
      done
    done
    if test ! -f auto/pathdef.c; then
      $MAKE objects/pathdef.o
    fi
    if test ! -f link1.sed; then
      echo "link.sh: Linked fine, no libraries can be omitted"
      touch link3.sed
    fi
  else
    exit_value=$?
  fi
fi

#
# Now do the real linking.
#
if test -s auto/link.sed; then
  echo "link.sh: Using auto/link.sed file to omit a few libraries"
  sed -f auto/link.sed <link.cmd >linkit.sh
  cat linkit.sh
  if sh linkit.sh; then
    exit_value=0
    echo "link.sh: Linked fine with a few libraries omitted"
  else
    exit_value=$?
    echo "link.sh: Linking failed, making auto/link.sed empty and trying again"
    mv -f auto/link.sed link2.sed
    touch auto/link.sed
    rm -f auto/pathdef.c
    $MAKE objects/pathdef.o
  fi
fi
if test -f auto/link.sed -a ! -s auto/link.sed -a ! -f link3.sed; then
  echo "link.sh: Using unmodified link command"
  cat link.cmd
  if sh link.cmd; then
    exit_value=0
    echo "link.sh: Linked OK"
  else
    exit_value=$?
    if test -f link2.sed; then
      echo "link.sh: Linking doesn't work at all, removing auto/link.sed"
      rm -f auto/link.sed
    fi
  fi
fi

fi

#
# cleanup
#
rm -f link.cmd linkit.sh link1.sed link2.sed link3.sed linkit2.sh

#
# return an error code if something went wrong
#
exit $exit_value

# vim:set sw=2 et: