@@ -757,12 +757,11 @@ Error RewriteInstance::run() {
757
757
if (opts::Instrument && !BC->IsStaticExecutable )
758
758
updateRtFiniReloc ();
759
759
760
- if (BC->IsLinuxKernel ) {
761
- errs () << " BOLT-WARNING: not writing the output file for Linux Kernel\n " ;
762
- return Error::success ();
763
- } else if (opts::OutputFilename == " /dev/null" ) {
760
+ if (opts::OutputFilename == " /dev/null" ) {
764
761
outs () << " BOLT-INFO: skipping writing final binary to disk\n " ;
765
762
return Error::success ();
763
+ } else if (BC->IsLinuxKernel ) {
764
+ errs () << " BOLT-WARNING: Linux kernel support is experimental\n " ;
766
765
}
767
766
768
767
// Rewrite allocatable contents and copy non-allocatable parts with mods.
@@ -1848,6 +1847,11 @@ Error RewriteInstance::readSpecialSections() {
1848
1847
BC->HasRelocations =
1849
1848
HasTextRelocations && (opts::RelocationMode != cl::BOU_FALSE);
1850
1849
1850
+ if (BC->IsLinuxKernel && BC->HasRelocations ) {
1851
+ outs () << " BOLT-INFO: disabling relocation mode for Linux kernel\n " ;
1852
+ BC->HasRelocations = false ;
1853
+ }
1854
+
1851
1855
BC->IsStripped = !HasSymbolTable;
1852
1856
1853
1857
if (BC->IsStripped && !opts::AllowStripped) {
@@ -4357,8 +4361,10 @@ void RewriteInstance::patchELFSectionHeaderTable(ELFObjectFile<ELFT> *File) {
4357
4361
assert ((NewEhdr.e_entry || !Obj.getHeader ().e_entry ) &&
4358
4362
" cannot find new address for entry point" );
4359
4363
}
4360
- NewEhdr.e_phoff = PHDRTableOffset;
4361
- NewEhdr.e_phnum = Phnum;
4364
+ if (PHDRTableOffset) {
4365
+ NewEhdr.e_phoff = PHDRTableOffset;
4366
+ NewEhdr.e_phnum = Phnum;
4367
+ }
4362
4368
NewEhdr.e_shoff = SHTOffset;
4363
4369
NewEhdr.e_shnum = OutputSections.size ();
4364
4370
NewEhdr.e_shstrndx = NewSectionIndex[NewEhdr.e_shstrndx ];
@@ -5493,7 +5499,8 @@ void RewriteInstance::rewriteFile() {
5493
5499
addBATSection ();
5494
5500
5495
5501
// Patch program header table.
5496
- patchELFPHDRTable ();
5502
+ if (!BC->IsLinuxKernel )
5503
+ patchELFPHDRTable ();
5497
5504
5498
5505
// Finalize memory image of section string table.
5499
5506
finalizeSectionStringTable ();
0 commit comments