[BOLT][DWARF] Force allocation of debug_line in RuntimeDyld

Summary:
Currently, RuntimeDyld will not allocate a section without relocations
even if such a section is marked allocatable and defines symbols.

When we emit .debug_line for compile units with unchanged code, we
output original (input) data, without relocations. If all units are
emitted in this way, we will have no relocations in the emitted
.debug_line. RuntimeDyld will not allocate the section and as a result
we will write an empty .debug_line section.

To workaround the issue, always emit a relocation of RELOC_NONE type
when emitting raw contents to debug_line.

(cherry picked from FBD32909869)
This commit is contained in:
Maksim Panchenko
2021-12-06 23:32:40 -08:00
parent cbf530bf41
commit b73c87bc4f
4 changed files with 38 additions and 3 deletions

View File

@@ -782,7 +782,8 @@ static inline void emitDwarfLineTable(
}
void DwarfLineTable::emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params,
Optional<MCDwarfLineStr> &LineStr) const {
Optional<MCDwarfLineStr> &LineStr,
BinaryContext &BC) const {
if (!RawData.empty()) {
assert(MCLineSections.getMCLineEntries().empty() &&
InputSequences.empty() &&
@@ -790,6 +791,14 @@ void DwarfLineTable::emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params,
MCOS->emitLabel(getLabel());
MCOS->emitBytes(RawData);
// Emit fake relocation for RuntimeDyld to always allocate the section.
//
// FIXME: remove this once RuntimeDyld stops skipping allocatable sections
// without relocations.
MCOS->emitRelocDirective(
*MCConstantExpr::create(0, *BC.Ctx), "BFD_RELOC_NONE",
MCSymbolRefExpr::create(getLabel(), *BC.Ctx), SMLoc(), *BC.STI);
return;
}
@@ -830,7 +839,7 @@ void DwarfLineTable::emit(BinaryContext &BC, MCStreamer &Streamer) {
// Handle the rest of the Compile Units.
for (auto &CUIDTablePair : LineTables) {
CUIDTablePair.second.emitCU(&Streamer, Params, LineStr);
CUIDTablePair.second.emitCU(&Streamer, Params, LineStr, BC);
}
}