bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: Paul Smith <psmith@gnu.org>
Subject: relocatable-prog: Use $ORIGIN trick on more platforms
Date: Wed, 20 Feb 2019 02:45:11 +0100	[thread overview]
Message-ID: <2334191.0oAdKfnz2d@omega> (raw)

Paul Smith noted on gnu-prog-discuss that other systems than glibc have support
for $ORIGIN in rpath. This patch changes the 'relocatable-prog' module to
make use of this feature, thus removing the need for a "wrapper"/"trampoline"
executable on these platforms.

Tested on
  - FreeBSD 11,
  - NetBSD 7, 8,
  - OpenBSD 6,
  - Solaris 9, 10, 11,
  - Haiku.


2019-02-19  Bruno Haible  <bruno@clisp.org>

	relocatable-prog: Use $ORIGIN trick on more platforms.
	* m4/relocatable.m4 (gl_RELOCATABLE_BODY): Use $ORIGIN trick also on
	FreeBSD >= 7.3, DragonFly >= 3.0, NetBSD >= 8.0, OpenBSD >= 5.4,
	Solaris >= 10, Haiku. But don't use it on Android.
	* build-aux/reloc-ldflags: Allow the use of the $ORIGIN trick also on
	Hurd, FreeBSD, DragonFly, NetBSD, OpenBSD, Solaris, Haiku.

diff --git a/m4/relocatable.m4 b/m4/relocatable.m4
index c55f7b4..0044477 100644
--- a/m4/relocatable.m4
+++ b/m4/relocatable.m4
@@ -1,4 +1,4 @@
-# relocatable.m4 serial 19
+# relocatable.m4 serial 20
 dnl Copyright (C) 2003, 2005-2007, 2009-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -40,10 +40,34 @@ AC_DEFUN([gl_RELOCATABLE_BODY],
     enable_rpath=no
     AC_CHECK_HEADERS([mach-o/dyld.h])
     AC_CHECK_FUNCS([_NSGetExecutablePath])
+changequote(,)dnl
     case "$host_os" in
       mingw*) is_noop=yes ;;
+      # For the platforms that support $ORIGIN, see
+      # <https://lekensteyn.nl/rpath.html>.
+      # glibc systems, Linux with musl libc: yes. Android: no.
+      # Hurd: no <http://lists.gnu.org/archive/html/bug-hurd/2019-02/msg00049.html>.
+      linux*-android*) ;;
+      gnu*) ;;
       linux* | kfreebsd*) use_elf_origin_trick=yes ;;
+      # FreeBSD >= 7.3, DragonFly >= 3.0: yes.
+      freebsd | freebsd[1-7] | freebsd[1-6].* | freebsd7.[0-2]) ;;
+      dragonfly | dragonfly[1-2] | dragonfly[1-2].*) ;;
+      freebsd* | dragonfly*) use_elf_origin_trick=yes ;;
+      # NetBSD >= 8.0: yes.
+      netbsd | netbsd[1-7] | netbsd[1-7].*) ;;
+      netbsdelf | netbsdelf[1-7] | netbsdelf[1-7].*) ;;
+      netbsd*) use_elf_origin_trick=yes ;;
+      # OpenBSD >= 5.4: yes.
+      openbsd | openbsd[1-5] | openbsd[1-4].* | openbsd5.[0-3]) ;;
+      openbsd*) use_elf_origin_trick=yes ;;
+      # Solaris >= 10: yes.
+      solaris | solaris2.[1-9] | solaris2.[1-9].*) ;;
+      solaris*) use_elf_origin_trick=yes ;;
+      # Haiku: yes.
+      haiku*) use_elf_origin_trick=yes ;;
     esac
+changequote([,])dnl
     if test $is_noop = yes; then
       RELOCATABLE_LDFLAGS=:
       AC_SUBST([RELOCATABLE_LDFLAGS])
diff --git a/build-aux/reloc-ldflags b/build-aux/reloc-ldflags
index 4f2b10d..3aed330 100755
--- a/build-aux/reloc-ldflags
+++ b/build-aux/reloc-ldflags
@@ -54,7 +54,12 @@ case "$installdir" in
 esac
 
 case "$host_os" in
-  linux* | kfreebsd*)
+  linux* | gnu* | kfreebsd* | \
+  freebsd* | dragonfly* | \
+  netbsd* | \
+  openbsd* | \
+  solaris* | \
+  haiku*)
     rpath=
     save_IFS="$IFS"; IFS=":"
     for dir in $library_path_value; do
@@ -89,7 +94,14 @@ case "$host_os" in
     IFS="$save_IFS"
     # Output it.
     if test -n "$rpath"; then
-      echo "-Wl,-rpath,$rpath"
+      case "$host_os" in
+        # At least some versions of FreeBSD, DragonFly, and OpenBSD need the
+        # linker option "-z origin". See <https://lekensteyn.nl/rpath.html>.
+        freebsd* | dragonfly* | openbsd*)
+          echo "-Wl,-z,origin -Wl,-rpath,$rpath" ;;
+        *)
+          echo "-Wl,-rpath,$rpath" ;;
+      esac
     fi
     ;;
   *)



             reply	other threads:[~2019-02-20  1:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20  1:45 Bruno Haible [this message]
2019-02-20 16:12 ` relocatable-prog: Use $ORIGIN trick on more platforms Paul Smith
2019-02-23 21:54   ` Bruno Haible
2019-02-24  0:51     ` Bruno Haible
2019-03-04 16:32     ` Bruno Haible
2019-02-23 20:26 ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2334191.0oAdKfnz2d@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=psmith@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).