[PATCH] D139224: [SanitizerBinaryMetadata] Add !associated to dummy variable

Marco Elver via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 2 12:51:36 PST 2022


melver created this revision.
melver added reviewers: MaskRay, dvyukov.
Herald added subscribers: Enna1, StephenFan, hiraditya.
Herald added a project: All.
melver requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139224

Files:
  llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
  llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139224.479722.patch
Type: text/x-patch
Size: 84693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221202/2fe4b985/attachment.bin>


More information about the llvm-commits mailing list