Grim Fandango
Grim Fandango

Reputation: 2426

is linking performance affected on whether a symbol is marked as local or global in the .obj file?

I am trying to find ways to reduce linking time for my program.

I have noticed that there are a lot of functions in my codebase, which have not been specified as static, hence they are treated as extern.

If I specify them as static, they will get internal linkage. I can verify this by running the name-mangling command on the object file (nm in linux):

Functions specified as static have a local symbol (e.g. 't') instead of a global symbol ('T').

Q: will the Linking time be notably reduced if enough symbols (functions) are converted from global (extern) to local (static)?

Q: Should I expect similar results if the objects have been created using a 'Release' compilation instead of 'Debug' compilation?

Q: Does the linkage specifier (extern/static) have any effect in the size of the object files?

Note: this question is about linking speed and object file size. It is not about the implications of having functions implicitly declared as extern.

Upvotes: 1

Views: 65

Answers (1)

Employed Russian
Employed Russian

Reputation: 213606

will the Linking time be notably reduced if enough symbols (functions) are converted from global (extern) to local (static)?

Maybe. The linker does have less work to do when lots of functions are static -- the symbol tables the linker builds will be smaller, and the lookup in them will be faster.

This is unlikely to be measurable in practice -- you'll probably have to have tens of thousands of symbols, and you'll have to convert 90% of them to static before you can actually observe the speedup.

Should I expect similar results if the objects have been created using a 'Release' compilation instead of 'Debug' compilation?

Possibly. In C++, with optimization on, a lot of functions may get inlined. This in turn leaves less work to do for the linker.

Does the linkage specifier (extern/static) have any effect in the size of the object files?

UNIX systems traditionally include local symbols in the .o for debugging, and thus extern vs. static will have no effect.

But you can use strip to remove unnecessary (for further linking) symbols, and then the .o with static functions will have smaller symbol table.

Upvotes: 1

Related Questions