Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a 'linkonce' section

Tags:

c++

linker

What is a 'linkonce' section, and for extra kudos how does it differ from a comdat section?

To be clear, I'm familiar with how comdat sections work, how they're used, etc. In googling, linkonce is almost exclusively discussed in forums where it's assumed the meaning/intent/purpose of that section is already fairly well understood.

like image 721
Brian Vandenberg Avatar asked Apr 01 '11 19:04

Brian Vandenberg


Video Answer


1 Answers

http://gcc.gnu.org/ml/gcc/2003-09/msg00984.html seems to discuss this very thing ...

edit

To summarize:

According to that thread, COMDAT is a bit more nebulous in the sense that there's no single correct/standard definition of what constitutes a true COMDAT implementation. g++'s linkonce is /an/ implementation of the concept.

In the COMDAT implementations used by MSVC++ and Wind River's 'diab' compiler, their implementations of COMDAT allow it to remove unused sections; eg, if main.cpp links against foo.cpp, the main binary can exclude any COMDAT sections from foo.o if the section is not referenced.

I'm uncertain whether this type of folding is applied to the g++ linkonce sections, but it seems logical.

like image 102
Code Maverick Avatar answered Oct 21 '22 13:10

Code Maverick