Skip to content
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

[BOLT] Enable re-writing of Linux kernel binary #80228

Merged
merged 1 commit into from
Feb 1, 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
21 changes: 14 additions & 7 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,11 @@ Error RewriteInstance::run() {
if (opts::Instrument && !BC->IsStaticExecutable)
updateRtFiniReloc();

if (BC->IsLinuxKernel) {
errs() << "BOLT-WARNING: not writing the output file for Linux Kernel\n";
return Error::success();
} else if (opts::OutputFilename == "/dev/null") {
if (opts::OutputFilename == "/dev/null") {
outs() << "BOLT-INFO: skipping writing final binary to disk\n";
return Error::success();
} else if (BC->IsLinuxKernel) {
errs() << "BOLT-WARNING: Linux kernel support is experimental\n";
}

// Rewrite allocatable contents and copy non-allocatable parts with mods.
Expand Down Expand Up @@ -1860,6 +1859,11 @@ Error RewriteInstance::readSpecialSections() {
BC->HasRelocations =
HasTextRelocations && (opts::RelocationMode != cl::BOU_FALSE);

if (BC->IsLinuxKernel && BC->HasRelocations) {
outs() << "BOLT-INFO: disabling relocation mode for Linux kernel\n";
BC->HasRelocations = false;
}

BC->IsStripped = !HasSymbolTable;

if (BC->IsStripped && !opts::AllowStripped) {
Expand Down Expand Up @@ -4369,8 +4373,10 @@ void RewriteInstance::patchELFSectionHeaderTable(ELFObjectFile<ELFT> *File) {
assert((NewEhdr.e_entry || !Obj.getHeader().e_entry) &&
"cannot find new address for entry point");
}
NewEhdr.e_phoff = PHDRTableOffset;
NewEhdr.e_phnum = Phnum;
if (PHDRTableOffset) {
NewEhdr.e_phoff = PHDRTableOffset;
NewEhdr.e_phnum = Phnum;
}
NewEhdr.e_shoff = SHTOffset;
NewEhdr.e_shnum = OutputSections.size();
NewEhdr.e_shstrndx = NewSectionIndex[NewEhdr.e_shstrndx];
Expand Down Expand Up @@ -5505,7 +5511,8 @@ void RewriteInstance::rewriteFile() {
addBATSection();

// Patch program header table.
patchELFPHDRTable();
if (!BC->IsLinuxKernel)
patchELFPHDRTable();

// Finalize memory image of section string table.
finalizeSectionStringTable();
Expand Down
2 changes: 2 additions & 0 deletions bolt/test/X86/linux-orc.s
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ bar:
.L4:
.size bar, .-bar

# CHECK: BOLT-WARNING: Linux kernel support is experimental

.section .orc_unwind,"a",@progbits
.align 4
.section .orc_unwind_ip,"a",@progbits
Expand Down
Loading