This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Ignore functions accessing false positive jump tables
ClosedPublic

Authored by nhuhuan on Jul 23 2022, 2:20 PM.

Details

Summary

Disassembly and branch target analysis are not decoupled, so any
analysis that depends on disassembly may not operate properly.

In specific, analyzeJumpTable uses instruction bounds check property.
A jump table was analyzed twice: (a) during disassembly, and (b) after
disassembly, so there are potentially some mismatched results.

In this update, functions that access JTs which fail the second check
will be marked as ignored.

Test Plan:

ninja check-bolt

Diff Detail

Event Timeline

nhuhuan created this revision.Jul 23 2022, 2:20 PM
Herald added a reviewer: Amir. · View Herald Transcript
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: ayermolo. · View Herald Transcript
nhuhuan requested review of this revision.Jul 23 2022, 2:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2022, 2:20 PM
nhuhuan edited the summary of this revision. (Show Details)Jul 23 2022, 2:25 PM
Amir added a comment.Jul 25 2022, 12:19 PM

Good findings, and the code looks good generally.
The summary lists three separate issues, can you please split up this diff so that each is addressed separately?

bolt/lib/Core/BinaryContext.cpp
623

Please add a context for this vector (e.g. "collect jump tables that failed analyzeJumpTable checks") and run clang-format on this commit.

704
nhuhuan updated this revision to Diff 448194.Jul 27 2022, 4:00 PM

Split this diff into a few diffs.

nhuhuan updated this revision to Diff 448197.Jul 27 2022, 4:03 PM
nhuhuan marked an inline comment as done.

Add description for AbortedJTs

nhuhuan marked an inline comment as done.Jul 27 2022, 4:04 PM
nhuhuan retitled this revision from [BOLT] Fix split jump table issues to [BOLT] Handle false positive jump tables.Jul 27 2022, 4:07 PM
nhuhuan edited the summary of this revision. (Show Details)
nhuhuan updated this revision to Diff 448209.Jul 27 2022, 4:34 PM

Added the manual test back

Amir accepted this revision.Jul 28 2022, 11:01 PM

LGTM

This revision is now accepted and ready to land.Jul 28 2022, 11:01 PM
Amir added a comment.Jul 28 2022, 11:03 PM

Let's retitle as "[BOLT] Ignore functions accessing false positive jump tables"

nhuhuan retitled this revision from [BOLT] Handle false positive jump tables to [BOLT] Ignore functions accessing false positive jump tables.Jul 28 2022, 11:08 PM
This revision was automatically updated to reflect the committed changes.
Amir added inline comments.Aug 4 2022, 11:35 PM
bolt/lib/Core/BinaryContext.cpp
673

Sorry, let's not reland this diff.
We want to preserve this llvm_unreachable here to crash in cases we failed to recognize the jump table.