Preserve ordering of GNU ld library grouping flags

Thomas Jahns <[email protected]>
Newsgroups gmane.comp.gnu.libtool.general
Message-ID <[email protected]>
Hello,

I noticed that libtool unfortunately puts -Wl,--start-group -Wl,--end-group and 
their short-hands -Wl,-( and -Wl,-) into an early position in the argument list 
of the link command instead of the libraries they are meant to go with, i.e. as 
originally specified.

Having libraries with cyclic dependencies is nothing I advocate for, but I think 
projects using libtool should be able to support it in their dependencies if 
necessary for external reasons.

So I had a look at what ltmain.sh does and figured out what special handling was 
needed. The corresponding patch is quite simple and straigh-forward. So I hope 
it can be included with an upcoming release.

The attached patch is vs. the master branch of
git://git.savannah.gnu.org/libtool.git at commit 
08c5524fb24b923ad91c2bdca836f1eafa56fd6c
which I hope is the correct place to use.

Regards, Thomas

_______________________________________________
https://lists.gnu.org/mailman/listinfo/libtool
0001-Fix-handling-of-flags-for-GNU-ld-library-grouping.patch (text/x-patch, 1.2 KB)
From 01fe8e27da2cbebfe2db79606e7bb846554a6863 Mon Sep 17 00:00:00 2001
From: Thomas Jahns <[email protected]>
Date: Mon, 31 Oct 2016 11:08:43 +0100
Subject: [PATCH] Fix handling of flags for GNU ld library grouping.

* -Wl,--start-group -Wl,--end-group -Wl,-\( -Wl,-) must preserve their
  respective position within the list of libraries to work as expected.
---
 build-aux/ltmain.in | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 4cd3818..41e95d9 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -5324,6 +5324,11 @@ func_mode_link ()
 	arg=$func_stripname_result
 	;;
 
+      -Wl,--start-group|-Wl,--end-group|-Wl,-\(|-Wl,-\))
+	func_append deplibs " $arg"
+	continue
+	;;
+
       -Wl,*)
 	func_stripname '-Wl,' '' "$arg"
 	args=$func_stripname_result
@@ -5938,6 +5943,15 @@ func_mode_link ()
 	  alldeplibs=:
 	  continue
 	  ;;
+        -Wl,--start-group|-Wl,--end-group|-Wl,-\(|-Wl,-\))
+	  if test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    deplibs="$deplib $deplibs"
+	  fi
+	  continue
+	  ;;
 	esac # case $deplib
 
 	$found || test -f "$lib" \
-- 
2.7.0.79.gdc08a19
smime.p7s (application/pkcs7-signature, 4.6 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.