The 0-sized dummy variable is created and added to the relevant section
so that even if there is no binary metadata generated at all, the empty
section itself would still be created by the linker and the associated
start_<section> and stop_<section> symbols. These are used by the
constructor and destructor callbacks (__sanitizer_metadata_*()), and
without the start and stop symbols would result in a linker error.
However, the section produced for the dummy variable does currently not
have the SHF_LINK_ORDER attribute. This is fine with newer linkers
(binutils >= 2.36), which can merge unordered and ordered sections [1].
We want to retain SHF_LINK_ORDER for our actual binary metadata since it
affects gc-sections behaviour [2].
However, we still want to support some older linkers. These will produce
an error such as:
/usr/bin/ld: sanmd_covered has both ordered [`sanmd_covered' in sanitize-metadata.o] and unordered [`sanmd_covered[__dummy_sanmd_covered]' in sanitize-metadata.o] sections /usr/bin/ld: final link failed: bad value
To support such linkers, add the !associated attribute to the dummy variable
which will lower to the SHF_LINK_ORDER attribute when targeting ELF.
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=26256
[2] https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order