Re: Global variable in static library - double free or corruption error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alexey Skidanov <skidanovalexey@xxxxxxxxx> writes:

> Do you mean, once I break the ODR theÂfurther behaviour is unexpected?
>
> You are right. I break it. And I would like to get linker/loader error/warning 
> as I get linkingÂtwo object files with the same global variable defined in each 
> file ( "Symbol zzz already defined" or something like that). 

You will already get an error for a multiple definition.

What is happening here is that you have two different instances of a
variable or function with vague linkage which originated in two
different sources.  Because g++ uses the Borland linking model by
default, in which symbols with vague linkage are duplicated in each .o
file which uses them, the linker can not easily determine that in this
case the symbols are an ODR violation rather than an ordinary
duplication.

The gold linker does implement a --detect-odr-violations option.
Whenever it sees a symbol with vague linkage appearing more than once,
such that the two instances have different sizes or symbol types, it
checks the debug info for the symbols.  If they originate from different
files, it issues a warning.  This approach works fairly well if the
object files are compiled with debugging information and without
optimization.  When optimization is used, there are false positives due
to confusion due to inlined functions.

Ian



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux