3.22 Segment Attribute COMDAT
With segment attribute COMDAT one may define COMDAT sections. A COMDAT section is a section that can be defined by more than one object file. A COMDAT section must contain at least one symbol, the COMDAT symbol. The syntax to define the section is:
segname SEGMENT COMDAT( selection [, assoc_segment ] ) ...
The selection argument tells the linker what to do if multiple definitions of a COMDAT symbol are found; the accepted values are:
Value | Description | |
---|---|---|
1 | no duplicates | If the symbol is already defined, the linker issues a "multiply defined symbol" error. |
2 | any | Any section that defines the same COMDAT symbol can be linked; the rest are removed. |
3 | same size | The linker chooses an arbitrary section among the definitions for this symbol. If all definitions are not the same size, a "multiply defined symbol" error is issued. |
4 | exact match | The linker chooses an arbitrary section among the definitions for this symbol. If all definitions do not match exactly, a "multiply defined symbol" error is issued. |
5 | associative | The section is linked if a certain other COMDAT section ( see the assoc_segment in the syntax description ) is linked. |
6 | largest | The linker chooses the largest definition from among all of the definitions for this symbol. If multiple definitions have this size, the choice between them is arbitrary. |
Currently support for COMDAT is restricted to COFF.
JWasm won't do anything special with COMDAT sections; in future releases this may change: cmdline options similar to the Microsoft VC compiler options -Gf or -Gy may be added.
To create an object module that places each function in its own COMDAT section ( as it is done by MS VC if the -Gy option is given ), it is recommended to use COMDAT in conjunction with ALIAS:
_TEXT_proc1 segment flat comdat(1) alias(".text")
proc1 proc c
...
proc1 endp
_TEXT1_proc1 ends
_TEXT_proc2 segment flat comdat(1) alias(".text")
proc2 proc c private
...
proc2 endp
_TEXT2_proc2 ends
_TEXT_proc3 segment flat comdat(1) alias(".text")
proc3 proc c
...
proc3 endp
_TEXT_proc3 ends