Exporting _start through library archives

BVK Chaitanya chaitu@csa.iisc.ernet.in
Tue Jan 24 17:43:00 GMT 2006


Hi,

    I got this problem, can anybody help me please? [I hope this is the 
right mailing list for these kind of questions, if not, please forgive me]

    I am developing a system level code, where i cannot use libc 
directly.  So, i wanted to write an assembly file, crt0-ia32.S, which 
passes control to main function.  I have converted it into a library 
archive file using ar & ranlib.  But the linker complaints that it 
cannot find _start symbol (even though nm reports that symbol).  If i 
try linking directly with crt0-ia32.o file, it works, but not when i 
linked through library.  Is there anyway that i can link crt0 through a 
library archive?

Thanks in advance,
BVK Chaitanya.

    Here are my source files and the compilation procedure i am following:

crt0-ia32.S
===========
       .text
       .global _start
       .global _stext

_stext:
_start:
        leal    __stack, %esp

        pushl   %ebx    /* mbi ptr      */
        pushl   %eax    /* mb magic     */
        pushl   $___return_from_main
        jmp     main /* call main() */

___return_from_main:
        int     $3
        jmp     1f
        .ascii  "System stopped."
1:      jmp      ___return_from_main

        .bss
        .space  4096
__stack:

main.c
======
int main (int magic, void *mbi)
{
    ...
    return 0;
}

PROCEDURE
=========
gcc -c -nostdinc crt0-ia32.S -o crt0-ia32.o
ar rcs libcrt0.a crt0-ia32.o
ranlib libcrt0.a

gcc -c -nostdinc main.c -o main.o
ld -e_start -N -L. -nostdlib -Ttext=300000 main.o -lcrt0
ld: warning: cannot find entry symbol _start; defaulting to 0000000000300000


-- 
The question is, how far down the rabbit hole do you want to go?



More information about the Gcc-help mailing list