Skip to content
Merged
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: 12 additions & 18 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4260,31 +4260,25 @@ void RewriteInstance::patchELFPHDRTable() {
const ELFFile<ELF64LE> &Obj = ELF64LEFile->getELFFile();
raw_fd_ostream &OS = Out->os();

// Write/re-write program headers.
Phnum = Obj.getHeader().e_phnum;
if (PHDRTableOffset) {
// Writing new pheader table and adding one new entry for R+X segment.
Phnum += 1;
if (NewWritableSegmentSize) {
// Adding one more entry for R+W segment.
Phnum += 1;
}
} else {

if (BC->NewSegments.empty()) {
BC->outs() << "BOLT-INFO: not adding new segments\n";
return;
}

if (opts::UseGnuStack) {
assert(!PHDRTableAddress && "unexpected address for program header table");
PHDRTableOffset = Obj.getHeader().e_phoff;
if (NewWritableSegmentSize) {
if (BC->NewSegments.size() > 1) {
BC->errs() << "BOLT-ERROR: unable to add writable segment\n";
exit(1);
}
} else {
Phnum += BC->NewSegments.size();
}

if (opts::Instrument)
Phnum += 2;

if (BC->NewSegments.empty()) {
BC->outs() << "BOLT-INFO: not adding new segments\n";
return;
}
if (!PHDRTableOffset)
PHDRTableOffset = Obj.getHeader().e_phoff;

const uint64_t SavedPos = OS.tell();
OS.seek(PHDRTableOffset);
Expand Down
Loading