Using the GNU ld Linker on Solaris

March 25th, 2011

On Solaris, GCC by default is compiled with the option –with-ld=/usr/ccs/bin/ld, telling it to use the Solaris linker. Unfortunately GCC uses this value above all else, meaning it will ignore LD= environment variables to set an alternative linker, such as /usr/sfw/bin/gld

Although tools like libtool/autoconf will pick up your LD= environment variable, and detect which options the linker supports (and whether its GNU ld or not), libtool unfortunately still calls gcc for the linking stage, which then ignores LD=. This makes it near-impossible to use GNU ld without actually doing a nasty hack, like “mv /usr/ccs/bin/ld /usr/ccs/bin/ld.off ; ln -s /usr/sfw/bin/ld /usr/ccs/bin/ld”. Yuck!

However, today when trying to get lame to compile using nasm (which generates objects that refuse to link with Solaris LD), I found Solaris LD accepts a very useful environment variable. The variable is LD_ALTEXEC.

Solaris LD will actually re-exec the value of LD_ALTEXEC, meaning that if you set LD_ALTEXEC to /usr/sfw/bin/gld, when /usr/ccs/bin/ld gets called, it immediately instead calls /usr/sfw/bin/gld with the arguments passed on. Thus, you can use whatever linker you wish. Hurrah! :-)

Entry Filed under: General

5 Comments Add your own

  • 1. Henry  |  March 21st, 2012 at 9:08 am

    You are an absolute champion. A colleague and I spent hours trying to get this going.

    Thank you so much; I wish I could send you a truckload of cookies.

  • 2. Henry  |  March 21st, 2012 at 9:11 am

    We couldn’t use the nasty ‘mv /usr/ccs/bin/ld hack’, as we were running in zone where /usr was read only (even to root). You have become my hero.

  • 3. Jeff Shantz  |  March 22nd, 2012 at 12:05 am

    Very helpful and fixed my problem immediately. Many thanks.

  • 4. Alasdair  |  March 22nd, 2012 at 5:20 am

    Glad to have been able to help! :-)

  • 5. Thermetics » Instal&hellip  |  March 22nd, 2012 at 11:11 pm

    [...] Info about Solaris LD_ALTEXEC [...]

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed