aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Panchenko <maks@fb.com>2024-03-07 15:29:38 -0800
committerGitHub <noreply@github.com>2024-03-07 15:29:38 -0800
commita9b0d7590b9e08151243b97aa75366e988e0d6c8 (patch)
treec40e44ffb16e5e21d5e18c6674392d7e9a7f6018
parent5669660f37ef1800f4a7852577364b024d75e3d8 (diff)
downloadllvm-a9b0d7590b9e08151243b97aa75366e988e0d6c8.zip
llvm-a9b0d7590b9e08151243b97aa75366e988e0d6c8.tar.gz
llvm-a9b0d7590b9e08151243b97aa75366e988e0d6c8.tar.bz2
[BOLT] Properly propagate Cursor errors (#84378)
Handle out-of-bounds reading errors correctly in LinuxKernelRewriter.
-rw-r--r--bolt/lib/Rewrite/LinuxKernelRewriter.cpp30
-rw-r--r--bolt/test/X86/linux-alt-instruction.s5
2 files changed, 25 insertions, 10 deletions
diff --git a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
index ecfbea3..331a61e 100644
--- a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
+++ b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
@@ -500,7 +500,8 @@ Error LinuxKernelRewriter::readORCTables() {
// Consume the status of the cursor.
if (!IPCursor)
return createStringError(errc::executable_format_error,
- "out of bounds while reading ORC IP table");
+ "out of bounds while reading ORC IP table: %s",
+ toString(IPCursor.takeError()).c_str());
if (IP < PrevIP && opts::Verbosity)
BC.errs() << "BOLT-WARNING: out of order IP 0x" << Twine::utohexstr(IP)
@@ -522,7 +523,8 @@ Error LinuxKernelRewriter::readORCTables() {
// Consume the status of the cursor.
if (!ORCCursor)
return createStringError(errc::executable_format_error,
- "out of bounds while reading ORC");
+ "out of bounds while reading ORC: %s",
+ toString(ORCCursor.takeError()).c_str());
if (Entry.ORC == NullORC)
continue;
@@ -843,7 +845,8 @@ Error LinuxKernelRewriter::readStaticCalls() {
// Consume the status of the cursor.
if (!Cursor)
return createStringError(errc::executable_format_error,
- "out of bounds while reading static calls");
+ "out of bounds while reading static calls: %s",
+ toString(Cursor.takeError()).c_str());
++EntryID;
@@ -954,8 +957,10 @@ Error LinuxKernelRewriter::readExceptionTable() {
// Consume the status of the cursor.
if (!Cursor)
- return createStringError(errc::executable_format_error,
- "out of bounds while reading exception table");
+ return createStringError(
+ errc::executable_format_error,
+ "out of bounds while reading exception table: %s",
+ toString(Cursor.takeError()).c_str());
++EntryID;
@@ -1061,8 +1066,10 @@ Error LinuxKernelRewriter::readParaInstructions() {
const uint8_t Len = DE.getU8(Cursor);
if (!Cursor)
- return createStringError(errc::executable_format_error,
- "out of bounds while reading .parainstructions");
+ return createStringError(
+ errc::executable_format_error,
+ "out of bounds while reading .parainstructions: %s",
+ toString(Cursor.takeError()).c_str());
++EntryID;
@@ -1129,7 +1136,8 @@ Error LinuxKernelRewriter::readBugTable() {
if (!Cursor)
return createStringError(errc::executable_format_error,
- "out of bounds while reading __bug_table");
+ "out of bounds while reading __bug_table: %s",
+ toString(Cursor.takeError()).c_str());
++EntryID;
@@ -1196,8 +1204,10 @@ Error LinuxKernelRewriter::readAltInstructions() {
const uint8_t PadLen = opts::AltInstHasPadLen ? DE.getU8(Cursor) : 0;
if (!Cursor)
- return createStringError(errc::executable_format_error,
- "out of bounds while reading .altinstructions");
+ return createStringError(
+ errc::executable_format_error,
+ "out of bounds while reading .altinstructions: %s",
+ toString(Cursor.takeError()).c_str());
++EntryID;
diff --git a/bolt/test/X86/linux-alt-instruction.s b/bolt/test/X86/linux-alt-instruction.s
index 96e7754..5dcc6fe 100644
--- a/bolt/test/X86/linux-alt-instruction.s
+++ b/bolt/test/X86/linux-alt-instruction.s
@@ -27,6 +27,11 @@
# RUN: llvm-bolt %t.exe --print-normalized --keep-nops \
# RUN: --alt-inst-feature-size=4 -o %t.out | FileCheck %s
+## Check that out-of-bounds read is handled properly.
+
+# RUN: not llvm-bolt %t.exe --print-normalized --keep-nops \
+# RUN: --alt-inst-feature-size=2 -o %t.out
+
# CHECK: BOLT-INFO: Linux kernel binary detected
# CHECK: BOLT-INFO: parsed 2 alternative instruction entries