Why are different linkers used by C compiler vs other compilers

I have installed Sun Studio 11 on our Linux machine and I am trying to use it to

compile programs of different languages. Prior to running, I set my PATH and

LD_LIBRARY_PATH to point to the software installation area as shown below.

setenv PATH /home/me/linux/SUNWspro/sunstudio12/bin:/home/me/linux/SUNWspro/sunstudio12/pro d/lib:${PATH}

setenv LD_LIBRARY_PATH /home/me/linux/SUNWspro/sunstudio12/prod/lib

I then notice that if I compile with the C compiler, it uses the linker in /usr/bin/ld

but if I use the C++, f77, or F90, they use the linker from my PATH,

/home/me/linux/SUNWspro/sunstudio12/prod/lib.

Normally, I do not care about this behavior but I am trying to pass a consistent set

of flags for all 4 cases, but with different linkers, this does not work. Specifically, I

have this set of flags for the C compiler.

"-Wl,--export-dynamic"

But, the other 3 compilers choke on this and get a warning like this:

CC: Warning: Option -Wl,--export-dynamic passed to ld, if ld is invoked, ignored otherwise

/home/me/linux/SUNWspro/sunstudio12/prod/lib/ld: unrecognized option '-Wl,--export-dynamic'

/home/me/linux/SUNWspro/sunstudio12/prod/lib/ld: use the --help option for usage information

I guess my question is why are different linkers used?

[1359 byte] By [rolfva] at [2007-11-27 5:54:38]
# 1

The C++ compiler relies on using "comdat" ELF sections. The linux linker does not process comdat sections properly, and it turns C++ binaries into trash. (The g++ compiler does not use comdat, which is probably why the bug was not previously noticed.)

We fixed the linux linker, and provide it as part of the compiler distribution. We also submitted the fixes to the linux source base for consideration, but we cannot predict when the fix will appear in any particular Linux distribution.

If you need to use the same linker for all operations, you can tell the C compiler to use the ld in prod/lib (or prod/lib/amd64 for 64-bit programs).

clamage45a at 2007-7-12 15:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Thanks for the explanation. That helps a lot. Looking back at the flags, it looks like

"-Yl,/home/ws/linux/SUNWspro/sunstudio12/prod/lib" does it for me. I tried this and

it worked.

So, is there a reason that the C compiler (via the Linux linker) supports the

"-Wl,--export-dynamic" but the C++, f77, and f90 compilers (via the Sun Studio shipped

linkers) do not?

rolfva at 2007-7-12 15:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
HiIt might be due to the fact that the system linker by default exports all symbols, whereas GNU ld doesn't and may need this option. You'll have to wait for someone from Sun to either confirm this or provide a better explanation.Paul
Paul_Floyda at 2007-7-12 15:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4

We prefer to use the system linker unless there is a reason why we cannot. For Sun C++ on current releases of linux, the system linker does not work.

For historical reasons, corresponding options for the C, C++, and Fortran compilers are not always spelled the same way. When we introduce a new common option, we try to spell it the same way on all compilers. But compilers inherit option spellings from older versions, and they sometimes conflict with spellings on other compilers.

Refer to the User Guide for each compiler to verify option spellings and behavior.

clamage45a at 2007-7-12 15:49:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...