@@ -252,11 +252,17 @@ class LinuxKernelRewriter final : public MetadataRewriter {
252
252
253
253
// / Paravirtual instruction patch sites.
254
254
Error readParaInstructions ();
255
+ Error rewriteParaInstructions ();
255
256
256
257
Error readBugTable ();
257
258
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.
259
264
Error readAltInstructions ();
265
+ Error rewriteAltInstructions ();
260
266
261
267
// / Read .pci_fixup
262
268
Error readPCIFixupTable ();
@@ -318,6 +324,12 @@ class LinuxKernelRewriter final : public MetadataRewriter {
318
324
if (Error E = rewriteExceptionTable ())
319
325
return E;
320
326
327
+ if (Error E = rewriteAltInstructions ())
328
+ return E;
329
+
330
+ if (Error E = rewriteParaInstructions ())
331
+ return E;
332
+
321
333
if (Error E = rewriteORCTables ())
322
334
return E;
323
335
@@ -1126,6 +1138,31 @@ Error LinuxKernelRewriter::readParaInstructions() {
1126
1138
return Error::success ();
1127
1139
}
1128
1140
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
+
1129
1166
// / Process __bug_table section.
1130
1167
// / This section contains information useful for kernel debugging.
1131
1168
// / Each entry in the section is a struct bug_entry that contains a pointer to
@@ -1305,6 +1342,14 @@ Error LinuxKernelRewriter::readAltInstructions() {
1305
1342
return Error::success ();
1306
1343
}
1307
1344
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
+
1308
1353
// / When the Linux kernel needs to handle an error associated with a given PCI
1309
1354
// / device, it uses a table stored in .pci_fixup section to locate a fixup code
1310
1355
// / specific to the vendor and the problematic device. The section contains a
0 commit comments