avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Unused functions linked?


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Unused functions linked?
Date: Tue, 14 Jan 2003 12:01:06 +0100 (MET)

"Tvrtko A. Ursulin" <address@hidden> wrote:

> Why is it that functions that are never used are still getting
> linked in final output?

Because the linker doesn't operate by function, it operates by
(object) file.  The linker simply doesn't have the notion of a
"function" or anything like that at all: all it knows are symbols.
So, a function is a global symbol as well as an (external) variable.
After combining all the explicitly named object files, any still
unresolved references are going to be resolved from the specified
libraries; any library module (i. e. any object file that has been
stored in a library) that would resolve an undefined reference will be
linked to the resulting ELF file, and the search continues.  New
undefined references caused by such a module can still be resolved by
looking up in the same library again (since it's a so-called random
access library, where the combined symbol table is a separate part of
the library to aid the linker in finding the object modules), but
libraries that have been specified earlier on the command-line will
not be considered again.  That's why the specification of libraries is
position-dependant on the command-line, and it can sometimes be
necessary to specify a library twice.  E. g., by default, gcc adds
"-lc -lgcc -lc" at the end of the linker command line.

Just have a look at the sourcecode of avr-libc itself, you'll notice
that most functions go into separate files.  There are exceptions
though, e. g. malloc() and free() currently live in the same file (so
they can share their private static variables).  So if you link
malloc(), you always also get free().  This might change in future
(e. g. when i come around to also implement realloc() since not
everybody who wants to have malloc() also needs realloc(), but then i
have to use global variables shared between these files).

> I thought that someone said that one can solve this but putting them
> in separate object file. I did that so I have two functions in a
> separate object file. Both are left unused, but linker includes them
> nevertheless..

Than you might have other references in that file.  Normally, that's
the way to go.  Oh, maybe we're talking about different things...
Read what i wrote above: /all/ .o files on the command-line will
/always/ be included into the resulting ELF file.  Maybe that's your
problem?  The automatic lookup will only work for library (.a) files.

-- 
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/
avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]