What are the negative consequences of including and / or binding things that are not used by your binary?

Say that I have a binary file that I create, and I include a bunch of files that are never used, and follow the link to the libraries described by these included files? (again, these libraries are never used)

What are the negative consequences of this, besides increasing compilation time?

+6
c ++ linux linker g ++ ld
source share
13 answers

A few I can think of are namespace pollution and binary size

+8
source share

In addition to compilation time; Increased complexity, unnecessary distraction during debugging, maintenance overhead.

Also nothing.

+5
source share

In addition to that, Sasha lists maintenance costs . Can you easily find out what is used and what is not used in the future, when and if you decide to remove unused things?

+4
source share

If libraries are never used, the size of the executable file should not increase.

+4
source share

Depending on the particular linker, you may also notice that the global objects of your unused libraries are still being created. This implies a lack of memory and increases startup costs.

+3
source share

If the libraries that you include but don’t use are not on the target system, they will not be able to compile even if they are not needed.

+1
source share

Here is my answer to a similar question about C and static libraries. Perhaps this is useful to you in the context of C ++.

+1
source share

You indicate an increase in compilation time. From this I understand that libraries are statically linked, not dynamically. In this case, it depends on how the linker processes unused functions. If he ignores them, you will have problems with the service. If they are included, the size of the executable file will increase. Now this is more important than the space required on the hard drive. Large executables may run slower due to caching issues. If the active code and the inactive code are adjacent in exe, they will be cached together, which makes the cache more efficient and less efficient.

VC2005 and above have an optimization called PGO, which orders the code inside the executable in a way that provides efficient caching of the code that is often used. I don't know if g ++ has a similar optimization, but it's worth a look at this.

+1
source share

A small compilation of problems here, wiki-edit it as needed:

The main problem is as follows: Namespace pollution This can cause problems with further debugging, version control, and an increase in maintenance costs in the future.

There will also be a minimal Binary Bloat , since references to the name of the function / class / namespace will be supported (in the symbol table?). Dynamic libraries should not greatly increase the size of the binary (but do they become dependent to run the binary?). Judging by the GNU C compiler, statically linked libraries should not be included in the final binary if they are never mentioned in the source. (An assumption based on the C compiler may need to be clarified / fixed)

In addition, depending on the nature of your libraries, global and static objects / variables can be created, resulting in increased startup time and low memory .

Oh, and increased compilation / linking time.

+1
source share

It seems to me that this is unpleasant when I edit the file in the source tree, because some symbol that I work in appears in the source file (for example, the name of the function where I just changed the prototype) or, unfortunately, but more usually just added a prototype to the header), so I need to check the correct use or the compiler now tells me that the use in this file is incorrect. So, I am editing the file. Then I see a problem - what does this file do? And it turns out that although the code is "used" in the product, it really is not actively used at all.

I discovered the occurrence of this problem on Monday. A file with 10,000 + lines of code called the function 'extern void add_remainder (void);' with argument 0. So, I decided to fix it. Then I looked at the rest of the code ... it turned out that it was an incomplete release about 15 years ago, which was never deleted. Having cleanly cut the code, it turned out that it included minor changes in more than half a dozen files, and I have not yet determined whether it is possible to remove the enumeration constant from the middle of the enumeration in the case. Temporarily what is marked "Unused / Deprecated", can it be safely deleted? "

This piece of code has had zero bay coverage over the past 15 years - production, test, ... True, this is just a tiny part of the vast system - in percent, it is less than 1% of the diagram. However, this is an extra waste of code.

Incomprehensible. Annoying. Disappointingly general (I have recorded and recorded at least half a dozen such errors this year so far).

And the waste of my time - and the time of other developers. Over the years, this file has been edited by other people doing what I did - meticulous work.

+1
source share

I've never had problems linking a .lib file from which only a very small part is used. Only the code that is actually used will be associated with the executable, and the connection time will not significantly increase (using Visual Studio).

0
source share

If you are linking to binary files and loading at run time, they can do non-trivial initialization, which can do anything from allocating a small amount of memory to consuming limited resources, to change the state of your module so that you don't expect further.

You better get rid of things you don't need, just to eliminate a bunch of unknowns.

0
source share

It may not even be possible to compile if the assembly tree is not supported. if you are compiling embedded systems without swap space. The compiler may run out of memory when trying to compile a massive object file.

This happened recently with us.

0
source share

All Articles