This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Fix intermittent crash with instrumentation
ClosedPublic

Authored by maksfb on Feb 25 2023, 9:35 PM.

Details

Summary

When createInstrumentedIndirectCall() was invoked for tail calls, we
attached annotation instruction twice to the new call instruction.
First in createDirectCall(), and then again while copying over the
metadata operands.

As a result, the annotations were not properly stripped for such calls
before the call to freeAnnotations() in LowerAnnotations pass. That lead
to use-after-free while restoring the offsets with setOffset() call.

Diff Detail

Event Timeline

maksfb created this revision.Feb 25 2023, 9:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2023, 9:35 PM
Herald added a subscriber: pengfei. · View Herald Transcript
maksfb requested review of this revision.Feb 25 2023, 9:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2023, 9:35 PM
yota9 added inline comments.Feb 27 2023, 7:04 AM
bolt/include/bolt/Core/MCPlusBuilder.h
181

Maybe add assert(!getAnnotationInst(DstInst) just for extra safety

182

How about to make separate function smth like "getAnnotationOpIndex" and use it also in getAnnotationInst and stripAnnotations? Just to ensure everything is in sync

maksfb added inline comments.Feb 27 2023, 11:58 AM
bolt/include/bolt/Core/MCPlusBuilder.h
181

We have it at line 168.

182

Operand handling should be happening in MCPlusBuilder annotation interface (after this change). I can add removeAnnotationInst(), but it still will be a part of the internal interface. The direct handling of operands in createInstrumentedIndirectCall() was really unfortunate.

yota9 accepted this revision.Feb 27 2023, 12:01 PM

LGTM

This revision is now accepted and ready to land.Feb 27 2023, 12:01 PM
maksfb updated this revision to Diff 500906.Feb 27 2023, 2:08 PM

Add MCPlusBuilder::removeAnnotationInst()

This revision was landed with ongoing or failed builds.Feb 27 2023, 2:11 PM
This revision was automatically updated to reflect the committed changes.