collect2 should accept more AIX linker flags to change shared library search order

Submitted by Michael Haubenwallner on Feb. 4, 2013, 1:56 p.m.

Details

Message ID 510FBE02.40704@salomon.at
State New
Headers show

Commit Message

Michael Haubenwallner Feb. 4, 2013, 1:56 p.m.
Hi,

when using "-shared -Wl,-G" to create AIX shared libraries for use with runtime linking,
without also using "-Wl,-brtl" collect2 still does search for lib.a before lib.so,
eventually registering global constructors found in static lib.a, which are not exported
by lib.so, so the subsequent link step fails resolving these symbols.

Thank you!
/haubi/

Comments

Ian Taylor Feb. 4, 2013, 6:08 p.m.
On Mon, Feb 4, 2013 at 5:56 AM, Michael Haubenwallner
<michael.haubenwallner@salomon.at> wrote:
>
> when using "-shared -Wl,-G" to create AIX shared libraries for use with runtime linking,
> without also using "-Wl,-brtl" collect2 still does search for lib.a before lib.so,
> eventually registering global constructors found in static lib.a, which are not exported
> by lib.so, so the subsequent link step fails resolving these symbols.

This is OK if it's OK with the AIX maintainers (do we have any AIX
maintainers?  dje?).

I'll also preapprove a patch to use strcmp and strncmp here, I have no
idea why this code is checking character by character.

Ian

Patch hide | download patch | download mbox

2013-02-04  Michael Haubenwallner <michael.haubenwallner@salomon.at>

	Accept all flags that enable aix runtime linking to change the
	library search order. Also there is a disabling flag.
	* collect2.c (aixrtl_flag): Enabled by -G and -bsvr4 too. Disabled
	by -bnortl. No false positive on -brtllib or -bnortllib.
---
 gcc/collect2.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index 0db908f..a9fd7a7 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -1033,9 +1033,15 @@  main (int argc, char **argv)
 	      export_flag = 1;
 	    else if (arg[2] == '6' && arg[3] == '4')
 	      aix64_flag = 1;
-	    else if (arg[2] == 'r' && arg[3] == 't' && arg[4] == 'l')
-	      aixrtl_flag = 1;
+	    else if (arg[2] == 'r' && arg[3] == 't' && arg[4] == 'l' && arg[5] == '\0')
+	      aixrtl_flag = 1; /* -brtl (not -brtllib) */
+	    else if (arg[2] == 'n' && arg[3] == 'o' && arg[4] == 'r' && arg[5] == 't' && arg[6] == 'l' && arg[7] == '\0')
+	      aixrtl_flag = 0; /* -bnortl (not -bnortllib) */
+	    else if (arg[2] == 's' && arg[3] == 'v' && arg[4] == 'r' && arg[5] == '4')
+	      aixrtl_flag = 1; /* -bsvr4 enables -brtl */
 	  }
+	if ((argv[i][0] == '-') && (argv[i][1] == 'G'))
+	    aixrtl_flag = 1; /* -G enables -brtl */
 #endif
       }
     vflag = debug;
-- 
1.7.3.4