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]
Other format: [Raw text]

Re: Does -gc-section (garbage collection) works only with staticlinking ?


Hi Valery,

As I understand unreachable code elimination can be only achieved with
static linking. Am I right ?

Essentially yes, but first lets be clear about one thing: We are talking about the elimination of unreachable functions, and for languages like C++, unused constructors and destructors. We are not talking about the elimination of unreachable code inside a particular function. That is the job of the compiler.


With static linking all of the references to symbols are resolved at link-time and so the linker has the opportunity to detect and eliminate unused functions. (It needs assistance from the compiler in order to do this, since the linker has no knowledge of flow control or program semantics). With dynamically linked code, some of the symbol references are left unresolved until run-time and so the linker cannot know whether a particular function is unreachable. Hence it cannot eliminate anything.

Cheers
  Nick


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