This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Handle unclaimed PC data relocation related to jump table
Needs ReviewPublic

Authored by nhuhuan on Jul 29 2022, 7:38 PM.

Details

Summary

The limit in current implementation of jump table analysis causes some
jump tables, or parts of a jump table to be mishandled. Optimizing
functions pointing to/pointed by such jump table lead to incorrect
binaries. Therefore, some efforts are needed to handle such unclaimed
relocations.

The main idea is (a) finding the jump table base potentially associated
to the unclaimed relocation, and (b) conservatively ignoring functions
pointing to/pointed by such possible jump table entry.

To avoid skipping many unrelated functions, we only process potential
entries within a range from the jump table base.

Test Plan:

ninja check-bolt

Diff Detail

Event Timeline

nhuhuan created this revision.Jul 29 2022, 7:38 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 29 2022, 7:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 29 2022, 7:38 PM
nhuhuan updated this revision to Diff 448838.Jul 31 2022, 12:17 AM

Improve checks to reduce unnecessary ignoring of functions

nhuhuan updated this revision to Diff 448884.Jul 31 2022, 1:26 PM

Improve the acceptable range of potental jump table entry

nhuhuan updated this revision to Diff 448910.Jul 31 2022, 9:31 PM

Fixed the acceptable range

nhuhuan updated this revision to Diff 448937.Aug 1 2022, 12:53 AM

Fix misidentifying jump table entries to be ignored

tschuett added inline comments.
bolt/lib/Core/BinaryContext.cpp
774

LLVM doesn't like really unordered_set because it is expensive. Maybe you like some of the alternatives that LLVM offers:
https://llvm.org/docs/ProgrammersManual.html#set-like-containers-std-set-smallset-setvector-etc