This is an archive of the discontinued LLVM Phabricator instance.

[SanitizerBinaryMetadata] Add !associated to dummy variable
AbandonedPublic

Authored by melver on Dec 2 2022, 12:51 PM.

Details

Reviewers
MaskRay
dvyukov
Summary

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

Diff Detail

Event Timeline

melver created this revision.Dec 2 2022, 12:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2022, 12:51 PM
melver requested review of this revision.Dec 2 2022, 12:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2022, 12:51 PM