Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Sep 2010 11:51:09 +0100 (BST)
From:      Anton Shterenlikht <mexas@bristol.ac.uk>
To:        Michel Talon <talon@lpthe.jussieu.fr>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: ld(1) cannot find entry symbol _start;
Message-ID:  <alpine.BSF.2.00.1009291140530.69179@mech-cluster241.men.bris.ac.uk>
In-Reply-To: <20100928135414.GA17159@lpthe.jussieu.fr>
References:  <20100928135414.GA17159@lpthe.jussieu.fr>

next in thread | previous in thread | raw e-mail | index | archive | help


On Tue, 28 Sep 2010, Michel Talon wrote:

> Paul B Mahol said:
> On 9/28/10, Anton Shterenlikht <mexas@bristol.ac.uk> wrote:
>>> I'm trying to learn the very basics of the
>>> compile - assemble - link process on FreeBSD.
>>> Please don't shoot me.
>> ....
>>> Then I try to link the object file into
>>> an executable:
>>>
>>> % ld tmp.o
>>
>> You are missing something in above command.
>>
>
> More precisely, if you run gcc -v on a C file you get someting like:
> /usr/bin/ld --eh-frame-hdr -V -dynamic-linker /libexec/ld-elf.so.1
> /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib
> -L/usr/lib /var/tmp//cco5EINk.o -lgcc --as-needed -lgcc_s --no-as-needed
> -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o
> /usr/lib/crtn.o
>
>
> where the object file produced by compilation and assembling is
> /var/tmp//cco5EINk.o
>
> That is adds several other object files to your own in order to get
> an executable.
>
> In particular the start symbol, at which execution begins is in
> /usr/lib/crt1.o
>
> as you can see from
> niobe% nm /usr/lib/crt1.o
>         w _DYNAMIC
> 00000000 D __progname
>         U _fini
>         U _init
>         U _init_tls
> 00000000 T _start
> 00000020 t _start1
> 00000000 r abitag
>         U atexit
> 00000004 C environ
>         U exit
>         U main
> which shows that _start is defined here, (but not e.g. _init). On the
> other hand the function main() which is defined in your program is
> referred to but undefined here.

thank you. Where can I read more on what each file is for:

% ls -al /usr/lib/crt*
-r--r--r--  1 root  wheel  2552 Sep 15 13:52 /usr/lib/crt1.o
-r--r--r--  1 root  wheel  4656 Sep 15 13:53 /usr/lib/crtbegin.o
-r--r--r--  1 root  wheel  4936 Sep 15 13:53 /usr/lib/crtbeginS.o
-r--r--r--  1 root  wheel  4656 Sep 15 13:53 /usr/lib/crtbeginT.o
-r--r--r--  1 root  wheel  3648 Sep 15 13:53 /usr/lib/crtend.o
-r--r--r--  1 root  wheel  3648 Sep 15 13:53 /usr/lib/crtendS.o
-r--r--r--  1 root  wheel  1928 Sep 15 13:52 /usr/lib/crti.o
-r--r--r--  1 root  wheel  1087 Sep 15 13:52 /usr/lib/crtn.o

The sources for these files are in asm, so would be good
to read a more accessible introduction.

Also, it seems only crt1, crti and crtn are provided
by FreeBSD itself (/usr/src/lib/csu/ia64), crtbegin and
crtend are under /usr/src/contrib/gcc/config/ia64/,
and sources for *S.o and *T.o I can't find at all.
So which of these are specific to GCC on FreeBSD, and
which aren't?

For example if I use g95 compiler instead of gfortran45,
will the linker still need all above object files?

many thanks
anton




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.00.1009291140530.69179>