Skip to content

Commit 56197d7

Browse files
authored
[BOLT] Skip functions with unsupported Linux kernel features (llvm#86345)
Do not overwrite functions with alternative and paravirtual instructions until a proper update support is implemented.
1 parent b1e97d6 commit 56197d7

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

bolt/lib/Rewrite/LinuxKernelRewriter.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,17 @@ class LinuxKernelRewriter final : public MetadataRewriter {
252252

253253
/// Paravirtual instruction patch sites.
254254
Error readParaInstructions();
255+
Error rewriteParaInstructions();
255256

256257
Error readBugTable();
257258

258-
/// Read alternative instruction info from .altinstructions.
259+
/// Do no process functions containing instruction annotated with
260+
/// \p Annotation.
261+
void skipFunctionsWithAnnotation(StringRef Annotation) const;
262+
263+
/// Handle alternative instruction info from .altinstructions.
259264
Error readAltInstructions();
265+
Error rewriteAltInstructions();
260266

261267
/// Read .pci_fixup
262268
Error readPCIFixupTable();
@@ -318,6 +324,12 @@ class LinuxKernelRewriter final : public MetadataRewriter {
318324
if (Error E = rewriteExceptionTable())
319325
return E;
320326

327+
if (Error E = rewriteAltInstructions())
328+
return E;
329+
330+
if (Error E = rewriteParaInstructions())
331+
return E;
332+
321333
if (Error E = rewriteORCTables())
322334
return E;
323335

@@ -1126,6 +1138,31 @@ Error LinuxKernelRewriter::readParaInstructions() {
11261138
return Error::success();
11271139
}
11281140

1141+
void LinuxKernelRewriter::skipFunctionsWithAnnotation(
1142+
StringRef Annotation) const {
1143+
for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
1144+
if (!BC.shouldEmit(BF))
1145+
continue;
1146+
for (const BinaryBasicBlock &BB : BF) {
1147+
const bool HasAnnotation = llvm::any_of(BB, [&](const MCInst &Inst) {
1148+
return BC.MIB->hasAnnotation(Inst, Annotation);
1149+
});
1150+
if (HasAnnotation) {
1151+
BF.setSimple(false);
1152+
break;
1153+
}
1154+
}
1155+
}
1156+
}
1157+
1158+
Error LinuxKernelRewriter::rewriteParaInstructions() {
1159+
// Disable output of functions with paravirtual instructions before the
1160+
// rewrite support is complete.
1161+
skipFunctionsWithAnnotation("ParaSite");
1162+
1163+
return Error::success();
1164+
}
1165+
11291166
/// Process __bug_table section.
11301167
/// This section contains information useful for kernel debugging.
11311168
/// Each entry in the section is a struct bug_entry that contains a pointer to
@@ -1305,6 +1342,14 @@ Error LinuxKernelRewriter::readAltInstructions() {
13051342
return Error::success();
13061343
}
13071344

1345+
Error LinuxKernelRewriter::rewriteAltInstructions() {
1346+
// Disable output of functions with alt instructions before the rewrite
1347+
// support is complete.
1348+
skipFunctionsWithAnnotation("AltInst");
1349+
1350+
return Error::success();
1351+
}
1352+
13081353
/// When the Linux kernel needs to handle an error associated with a given PCI
13091354
/// device, it uses a table stored in .pci_fixup section to locate a fixup code
13101355
/// specific to the vendor and the problematic device. The section contains a

0 commit comments

Comments
 (0)