1

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 section COMDAT with Selection IMAGE_COMDAT_SELECT_NODUPLICATES. The purpose of COMDAT is to allow something to be defined in more than one place (the linker picks one definition and discards the others), but that Selection value disallows multiple definitions, which would seem to simply undo the effect.

What exactly is the purpose of IMAGE_COMDAT_SELECT_NODUPLICATES? Or why does Microsoft C++ with /Gy mark code sections COMDAT?

rwallace
  • 31,405
  • 40
  • 123
  • 242
  • You should complain when you find more than one symbol with the same name. Just as you normally would if it wasn't in a COMDAT. This is COMDAT getting used for another purpose, allowing functions to be removed or reordered. – Hans Passant Apr 08 '14 at 13:18
  • @HansPassant But on the face of it, it would seem to be placing each function in a separate section that allows them to be removed or reordered. Why is it necessary for those sections to be flagged COMDAT? Why wouldn't it work equally well if each function was in a separate non-COMDAT section? – rwallace Apr 08 '14 at 13:56
  • No idea, this is 20+ years of history that is murky as coal. Why on Earth does it matter? – Hans Passant Apr 08 '14 at 14:04
  • @HansPassant On a general level, it gives me the unpleasant feeling that there are important gaps in my understanding of the semantics of the PE format, which could be a problem since I'm writing a linker. More specifically, I'm trying to figure out whether I can merge all the object files I read into a single big list of sections, or whether the grouping of sections into object files needs to be preserved during processing because it has semantic significance. – rwallace Apr 08 '14 at 14:34
  • Yeah, sure, pecoff is pro-forma documentation only. Most any tool builder takes the practical approach and works closely with a Microsoft guru, usually through a partnership agreement. – Hans Passant Apr 08 '14 at 14:46
  • @HansPassant Right, thus far I've been substituting Stack Overflow for that, though if you know any Microsoft gurus who would like to work with an open source project, that would definitely help! – rwallace Apr 08 '14 at 15:06

0 Answers0