This is an archive of the discontinued LLVM Phabricator instance.

[SanitizerBinaryMetadata] Declare callbacks extern weak
ClosedPublic

Authored by melver on Jan 23 2023, 2:57 PM.

Details

Summary

Declare callbacks extern weak (if no existing declaration exists), and
only call if the function address is non-null.

This allows to attach semantic metadata to binaries where no user of
that metadata exists, avoiding to have to link empty stub callbacks.

Once the binary is linked (statically or dynamically) against a tool
runtime that implements the callbacks, the respective callbacks will be
called. This vastly simplifies gradual deployment of tools using the
metadata, esp. avoiding having to recompile large codebases with
different compiler flags (which negatively impacts compiler caches).

Diff Detail

Event Timeline

melver created this revision.Jan 23 2023, 2:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 2:57 PM
melver requested review of this revision.Jan 23 2023, 2:57 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 23 2023, 2:57 PM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript
vitalybuka accepted this revision.Jan 23 2023, 3:11 PM
vitalybuka added inline comments.
llvm/lib/Transforms/Utils/ModuleUtils.cpp
181

maybe we want skip only if it's defined?
What is the reason to respect declaration?

This revision is now accepted and ready to land.Jan 23 2023, 3:11 PM
melver updated this revision to Diff 491524.Jan 23 2023, 3:27 PM

Only skip setting weak linkage if function is defined in module.

llvm/lib/Transforms/Utils/ModuleUtils.cpp
181

Right, the AsmPrinter complained on definition only:

Should never emit this
UNREACHABLE executed at /usr/local/google/home/elver/third_party/llvm/llvm-project/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:633!

Changing it to skip if definition works.

dvyukov accepted this revision.Jan 24 2023, 1:49 AM

Nice!

This revision was landed with ongoing or failed builds.Jan 24 2023, 3:55 AM
This revision was automatically updated to reflect the committed changes.