Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

force gcc use my own crt.o

1,310 views
Skip to first unread message

peter

unread,
Mar 6, 2010, 12:17:20 PM3/6/10
to
Dear All
I have written my own start.S and libc_start_main.c , If I compile
my program like this:
gcc test.c -g -o test.o ../plibc/crt/start.o ../plibc/crt/
libc_start_main.o

It will give me this error:
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../crt1.o:(.text+0x0):
first defined here

So how to stop gcc using its build-in crt.o?

thanks
from Peter (cmk...@hotmail.com)

peter

unread,
Mar 6, 2010, 12:19:37 PM3/6/10
to

ok, may be I know the answer now. if your type in "ld --verbose", you
will see the build-in linker script, and it used the buildin crt.o. If
I compile it by my own linker script, then I can force gcc to use my
own crt.o.

correct me if I am wrong. thanks

Alexei A. Frounze

unread,
Mar 6, 2010, 12:44:14 PM3/6/10
to

I think you could also specify a parameter like -nostdlib to force it
not to link in the standard libraries.

Alex

van...@vsta.org

unread,
Mar 6, 2010, 5:05:47 PM3/6/10
to
In alt.os.development Alexei A. Frounze <alexf...@gmail.com> wrote:
> I think you could also specify a parameter like -nostdlib to force it
> not to link in the standard libraries.

Or just invoke "ld" yourself and skip the hassle of battling gcc.

--
Andy Valencia
Home page: http://www.vsta.org/andy/
To contact me: http://www.vsta.org/contact/andy.html

peter

unread,
Mar 7, 2010, 12:27:00 AM3/7/10
to
On Mar 7, 6:05 am, van...@vsta.org wrote:

> In alt.os.development Alexei A. Frounze <alexfrun...@gmail.com> wrote:
>
> > I think you could also specify a parameter like -nostdlib to force it
> > not to link in the standard libraries.
>
> Or just invoke "ld" yourself and skip the hassle of battling gcc.
>
> --
> Andy Valencia
> Home page:http://www.vsta.org/andy/
> To contact me:http://www.vsta.org/contact/andy.html

After I can load ELF in my OS, then I probably can move some
foundation library from linux, hopefully can finish it before 2012, my
progress is very slow.
thanks for the answers

peter

unread,
Mar 7, 2010, 8:50:26 AM3/7/10
to
I tested the "-nostdlib" option. If you use it, gcc will ignore to use
the start.S and libc_start_main.c . So the starting point of your
target ELF is your own main().

thanks

Marven Lee

unread,
Mar 16, 2010, 8:25:32 AM3/16/10
to

peter wrote:
> Dear All
> I have written my own start.S and libc_start_main.c , If I compile
> my program like this:
> gcc test.c -g -o test.o ../plibc/crt/start.o ../plibc/crt/
> libc_start_main.o
>
> It will give me this error:
> /usr/lib/gcc/i586-redhat-linux/4.4.1/../../../crt1.o:(.text+0x0):
> first defined here
>
> So how to stop gcc using its build-in crt.o?

If you're wanting to create a kernel without crt.o you could link
with LD instead of letting GCC call LD to do the linking. With
LD you can create a linker script which also allows you to
specify where each section of the executable should be loaded as
well as specify the entry point.

If you want to specify your own crt.o when compiling applications
then you can create your own target when making a cross-compiler.
Look through the configuration files in GCC an Binutils for some
of the simpler OSes, and duplicate what they do, replacing with
your own OS's name. I think there is a few config files where
you can specify your own crt0.o and load address that GCC/LD
will use in the default linker script.


--
Marv

0 new messages