Hi! I have a question regarding linking binaries under hurd.

I found that if I compile binaries to object files under linux and then
link it under hurd agains its libc everything works OK.

I'am trying to port a386 and Linux/a386 to hurd, so I'm compiling linux
kernel under linux and I would like to link it against hurd's a386 and
libc, but the problem is that I'm not using gcc but ld directly.

Normally If I compile sample program under linux to .o file I can then
link it against standard libraries doing something like this:

ld -Bstatic  -m elf_i386 -e _start main.o /usr/lib/crt1.o /usr/lib/crti.o
/usr/lib/crtn.o /usr/lib/libc.a 
/usr/lib/gcc-lib/i486-unknown-linux-gnulibc1/2.7.2.3/libgcc.a
-rpath /lib -Bstatic -o main

and it works well.

But if I do something similar under hurd:

ld -Bstatic -m elf_i386  -e _start /usr/lib/crtn.o main.o /usr/lib/crt0.o
/usr/lib/crti.o /lib/libc.a -o main -Bstatic

it segfaults in _init.
If I disassemble it, it looks:

0x80480b8 <_init>:      push   %ebp
0x80480b9 <_init+1>:    mov    %esp,%ebp
0x80480bb <_init+3>:    sub    $0x14,%esp
0x80480be <_init+6>:    push   %ebx
0x80480bf <_init+7>:    call   0x80480c4 <_init+12>
0x80480c4 <_init+12>:   pop    %ebx
0x80480c5 <_init+13>:   add    $0x58bfc,%ebx
0x80480cb <_init+19>:   cmpl   $0x0,0xc(%ebx)
0x80480d2 <_init+26>:   je     0x80480d9 <_init+33>
0x80480d4 <_init+28>:   call   0x0
0x80480d9 <_init+33>:   lea    0x0(%esi),%esi
0x80480dc:      add    %al,(%eax)
0x80480de:      add    %al,(%eax)
0x80480e0 <main>:       push   %ebp
0x80480e1 <main+1>:     mov    %esp,%ebp
(...)

that's all... it ends in _init+33...
But if I compile static binary using gcc it it longer:

0x80480b4 <_init>:      push   %ebp
0x80480b5 <_init+1>:    mov    %esp,%ebp
0x80480b7 <_init+3>:    sub    $0x14,%esp
0x80480ba <_init+6>:    push   %ebx
0x80480bb <_init+7>:    call   0x80480c0 <_init+12>
0x80480c0 <_init+12>:   pop    %ebx
0x80480c1 <_init+13>:   add    $0x58d34,%ebx
0x80480c7 <_init+19>:   cmpl   $0x0,0xc(%ebx)
0x80480ce <_init+26>:   je     0x80480d5 <_init+33>
0x80480d0 <_init+28>:   call   0x0
0x80480d5 <_init+33>:   lea    0x0(%esi),%esi
0x80480d8 <_init+36>:   call   0x8048194 <frame_dummy>
0x80480dd <_init+41>:   call   0x80924e0 <__do_global_ctors_aux>
0x80480e2 <_init+46>:   pop    %ebx
0x80480e3 <_init+47>:   leave  
0x80480e4 <_init+48>:   ret    

So my question is: HOW should I link binaries under hurd? :)


--
Mariusz Wołoszyn
Internet Security Specialist, Internet Partners, GTS Poland

Reply via email to