comdat-folding

Relation between MSVC Compiler & linker option for COMDAT folding

泄露秘密 提交于 2019-12-23 16:18:03
问题 This question has some answers on SO but mine is slightly different. Before marking as duplicate, please give it a shot. MSVC has always provided the /Gy compiler option to enable identical functions to be folded into COMDAT sections. At the same time, the linker also provides the /OPT:ICF option. Is my understanding right that these two options must be used in conjunction? That is, while the former packages functions into COMDAT, the latter eliminates redundant COMDATs. Is that correct? If

Any way to generate warnings for function-pointer comparisons?

只愿长相守 提交于 2019-12-03 06:37:57
问题 It took me forever to track down that there was a bug in my code being triggered by /OPT:ICF : Because /OPT:ICF can cause the same address to be assigned to different functions or read-only data members (const variables compiled by using /Gy), it can break a program that depends on unique addresses for functions or read-only data members. (I had been storing and comparing function pointers for equality, which breaks when the linker throws away identical functions.) Now I need to find every

Do distinct functions have distinct addresses?

百般思念 提交于 2019-11-26 11:46:13
Consider these two functions: void foo() {} void bar() {} is it guaranteed that &foo != &bar ? Similarly, template<class T> void foo() { } is it guaranteed that &foo<int> != &foo<double> ? There are two linkers I know of that fold function definitions together. MSVC aggressively COMDAT folds functions, so two functions with the same implementation can be turned into one function. As a side effect, the two functions share the same address. I was under the impression that this was illegal, but I cannot find where in the standard it is made illegal. The Gold linker also folds functions, with both

Do distinct functions have distinct addresses?

Deadly 提交于 2019-11-26 02:20:33
问题 Consider these two functions: void foo() {} void bar() {} is it guaranteed that &foo != &bar ? Similarly, template<class T> void foo() { } is it guaranteed that &foo<int> != &foo<double> ? There are two linkers I know of that fold function definitions together. MSVC aggressively COMDAT folds functions, so two functions with the same implementation can be turned into one function. As a side effect, the two functions share the same address. I was under the impression that this was illegal, but