[llvm] [BOLT] Add reading support for Linux kernel .altinstructions section (PR #84283)
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 7 09:41:57 PST 2024
================
@@ -1132,6 +1156,123 @@ Error LinuxKernelRewriter::readBugTable() {
return Error::success();
}
+/// The kernel can replace certain instruction sequences depending on hardware
+/// it is running on and features specified during boot time. The information
+/// about alternative instruction sequences is stored in .altinstructions
+/// section. The format of entries in this section is defined in
+/// arch/x86/include/asm/alternative.h:
+///
+/// struct alt_instr {
+/// s32 instr_offset;
+/// s32 repl_offset;
+/// uXX feature;
+/// u8 instrlen;
+/// u8 replacementlen;
+/// u8 padlen; // present in older kernels
+/// } __packed;
+///
+/// Note the structures is packed.
+Error LinuxKernelRewriter::readAltInstructions() {
+ AltInstrSection = BC.getUniqueSectionByName(".altinstructions");
+ if (!AltInstrSection)
+ return Error::success();
+
+ const uint64_t Address = AltInstrSection->getAddress();
+ DataExtractor DE = DataExtractor(AltInstrSection->getContents(),
+ BC.AsmInfo->isLittleEndian(),
+ BC.AsmInfo->getCodePointerSize());
+ uint64_t EntryID = 0;
+ DataExtractor::Cursor Cursor(0);
+ while (Cursor && !DE.eof(Cursor)) {
+ const uint64_t OrgInstAddress =
+ Address + Cursor.tell() + (int32_t)DE.getU32(Cursor);
----------------
dcci wrote:
here you're parsing a signed 32-bit value as unsigned then casting. Is it always correct?
https://github.com/llvm/llvm-project/pull/84283
More information about the llvm-commits
mailing list