@@ -5896,6 +5896,44 @@ for data (and BSS) sections.
5896
5896
Informational sections get a default alignment of 1 byte (no
5897
5897
alignment), though the value does not matter.
5898
5898
5899
+ \b \I{comdat, win32 attribute}\c{comdat=}, followed by a number
5900
+ ("selection"), colon (acting as a separator) and a name,
5901
+ marks the section as a \I{COMDAT section, in win32}"COMDAT section".
5902
+ It allows Microsoft linkers to perform function-level linking,
5903
+ to deal with multiply defined symbols, to eliminate dead code/data.
5904
+ The "selection" number should be one of the
5905
+ \c{IMAGE_COMDAT_SELECT_*} constants from
5906
+ \W{https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/Debug/pe-format.md#comdat-sections-object-only}\c{COFF format specification};
5907
+ this value controls if the linker allows multiply defined symbols
5908
+ and how it handles them.
5909
+ The name is the \I{COMDAT symbol, in win32}"COMDAT symbol"
5910
+ - basically a new name for the section. So even though you have one
5911
+ section given by the main name (e.g. \c{.text}), it can actually
5912
+ consist of hundreds of COMDAT sections having their own name
5913
+ (and alignment).
5914
+ When the "selection" is IMAGE_COMDAT_SELECT_ASSOCIATIVE (5),
5915
+ the following name is the "COMDAT symbol" of the associated COMDAT
5916
+ section; this way you can link a piece of code or data only when
5917
+ another piece of code or data gets actually linked.
5918
+
5919
+ \> So, when linking a NASM-compiled file with some C code,
5920
+ the source may be structured as follows.
5921
+ Note that the default \c{.text} section in handled in a special
5922
+ way and it doesn't work well with \c{comdat}; you may want to append
5923
+ a \c{$} character and an arbitrary suffix to the section name.
5924
+ It will get linked into the \c{.text} section anyway - see the info on
5925
+ \W{https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/Debug/pe-format.md#grouped-sections-object-only}\c{Grouped Sections}.
5926
+
5927
+ \c section .text$1 align=16 comdat=1:FirstFnc
5928
+ \c ... ; Code linked only if referenced from C
5929
+ \c
5930
+ \c section .text$1 align=16 comdat=1:SecondFnc
5931
+ \c ... ; Code linked only if referenced from C
5932
+ \c
5933
+ \c section .rdata align=32 comdat=5:FirstFnc
5934
+ \c ... ; Data linked only if the related code (FirstFnc) is linked
5935
+ \c
5936
+
5899
5937
The defaults assumed by NASM if you do not specify the above
5900
5938
qualifiers are:
5901
5939
0 commit comments