[llvm] [BOLT] Skip functions with unsupported Linux kernel features (PR #86345)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 22 14:43:34 PDT 2024
https://github.com/maksfb created https://github.com/llvm/llvm-project/pull/86345
Do not overwrite functions with alternative and paravirtual instructions until a proper update support is implemented.
>From 26513312a5d061823afa0c5e780dfe7dc49ecc64 Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Fri, 22 Mar 2024 14:34:17 -0700
Subject: [PATCH] [BOLT] Skip functions with unsupported Linux kernel features
Do not overwrite functions with alternative and paravirtual instructions
until a proper update support is implemented.
---
bolt/lib/Rewrite/LinuxKernelRewriter.cpp | 52 +++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
index 303e8b18fd32ca..21eeecc0cb87fd 100644
--- a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
+++ b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
@@ -252,11 +252,13 @@ class LinuxKernelRewriter final : public MetadataRewriter {
/// Paravirtual instruction patch sites.
Error readParaInstructions();
+ Error rewriteParaInstructions();
Error readBugTable();
- /// Read alternative instruction info from .altinstructions.
+ /// Handle alternative instruction info from .altinstructions.
Error readAltInstructions();
+ Error rewriteAltInstructions();
/// Read .pci_fixup
Error readPCIFixupTable();
@@ -318,6 +320,12 @@ class LinuxKernelRewriter final : public MetadataRewriter {
if (Error E = rewriteExceptionTable())
return E;
+ if (Error E = rewriteAltInstructions())
+ return E;
+
+ if (Error E = rewriteParaInstructions())
+ return E;
+
if (Error E = rewriteORCTables())
return E;
@@ -1126,6 +1134,27 @@ Error LinuxKernelRewriter::readParaInstructions() {
return Error::success();
}
+Error LinuxKernelRewriter::rewriteParaInstructions() {
+ // Disable output of functions with paravirtual instructions before the
+ // rewrite support is complete.
+ for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
+ if (!BC.shouldEmit(BF))
+ continue;
+ for (const BinaryBasicBlock &BB : BF) {
+ if (!BC.shouldEmit(BF))
+ break;
+ for (const MCInst &Inst : BB) {
+ if (BC.MIB->hasAnnotation(Inst, "ParaSite")) {
+ BF.setSimple(false);
+ break;
+ }
+ }
+ }
+ }
+
+ return Error::success();
+}
+
/// Process __bug_table section.
/// This section contains information useful for kernel debugging.
/// Each entry in the section is a struct bug_entry that contains a pointer to
@@ -1305,6 +1334,27 @@ Error LinuxKernelRewriter::readAltInstructions() {
return Error::success();
}
+Error LinuxKernelRewriter::rewriteAltInstructions() {
+ // Disable output of functions with alt instructions before the rewrite
+ // support is complete.
+ for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
+ if (!BC.shouldEmit(BF))
+ continue;
+ for (const BinaryBasicBlock &BB : BF) {
+ if (!BC.shouldEmit(BF))
+ break;
+ for (const MCInst &Inst : BB) {
+ if (BC.MIB->hasAnnotation(Inst, "AltInst")) {
+ BF.setSimple(false);
+ break;
+ }
+ }
+ }
+ }
+
+ return Error::success();
+}
+
/// When the Linux kernel needs to handle an error associated with a given PCI
/// device, it uses a table stored in .pci_fixup section to locate a fixup code
/// specific to the vendor and the problematic device. The section contains a
More information about the llvm-commits
mailing list