5.5.6 COMDAT Sections (Object Only)

The Selection field of the Section Definition auxiliary format is applicable if the section is a COMDAT section: a section that can be defined by more than one object file. (The flag IMAGE_SCN_LNK_COMDAT is set in the Section Flags field of the section header.) The Selection field determines the way that the linker resolves the multiple definitions of COMDAT sections.

The first symbol having the section value of the COMDAT section must be the section symbol. This symbol has the name of the section, Value field equal to 0, the section number of the COMDAT section in question, Type field equal to IMAGE_SYM_TYPE_NULL, Class field equal to IMAGE_SYM_CLASS_STATIC, and one auxiliary record. The second symbol is called "the COMDAT symbol" and is used by the linker in conjunction with the Selection field.

Values for the Selection field are shown below.

Constant Value Description
IMAGE_COMDAT_SELECT_NODUPLICATES 1 The linker issues a multiply defined symbol error if this symbol is already defined.
IMAGE_COMDAT_SELECT_ANY 2 Any section defining the same COMDAT symbol may be linked; the rest are removed.
IMAGE_COMDAT_SELECT_SAME_SIZE 3 The linker chooses an arbitrary section among the definitions for this symbol. A multiply defined symbol error is issued if all definitions don't have the same size.
IMAGE_COMDAT_SELECT_EXACT_MATCH 4 The linker chooses an arbitrary section among the definitions for this symbol. A multiply defined symbol error is issued if all definitions don't match exactly.
IMAGE_COMDAT_SELECT_ASSOCIATIVE 5 The section is linked if a certain other COMDAT section is linked. This other section is indicated by the Number field of the auxiliary symbol record for the section definition. Use of this setting is useful for definitions that have components in multiple sections (for example, code in one and data in another), but where all must be linked or discarded as a set.
IMAGE_COMDAT_SELECT_LARGEST 6 The linker chooses the largest from the definitions for this symbol. If multiple definitions have this size the choice between them is arbitrary.