Questions tagged [comdat-folding]
6 questions
59
votes
4 answers
Do distinct functions have distinct addresses?
Consider these two functions:
void foo() {}
void bar() {}
is it guaranteed that &foo != &bar?
Similarly,
template void foo() { }
is it guaranteed that &foo != &foo?
There are two linkers I know of that fold function…

Yakk - Adam Nevraumont
- 262,606
- 27
- 330
- 524
29
votes
1 answer
Any way to generate warnings for function-pointer comparisons?
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…

user541686
- 205,094
- 128
- 528
- 886
6
votes
2 answers
Relation between MSVC Compiler & linker option for COMDAT folding
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…

ForeverLearning
- 6,352
- 3
- 27
- 33
2
votes
0 answers
Can a compiler elide the bodies of functions that are address-taken but never called?
Background information
Consider this simplified implementation of std::any (irrelevant parts omitted) and some code that uses it:
namespace std {
namespace details {
// Each instance of this function template has a different address
…

fghzxm
- 1,185
- 7
- 19
1
vote
0 answers
Purpose of IMAGE_COMDAT_SELECT_NODUPLICATES
Microsoft C++ with the /Gy option will place every function in a different section so that the linker can omit unused functions, which may reduce the executable size.
In addition to placing every function in a different section, it also marks each…

rwallace
- 31,405
- 40
- 123
- 242
1
vote
1 answer
COMDAT section name
I'm writing a linker for Windows binaries, and currently working on implementing COMDAT. I think I understand most of the specification, except that of the three records for a COMDAT section (the section header, section symbols and auxiliary…

rwallace
- 31,405
- 40
- 123
- 242