Subject: Re: Dynamic linking is go (again)
To: None <>
From: Valeriy E. Ushakov <>
List: port-sh3
Date: 07/06/2003 00:49:42
On Sun, Jul 06, 2003 at 05:09:29 +0900, Izumi Tsutsui wrote:

> > Hmm, so it doesn't work.  Apparently it crashes in _rtld_setup.
> Maybe it's _start vs __start ENTRY problem in ld(1) which I posted.
> You have to fix ld in binutils or add -e __start in

I saw your posting, so I changed linker scripts:

> FYI, what I tried is:
> (1) Build usual toolchain for sh3el:
> % cd /usr/src
> % sh -m dreamcast -D [somewhere for ${DESTDIR}] tools


Then I built stock binutils-2.14 and tell gcc-3.3 (next step) to use

> (2) Build gcc-3.3:
> % tar jxvf gcc-3.3.tar.bz2
> % cd gcc-3.3
> % ./configure --target=shle--netbsdelf \
> --with-as=/usr/tools/sh3el/bin/shle--netbsdelf-as \
> --with-ld=/usr/tools/sh3el/bin/shle--netbsdelf-ld \
> --disable-shared --enable-languages=c,c++
> % gmake
> [I might see some errors but not sure..]
> % su
> # gmake install


> (3) Build binaries with make script
> % cd /usr/src
> % ${TOOLDIR}/bin/make-dreamcast CC=/usr/local/bin/shle--netbsdelf-gcc \
> HAVE_GCC3=yes MKPROFILE=no TOOLCHAIN_MISSING=yes BUILD_tools=no -k build
> (I'm not sure 'make -k build' works. Maybe you should visit
>  directories (lib/csu, lib/libc, libexec/ld.elf_so..) manually)

Yes.  BTW, we have convenient do-* targets in the toplevel Makefile to
build and install each of the above.  I ran nbmake-hpcsh with:


> > Perhaps, can you send me your working (on the DC) ld.elf_so,
> > and a sample binary?
> Marcus has already put some binaries, but I'll put other binaries later.

I recompiled ld.elf_so with debugging and now it prints something

<toor@nada:/mnt/distrib/bin> # ldd date
         -lutil.7 => /lib/
         -lc.12 => /lib/
<toor@nada:/mnt/distrib/bin> # ./date
sp = 0x7fffe954, argc = 1, argv = 0x7fffe960 <./date> relocbase 0x20420000
Memory fault (core dumped) 

Looking at the code in rtld.c:

        dbg(("sp = %p, argc = %ld, argv = %p <%s> relocbase %p", sp,
            (long)sp[2], &sp[3], (char *) sp[3], (void *)relocbase));
        dbg(("got is at %p, dynamic is at %p", _GLOBAL_OFFSET_TABLE_,

it looks like it crashes trying to pass _GLOBAL_OFFSET_TABLE_:

gdb (the one i already have installed on the jornada, 5.0nb1)
complains about that ./date binary:

    Dwarf Error: Cannot handler DW_FORM_strp in DWARF reader.

[... run, get sigsegv ...]
(gdb) x/i $pc
0x2042310c:	mov.l	@(r0,r12),r5
(gdb) disass $pc-4 $pc+2
0x20423108:	mov	r12,r4
0x2042310a:	mov.l	0x204232c8,r0	! 0x17454
0x2042310c:	mov.l	@(r0,r12),r5
(gdb) p/x $r0
$1 = 0x17454
(gdb) p/x $12
$2 = 0x2043a71c

Diassembling the PIC setup at start of that function (_rtld()):

0x204230cc:	mova	0x204232b4,r0
0x204230ce:	mov.l	0x204232b4,r12	! 0x17468
0x204230d0:	add	r0,r12		# uwe: 0x2043a71c

Hmm, actually looking at the build log for the ld.eld_so (with
debugging enabled) I can see

/var/tmp//ccG2h5LE.s:864: Warning: rest of line ignored; first ignored character is `@'

And that's exactly the


that we pass as the second argument to the debug_printf.

Having no clue about PIC for sh3 I wonder if something is Wrong(TM)

SY, Uwe
--                         |       Zu Grunde kommen            |       Ist zu Grunde gehen