[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 15:16:07 PDT 2024
https://github.com/maksfb updated https://github.com/llvm/llvm-project/pull/86345
>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 1/2] [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
>From 57111b4fab96d32dd5e6b1e4b74a48e02cca0d2b Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Fri, 22 Mar 2024 15:15:43 -0700
Subject: [PATCH 2/2] fixup! [BOLT] Skip functions with unsupported Linux
kernel features
---
bolt/lib/Rewrite/LinuxKernelRewriter.cpp | 41 +++++++++++-------------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
index 21eeecc0cb87fd..42df9681727590 100644
--- a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
+++ b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
@@ -256,6 +256,10 @@ class LinuxKernelRewriter final : public MetadataRewriter {
Error readBugTable();
+ /// Do no process functions containing instruction annotated with
+ /// \p Annotation.
+ void skipFunctionsWithAnnotation(StringRef Annotation) const;
+
/// Handle alternative instruction info from .altinstructions.
Error readAltInstructions();
Error rewriteAltInstructions();
@@ -1134,23 +1138,27 @@ Error LinuxKernelRewriter::readParaInstructions() {
return Error::success();
}
-Error LinuxKernelRewriter::rewriteParaInstructions() {
- // Disable output of functions with paravirtual instructions before the
- // rewrite support is complete.
+void LinuxKernelRewriter::skipFunctionsWithAnnotation(
+ StringRef Annotation) const {
for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
if (!BC.shouldEmit(BF))
continue;
for (const BinaryBasicBlock &BB : BF) {
- if (!BC.shouldEmit(BF))
+ const bool HasAnnotation = llvm::any_of(BB, [&](const MCInst &Inst) {
+ return BC.MIB->hasAnnotation(Inst, Annotation);
+ });
+ if (HasAnnotation) {
+ BF.setSimple(false);
break;
- for (const MCInst &Inst : BB) {
- if (BC.MIB->hasAnnotation(Inst, "ParaSite")) {
- BF.setSimple(false);
- break;
- }
}
}
}
+}
+
+Error LinuxKernelRewriter::rewriteParaInstructions() {
+ // Disable output of functions with paravirtual instructions before the
+ // rewrite support is complete.
+ skipFunctionsWithAnnotation("ParaSite");
return Error::success();
}
@@ -1337,20 +1345,7 @@ Error LinuxKernelRewriter::readAltInstructions() {
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;
- }
- }
- }
- }
+ skipFunctionsWithAnnotation("AltInst");
return Error::success();
}
More information about the llvm-commits
mailing list