This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: AboutShareLib


Robert Lipe wrote:
> 
> Yu Xuanwei wrote:
> 
> > In libfoo.a:
> > /*function and function1 never call each other*/
> > function(){}
> > function1(){}
> >
> > In my myprog.c (compiled to myprog.o)
> > main(){
> >   function();
> >   return 0;
> > }
> >
> > Then after static linking to build myprog.out(final binary), the unuseful
> > function1() assembly exists in myprog.out or not?
> 
> Depends if function and function were defined in the same file and
> whether your linker is working correctly.

It may also be worth looking up about section garbage collection. This is
only relevant for ELF, but if you are using gcc and it is invoked with
-ffunction-sections, and then the GNU linker is invoked with --gc-sections
(i.e. -Wl,--gc-sections on the gcc command line), then it would remove
unused functions, even if other functions in the same object would be
included. i.e. in the example above, if function() and function1() are in
the same object file, ordinarily the reference to function() will cause
function1() to be included even though it isn't used. With section garbage
collection, function1() is omitted.

There are also -fdata-sections and -fvtable-gc options to gcc which allow
the same type of thing for data sections and C++ vtable entries.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]