Skip to content

[BOLT] Properly propagate Cursor errors #84378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions bolt/lib/Rewrite/LinuxKernelRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions bolt/test/X86/linux-alt-instruction.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down