-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[BOLT] Don't terminate on trap instruction for Linux kernel #87021
Conversation
Under normal circumstances, we terminate basic blocks on a trap instruction. However, Linux kernel may resume execution after hitting a trap (ud2 on x86). Thus, we introduce "--terminal-trap" option that will specify if the trap instruction should terminate the control flow. The option is on by default except for the Linux kernel mode when it's off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
return Info->get(Opcode).isTerminator() || X86::isUD1(Opcode) || | ||
X86::isUD2(Opcode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming you tested that it's safe to drop ud1/ud2 from terminators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm dropping them only for the Linux kernel. For the rest, by default they will still terminate, but the condition check is modified with isTrap()
check instead of the opcode lookup.
@@ -121,6 +130,11 @@ bool MCPlusBuilder::equals(const MCTargetExpr &A, const MCTargetExpr &B, | |||
llvm_unreachable("target-specific expressions are unsupported"); | |||
} | |||
|
|||
bool MCPlusBuilder::isTerminator(const MCInst &Inst) const { | |||
return Analysis->isTerminator(Inst) || | |||
(opts::TerminalTrap && Info->get(Inst.getOpcode()).isTrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yota9 The new code makes brk 0x3e8
Arm instruction a basic block terminator. If it's not the desired behavior, we can turn off --terminal-trap
on Arm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maksfb Hi! Currently I don't think it is a huge problem
Under normal circumstances, we terminate basic blocks on a trap instruction. However, Linux kernel may resume execution after hitting a trap (ud2 on x86). Thus, we introduce "--terminal-trap" option that will specify if the trap instruction should terminate the control flow. The option is on by default except for the Linux kernel mode when it's off.