C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

will linker leave out unused symbols from binary?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Sam Smith
Guest





PostPosted: Tue Sep 28, 2004 2:16 pm    Post subject: will linker leave out unused symbols from binary? Reply with quote



Hi,

I'm thinking about whether or not to build a general library on its own and
later link that lib with the main executable, or to build the main
executable with a subset of the relevant source files from that library.

If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions that
are never used.

But I do not like to manage this kind of dependency! I'd much rather just
build a lib with all files that belongs to that module and later link
against that library when producing the exe. Separations of concern and easy
management of dependicies :-)

However, I'm not sure if this may lead to an undesired increase of the
executable's size (since unused symbols and functions may get linked in into
the executable). What is the story about this?

I know that this must be an implementation issue, i.e. it is up to the
linker to leave unused stuff out of the exe - but I hope that there is a
general answer :-)

Thanks in advance!



Back to top
John Harrison
Guest





PostPosted: Tue Sep 28, 2004 2:21 pm    Post subject: Re: will linker leave out unused symbols from binary? Reply with quote




"Sam Smith" <sam (AT) smith (DOT) com> wrote

Quote:
Hi,

I'm thinking about whether or not to build a general library on its own
and
later link that lib with the main executable, or to build the main
executable with a subset of the relevant source files from that library.

If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions
that
are never used.

But I do not like to manage this kind of dependency! I'd much rather just
build a lib with all files that belongs to that module and later link
against that library when producing the exe. Separations of concern and
easy
management of dependicies :-)

However, I'm not sure if this may lead to an undesired increase of the
executable's size (since unused symbols and functions may get linked in
into
the executable). What is the story about this?

I know that this must be an implementation issue, i.e. it is up to the
linker to leave unused stuff out of the exe - but I hope that there is a
general answer :-)


The general answer is that it is an implementation issue. Consult your
linker documentation. Maybe even do some experiments.

Incidentally this question has very little to do with C++ which is what this
group is supposed to be about.

john



Back to top
Victor Bazarov
Guest





PostPosted: Tue Sep 28, 2004 2:27 pm    Post subject: Re: will linker leave out unused symbols from binary? Reply with quote



Sam Smith wrote:
Quote:
I'm thinking about whether or not to build a general library on its own and
later link that lib with the main executable, or to build the main
executable with a subset of the relevant source files from that library.

If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions that
are never used.

But I do not like to manage this kind of dependency! I'd much rather just
build a lib with all files that belongs to that module and later link
against that library when producing the exe. Separations of concern and easy
management of dependicies :-)

However, I'm not sure if this may lead to an undesired increase of the
executable's size (since unused symbols and functions may get linked in into
the executable). What is the story about this?

I know that this must be an implementation issue, i.e. it is up to the
linker to leave unused stuff out of the exe - but I hope that there is a
general answer Smile

There is no general answer, not in terms of Standard C++ language, anyway.
Linkers are OS-dependent, compiler-dependent, and differ from vendor to
vendor. Some are smarter, some are dumber. All we can tell you that you
are right to _want_ this, but there is no guarantee to get it.

V

Back to top
David Harmon
Guest





PostPosted: Tue Sep 28, 2004 6:04 pm    Post subject: Re: will linker leave out unused symbols from binary? Reply with quote

On Tue, 28 Sep 2004 16:16:45 +0200 in comp.lang.c++, "Sam Smith"
<sam (AT) smith (DOT) com> wrote,
Quote:
If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions that
are never used.

A typical common behavior is that the linker will pull out of the
library any object file that is needed to satisfy a reference, and leave
out any object file that is completely unused, but it cannot split up
any object file and bring in part of it. For best results the library
must be built out of many small object files each containing the
smallest working subset of mutually dependent code and data.

Of course this is outside the scope of the C++ language and you must
read the fine manual of your particular implementation.


Back to top
Nils O. Selåsdal
Guest





PostPosted: Wed Sep 29, 2004 1:49 pm    Post subject: Re: will linker leave out unused symbols from binary? Reply with quote

Sam Smith wrote:
Quote:
Hi,

I'm thinking about whether or not to build a general library on its own and
later link that lib with the main executable, or to build the main
executable with a subset of the relevant source files from that library.

If I choose to build the executable directly with only relevant source
files, I know I do not bloat the executable with symbols and functions that
are never used.

But I do not like to manage this kind of dependency! I'd much rather just
build a lib with all files that belongs to that module and later link
against that library when producing the exe. Separations of concern and easy
management of dependicies :-)

However, I'm not sure if this may lead to an undesired increase of the
executable's size (since unused symbols and functions may get linked in into
the executable). What is the story about this?

I know that this must be an implementation issue, i.e. it is up to the
linker to leave unused stuff out of the exe - but I hope that there is a
general answer Smile
There is not.


On e.g. GNU/Linux, if you create a (static archive/library)
every object file as a whole is either included or not.
That is, if something is needed in a .o file, the whole .o
file is linked in, otherwise it is left out. This seems
rather common among other implmentations as well though.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.