This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: Coding error causes odd error message.


> What does g++ do if the code is written so that all of the
> virtual methods are written as if they were inlined?  How
> does the compiler know when to generate the functions out
> of line?

I can't give a complete and correct answer here, it also changes
between versions, and depending on the platform.

First of all, they are only emitted when they are used. A virtual
function is used when the vtable of the class is emitted. A vtable
is emitted if it is used in a constructor or destructor.

On ELF systems, g++ emits each such function (as well as virtual
tables, implicit constructors, and template instantiations) into
individual object file sections, named .gnu.linkonce.*. These symbols
are marked as weak, the linkonce flag is set on the symbol, and data
are marked as common.

When linking, a linker might find duplicates. If these are data
duplicates, it will check whether they are same-sized and identically
initialized, and remove the duplicates. For functions, the linker will
chose one of the weak versions. The GNU linker will also remove the
link-once duplicates.

On other systems, duplicates are emitted into each object file. They
are marked static so that the compiler does not complain.

Generation can be controlled using various options. In particular,
#pragma interface tells the compiler not to emit, unless it also sees
#pragma implementation. Similarly, -fimplement-inlines can be used
to guide generation.

Hope this helps,
Martin


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