question about linking

Started by
2 comments, last by Bregma 9 years, 9 months ago

I always do not know this - If i link many object modules (or library) and thay contain the functions that are not called from my code will they be linked to or stripped out form final exe? Thare maybe may be some differences in behavoiur of modules and libraries but im not sure..

?

Advertisement

If you're talking about static libs, then the behavior depends on the compiler toolchain you're using as well as the settings provided for the linker. In Visual C++ for instance, dead-code stripping is controlled by the /OPT:REF command-line option.

c standard is not saying something? or some common rule - that it is linked in or not?

c standard is not saying something? or some common rule - that it is linked in or not?

"Linking" is not a concept addressed by the language standard, no. There is no requirement in the language standard that a system offer separate compilation of modules, and indeed there are embedded systems that do not.

Practically, though, most modern (post-1960s at least) linkers will normally only satisfy undefined symbols from a static archive (library). Dynamic shared objects (DLLs, .so files, .dylibs and so on) are loaded by the dynamic link-loader in their entirety, just as an executable is, but their symbol relocation tables may not be resolve until required (so-called "lazy" loading). Command-line options can be used to vary that behaviour (eg. --Wl,-whole-archive passed to GCC).

Symbols from object modules may also have unreferenced symbols stripped. That's going to depend on your linker and likely on the options passed o the linker.

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement