Overwrite contents of .debug_line section.

Summary:
Overwrite contents of .debug_line section since we don't reference
the original contents anymore. This saves ~100MB of HHVM binary.

(cherry picked from FBD3314917)
This commit is contained in:
Maksim Panchenko 2016-05-16 17:02:17 -07:00
parent e63984f325
commit f047b9d43a
2 changed files with 31 additions and 15 deletions

View File

@ -268,6 +268,7 @@ uint8_t *ExecutableFileMemoryManager::allocateSection(intptr_t Size,
return ret;
}
/// Notifier for non-allocatable (note) section.
uint8_t *ExecutableFileMemoryManager::recordNoteSection(
const uint8_t *Data,
uintptr_t Size,
@ -758,8 +759,6 @@ void RewriteInstance::readSpecialSections() {
FrameHdrAddress = Section.getAddress();
FrameHdrContents = SectionContents;
FrameHdrAlign = Section.getAlignment();
} else if (SectionName == ".debug_line") {
DebugLineSize = Section.getSize();
} else if (SectionName == ".debug_ranges") {
DebugRangesSize = Section.getSize();
} else if (SectionName == ".debug_loc") {
@ -1697,11 +1696,11 @@ void RewriteInstance::rewriteNoteSections() {
ErrorOr<StringRef> SectionName = Obj->getSectionName(&Section);
check_error(SectionName.getError(), "cannot get section name");
// Copy over section contents unless it's .debug_aranges, which shall be
// overwritten if -update-debug-sections is passed.
// New section size.
uint64_t Size = 0;
if (*SectionName != ".debug_aranges" || !opts::UpdateDebugSections) {
// Copy over section contents unless it's one of the sections we ovewrite.
if (!shouldOverwriteSection(*SectionName)) {
Size = Section.sh_size;
std::string Data = InputFile->getData().substr(Section.sh_offset, Size);
auto SectionPatchersIt = SectionPatchers.find(*SectionName);
@ -1725,7 +1724,8 @@ void RewriteInstance::rewriteNoteSections() {
// Write section extension.
Address = SI.AllocAddress;
if (Address) {
DEBUG(dbgs() << "BOLT: appending contents to section "
DEBUG(dbgs() << "BOLT: " << (Size ? "appending" : "writing")
<< " contents to section "
<< *SectionName << '\n');
OS.write(reinterpret_cast<const char *>(Address), SI.Size);
Size += SI.Size;
@ -2081,7 +2081,6 @@ void RewriteInstance::computeLineTableOffsets() {
continue;
auto Fragment = Label->getFragment();
while (&*CurrentFragment != Fragment) {
switch (CurrentFragment->getKind()) {
case MCFragment::FT_Dwarf:
@ -2096,7 +2095,6 @@ void RewriteInstance::computeLineTableOffsets() {
llvm_unreachable(".debug_line section shouldn't contain other types "
"of fragments.");
}
++CurrentFragment;
CurrentOffset = 0;
}
@ -2113,7 +2111,7 @@ void RewriteInstance::computeLineTableOffsets() {
<< "in .debug_info\n");
auto &SI = SectionMM->NoteSectionInfo[".debug_info"];
SI.PendingRelocs.emplace_back(
SectionInfo::Reloc{LTOI->second, 4, 0, Offset + DebugLineSize});
SectionInfo::Reloc{LTOI->second, 4, 0, Offset});
}
DEBUG(dbgs() << "BOLT-DEBUG: CU " << CUIDLineTablePair.first
<< " has line table at " << Offset << "\n");
@ -2326,3 +2324,14 @@ void RewriteInstance::updateDebugLineInfoForNonSimpleFunctions() {
}
}
}
bool RewriteInstance::shouldOverwriteSection(StringRef SectionName) {
if (opts::UpdateDebugSections) {
for (auto &OverwriteName : DebugSectionsToOverwrite) {
if (SectionName == OverwriteName)
return true;
}
}
return false;
}

View File

@ -179,9 +179,6 @@ public:
private:
/// Huge page size used for alignment.
static constexpr unsigned PageAlign = 0x200000;
/// Detect addresses and offsets available in the binary for allocating
/// new sections.
void discoverStorage();
@ -247,7 +244,20 @@ private:
return Address - NewTextSegmentAddress + NewTextSegmentOffset;
}
/// Return true if we should overwrite contents of the section instead
/// of appending contents to it.
bool shouldOverwriteSection(StringRef SectionName);
private:
/// If we are updating debug info, these are the section we need to overwrite.
static constexpr const char *DebugSectionsToOverwrite[] = {
".debug_aranges",
".debug_line"};
/// Huge page size used for alignment.
static constexpr unsigned PageAlign = 0x200000;
/// An instance of the input binary we are processing, externally owned.
llvm::object::ELFObjectFileBase *InputFile;
@ -306,9 +316,6 @@ private:
/// rewriting CFI info for these functions.
std::vector<uint64_t> FailedAddresses;
/// Size of the .debug_line section on input.
uint32_t DebugLineSize{0};
/// Size of the .debug_loc section in input.
uint32_t DebugLocSize{0};