IT lexicon › Programming › COMDAT

COMDAT

Programming På svenska → Updated: 2026-11-05

A section in an object file that the linker may discard if it already has one with the same name.

C++ comes with a built-in duplication problem. An inline function or a template instance such as std::vector<int>::push_back is emitted in every translation unit that uses it, and left alone the linker would complain about hundreds of definitions of the same symbol. The fix is to put each such function in its own COMDAT section. The linker keeps one and throws the rest away without looking inside.

The term comes from Microsoft's COFF; ELF's equivalent is section groups flagged GRP_COMDAT. The scheme assumes every copy is identical, which the one definition rule promises and nobody checks. Break the rule and the linker picks a variant by its own lights, and the bug only shows when the wrong version runs. Microsoft's /OPT:REF and /OPT:ICF also work at COMDAT granularity.

← Back to the lexicon