Using a shared library to partly replace an archive library - ld changed behaviour
H. J. Lu
hjl@lucon.org
Sun May 1 20:45:00 GMT 2005
On Sun, May 01, 2005 at 04:29:49PM -0400, Daniel Jacobowitz wrote:
> On Sun, May 01, 2005 at 10:05:57AM -0700, H. J. Lu wrote:
> > Could someone please run this test on Solaris and report the result
> > to me? I'd like to know what Solaris does before I make the change. I
> > had the impression that on Solaris, a weak definition in relocatable
> > file will override the strong one in DSO.
>
> On Solaris, I needed two changes: use -R instead of -Wl,-rpath, and
> explicitly define a new macro when using -fPIC, since my GCC doesn't
> appear to define __PIC__.
>
> With those changes the result is:
>
> gcc -B./ -O -g -c -o main.o main.c
> gcc -B./ -O -g -fPIC -DPIC -c foo.c -o shared.o
> gcc -B./ -shared -o libshared1.so shared.o
> gcc -B./ -O -g -fPIC -DPIC -c bar.c -o bar.o
> ar rv libfoo.a bar.o
> a - bar.o
> gcc -B./ -o main1 main.o libshared1.so libfoo.a -R .
> gcc -B./ -o main2 main.o libfoo.a
> gcc -B./ -shared -o libshared3.so shared.o libfoo.a
> gcc -B./ -o main3 main.o libshared3.so libfoo.a -R .
> ./main1
> Real bar
> ./main2
> Real bar
> ./main3
> Shared library
> Real bar
>
> So it appears that whatever version of binutils FC3 uses is behaving
> identically to Sun's linker.
>
Thanks, Dan. Just to double check. You used the Solaris linker, not
the GNU linker, Solaris.
Graham, now I know why the change was made :-). This change is to
ensure that the same source code will behave the same on Linux and
Solaris.
H.J.
More information about the Binutils
mailing list