This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Disable -lite when split function is present
ClosedPublic

Authored by nhuhuan on Aug 5 2022, 12:52 PM.

Details

Summary

In lite mode, BOLT only transforms a subset of functions, leave the
remaining functions intact.

For NoPIC, it is fine. BOLT can scan relocations and fix-up all refs
that point to any function body in the subset.

For no-split function PIC, it is fine. Since jump tables are intra-
procedural transfer, BOLT can find both the jump table base and the
target within same function. Thus, BOLT can update and/or move jump
tables.

However, it is wrong to process a subset of functions in split function
PIC. This is because BOLT does not know if functions in the subset are
isolated, i.e., cannot be accessed by functions out of the subset,
especially via split jump table.

For example, BOLT only process three functions A, B and C. Suppose that
A is reached via jump table from A.cold, which is not processed. When
A is moved (due to optimization), the jump table in A.cold is invalid.
We cannot fix-up this jump table since it is only recognized in A.cold,
which BOLT does not process.

Solution: Disable lite mode if split function is present.

Future improvement: In lite mode, if split function is found, BOLT
processes both functions in the subset and all of their sibling
fragments.

Test Plan:

ninja check-bolt

Diff Detail

Event Timeline

nhuhuan created this revision.Aug 5 2022, 12:52 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.Aug 5 2022, 12:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 12:52 PM
Amir added inline comments.Aug 5 2022, 2:14 PM
bolt/lib/Rewrite/RewriteInstance.cpp
1436

Let's move it under !PrintedWarning to only print it once.

nhuhuan updated this revision to Diff 450419.Aug 5 2022, 2:47 PM

Avoid printing duplicate warnings.

nhuhuan updated this revision to Diff 450420.Aug 5 2022, 2:49 PM

Clang-formatted.

nhuhuan marked an inline comment as done.Aug 5 2022, 2:49 PM
Amir accepted this revision.Aug 5 2022, 3:01 PM

Thanks!

This revision is now accepted and ready to land.Aug 5 2022, 3:01 PM
maksfb requested changes to this revision.Aug 5 2022, 3:03 PM
maksfb added inline comments.
bolt/lib/Rewrite/RewriteInstance.cpp
1440

Check if the lite mode is enabled before issuing the warning.

This revision now requires changes to proceed.Aug 5 2022, 3:03 PM
nhuhuan updated this revision to Diff 450433.Aug 5 2022, 3:26 PM

Check before issue the warning.

nhuhuan marked an inline comment as done.Aug 5 2022, 3:27 PM
maksfb accepted this revision.Aug 5 2022, 3:50 PM
maksfb added inline comments.
bolt/lib/Rewrite/RewriteInstance.cpp
1442

nit: drop the trailing period.

This revision is now accepted and ready to land.Aug 5 2022, 3:50 PM
nhuhuan updated this revision to Diff 450445.Aug 5 2022, 4:21 PM

Remove trailing dots.

nhuhuan marked an inline comment as done.Aug 5 2022, 4:22 PM
This revision was automatically updated to reflect the committed changes.