Skip to content

[BOLT] Add reading support for Linux kernel .altinstructions section #84283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

maksfb
Copy link
Contributor

@maksfb maksfb commented Mar 7, 2024

Read .altinstructions and annotate instructions that have alternative sequences with "AltInst" annotation. Note that some instructions may have more than one alternatives, in which case they will have multiple annotations in the form "AltInst", "AltInst2", "AltInst3", etc.

Read .altinstructions and annotate instructions that have alternative
sequences with "AltInst" annotation. Note that some instructions may
have more than one alternatives, in which case they will have multiple
annotations in the form "AltInst", "AltInst2", "AltInst3", etc.
@maksfb
Copy link
Contributor Author

maksfb commented Mar 7, 2024

Need to add a test case.


static cl::opt<bool>
DumpAltInstructions("dump-alt-instructions",
cl::desc("dump Linux alernative instructions info"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: alternative.

DataExtractor::Cursor Cursor(0);
while (Cursor && !DE.eof(Cursor)) {
const uint64_t OrgInstAddress =
Address + Cursor.tell() + (int32_t)DE.getU32(Cursor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you're parsing a signed 32-bit value as unsigned then casting. Is it always correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That's what DataExtractor::getSigned() does underneath. I would have used it, but there's no Cursor version of this interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't coding guide prefers using c++ style casting?
https://llvm.org/docs/CodingStandards.html#prefer-c-style-casts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule lists an exception for integral type casts.

/// struct alt_instr {
/// s32 instr_offset;
/// s32 repl_offset;
/// uXX feature;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does uXX stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u16 or u32. Perhaps u64 in the future.

@maksfb maksfb force-pushed the gh-alt-instructions branch from 31de825 to 100df3d Compare March 7, 2024 19:31
Copy link
Member

@dcci dcci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. (I already reviewed it -- appreciate you clarifying my comments). Thanks for adding a test.

@maksfb
Copy link
Contributor Author

maksfb commented Mar 7, 2024

Thanks for the review.

@maksfb maksfb merged commit 143afb4 into llvm:main Mar 7, 2024
@maksfb maksfb deleted the gh-alt-instructions branch March 28, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants