Subject: Re: Dynamic linking is go (again)
To: None <marcus@mc.pp.se>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-sh3
Date: 07/05/2003 12:22:30
In article <yf9znjtepvz.fsf@mc.pp.se>
marcus@mc.pp.se wrote:

> The -nostdlib comes from bsd.prog.mk, right?

Yes. It was passed if DESTDIR is set, and DESTDIR is set
unless USETOOLS=no.

> Does it choose the wrong
> crt*.o, or put the objects in the wrong order or something perhaps?
> If -nostdlib is specified, all crt objects must be added manually, and
> this makefile might not be updated to work with gcc3...

crt*.o files are also set properly by bsd.prog.mk and
they are passed to gcc(1), but gcc(1) does not pass "-e __start"
to collect2 in that case even with your gcc3.3 toolchain:
---
% pwd
/usr/src/bin/cat
% make CC=/usr/local/bin/gcc HAVE_GCC3=yes MKPROFILE=no -n
/usr/local/bin/gcc   -o cat -nostdlib  -Wl,-dynamic-linker=/libexec/ld.elf_so \
-Wl,-rpath-link,/lib:/usr/lib  -R/lib -R/usr/lib  -L/lib /usr/lib/crt0.o \
/usr/lib/crti.o /usr/lib/crtbegin.o cat.o  -L/usr/lib -L/usr/lib  \
-lgcc -lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o
% /usr/local/bin/gcc   -o cat -nostdlib  \
-Wl,-dynamic-linker=/libexec/ld.elf_so -Wl,-rpath-link,/lib:/usr/lib  \
-R/lib -R/usr/lib  -L/lib /usr/lib/crt0.o /usr/lib/crti.o \
/usr/lib/crtbegin.o cat.o  -L/usr/lib -L/usr/lib  -lgcc -lc -lgcc \
/usr/lib/crtend.o /usr/lib/crtn.o -v
Reading specs from /usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3/specs
Configured with: /home/marcus/gcc-3.3/configure \
--enable-languages=c,c++ --disable-shared
Thread model: single
gcc version 3.3
 /usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3/collect2 -m shlelf_nbsd \
-R/lib -R/usr/lib -dc -dp -dynamic-linker /usr/libexec/ld.elf_so -o cat \
-L/lib -L/usr/lib -L/usr/lib \
-L/usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3 \
-L/usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3/../../../../shl-unknown-netbsdelf1.6T/lib \
-L/usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3/../../.. \
-dynamic-linker=/libexec/ld.elf_so -rpath-link /lib:/usr/lib \
/usr/lib/crt0.o /usr/lib/crti.o /usr/lib/crtbegin.o cat.o -lgcc -lc -lgcc \
/usr/lib/crtend.o /usr/lib/crtn.o
% 
(and generated binary dumps core)
---

If USETOOLS=no is set (i.e. DESTDIR is not set in that case),
-nostdlib is not passed to gcc and collect2 is called with "-e __start":
---
% make CC=/usr/local/bin/gcc HAVE_GCC3=yes MKPROFILE=no USETOOLS=no -n
/usr/local/bin/gcc   -o cat  -Wl,-dynamic-linker=/libexec/ld.elf_so \
-Wl,-rpath-link,/lib:/usr/lib  -R/lib -R/usr/lib  -L/lib cat.o 
% /usr/local/bin/gcc   -o cat  -Wl,-dynamic-linker=/libexec/ld.elf_so \
-Wl,-rpath-link,/lib:/usr/lib  -R/lib -R/usr/lib  -L/lib cat.o -v
Reading specs from /usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3/specs
Configured with: /home/marcus/gcc-3.3/configure \
--enable-languages=c,c++ --disable-shared
Thread model: single
gcc version 3.3
 /usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3/collect2 -m shlelf_nbsd \
-R/lib -R/usr/lib -dc -dp -e __start -dynamic-linker /usr/libexec/ld.elf_so \
-o cat /usr/lib/crt0.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/lib \
-L/usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3 \
-L/usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3/../../../../shl-unknown-netbsdelf1.6T/lib \
-L/usr/local/lib/gcc-lib/shl-unknown-netbsdelf1.6T/3.3/../../.. \
-dynamic-linker=/libexec/ld.elf_so -rpath-link /lib:/usr/lib cat.o \
-lgcc -lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o
%
(This binary works fine)
---

We should check LINK_SPEC or something in gcc-3.3?
---
Izumi Tsutsui
tsutsui@ceres.dti.ne.jp