A deep dive into how ELF-based compilers and linkers merge potentially non-unique objects using three distinct mechanisms: compiler-level merging for initializer_list backing arrays, SHF_MERGE sections for string literals and fixed-size data, and SHF_GROUP (COMDAT) sections for inline variables and template instantiations. The post explores why GCC 16's experimental define_static_array implementation doesn't coalesce template parameter objects of array type as expected, explaining the fundamental tradeoffs between data-addressed (SHF_MERGE) and name-addressed (COMDAT) deduplication. It concludes that no existing combination of these tools achieves ideal behavior for C++26's define_static_array, and speculates on potential future linker extensions.
Table of contents
The compiler can merge similar dataSHF_MERGE sectionsSHF_MERGE | SHF_STRINGSSHF_GROUP , a.k.a. COMDAT sectionsConclusionSort: