[llvm] [BOLT] Fix shifted DWARF inline-scope ranges; track scope boundaries (PR #207291)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 15:50:59 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Rafael Auler (rafaelauler)
<details>
<summary>Changes</summary>
Summary:
BOLT updated DWARF lexical-scope ranges (DW_TAG_inlined_subroutine / lexical_block low_pc/high_pc and DW_AT_ranges) via translateInputToOutputRange(), which mapped a boundary using its input offset relative to the start of the containing basic block:
OutAddr = BB.getOutputAddressRange().first + (InputOffset - BB.getOffset())
This assumes intra-block byte offsets are preserved input->output. Any pass that changes instruction sizes within a block ahead of a scope boundary breaks that assumption. With --plt=all, each `call foo@<!-- -->PLT` (5 bytes, e8+rel32) is rewritten to `call *foo@<!-- -->GOT(%rip)` (6 bytes, ff 15+rel32); N such calls before a boundary shift its emitted low_pc/ high_pc N bytes too early, onto the preceding instruction. The range stays within the parent so `llvm-dwarfdump --verify` does not catch it; symbolizers then attribute samples on those instructions to the wrong inlined frames.
Fix is to resolve scope-range boundaries through the precise per-instruction input-to-output AddressMap (the same map BAT already uses) instead of input-relative block offsets. Boundary instructions are arbitrary (not just calls/branches), so they are normally absent from that map; to make them resolvable, disassembly now keeps an offset for the boundary instructions (only the boundaries, to keep the AddressMap small) and those offsets are emitted as AddressMap entries whenever an address map is required (requiresAddressMap(), which includes --update-debug-sections via requiresPreciseAddressMap()), not only under BAT.
Boundary collection (BinaryContext::collectDebugScopeBoundaries) runs in readDebugInfo() after preprocessDebugInfo(). It streams the DIEs of the CUs that will be updated directly from the already-loaded DWARFContext with DWARFDebugInfoEntry::extractFast, decoding one DIE at a time into a single reusable entry, so no DIE forest is materialized and no second DWARF context is created. For split DWARF the .dwo DIEs are already extracted by preprocessDWODebugInfo(), so the cached array is reused instead. Boundaries are stored per function in a sorted, deduplicated vector (BinaryFunction::DebugScopeBoundaryOffsets), queried during disassembly with a monotonic cursor, and freed once the function is disassembled, so the feature adds no global state.
The behavior is on by default and can be disabled with --accurate-debug-ranges=0, which falls back to the old block-relative mapping.
Test on big binaries with split dwarf, -lite=0:
wall Max RSS
-accurate-debug-ranges=0 1070.1s 94.91
-accurate-debug-ranges=1 1173.0s 100.07
delta +102.9s +5.16 (+4.6% CPU,
+5.4% RSS)
Test on big binaries with split dwarf, lite=1:
-accurate-debug-ranges=0 433.9s 83.23
-accurate-debug-ranges=1 434.7s 83.79 (+0.7% RSS)
--time-rewrite shows the boundary-collection phase itself is cheap:
"read debug ranges" is 5.8s of 4960s total user time on one binary
(0.1%) and 18.8s of 6307s on another binary; the feature's
cost is dominated by emitting/translating the extra AddressMap entries,
not by collection.
---
Patch is 47.94 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/207291.diff
7 Files Affected:
- (modified) bolt/include/bolt/Core/BinaryContext.h (+5-10)
- (modified) bolt/include/bolt/Core/BinaryFunction.h (+54-4)
- (modified) bolt/lib/Core/BinaryContext.cpp (+81)
- (modified) bolt/lib/Core/BinaryEmitter.cpp (+4-2)
- (modified) bolt/lib/Core/BinaryFunction.cpp (+42-12)
- (modified) bolt/lib/Rewrite/RewriteInstance.cpp (+14)
- (added) bolt/test/X86/dwarf-inline-range-plt-shift.s (+614)
``````````diff
diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h
index 73ccb911039de..670832288ecbd 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -1446,6 +1446,11 @@ class BinaryContext {
/// Populate some internal data structures with debug info.
void preprocessDebugInfo();
+ /// Record DWARF lexical-scope range boundaries into the containing functions'
+ /// BinaryFunction::DebugScopeBoundaryOffsets. Relies on preprocessDebugInfo's
+ /// actions: populated ProcessedCUs and pre-extracted DIEs for split dwarf.
+ void collectDebugScopeBoundaries();
+
/// Add a filename entry from SrcCUID to DestCUID.
unsigned addDebugFilenameToUnit(const uint32_t DestCUID,
const uint32_t SrcCUID, unsigned FileIndex);
@@ -1513,16 +1518,6 @@ class BinaryContext {
/// count of profiled functions.
uint64_t getHotThreshold() const;
- /// Return true if instruction \p Inst requires an offset for further
- /// processing (e.g. assigning a profile).
- bool keepOffsetForInstruction(const MCInst &Inst) const {
- if (MIB->isCall(Inst) || MIB->isBranch(Inst) || MIB->isReturn(Inst) ||
- MIB->isPrefix(Inst) || MIB->isIndirectBranch(Inst)) {
- return true;
- }
- return false;
- }
-
/// Return true if the function should be emitted to the output file.
bool shouldEmit(const BinaryFunction &Function) const;
diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index 84fbd5661fd0a..df42eecb98512 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -295,6 +295,18 @@ class BinaryFunction {
/// Offsets of indirect branches with unknown destinations.
std::set<uint64_t> UnknownIndirectBranchOffsets;
+ /// Offsets of instructions that begin or end a DWARF lexical scope
+ /// (inlined_subroutine / lexical_block low_pc/high_pc and DW_AT_ranges).
+ /// Populated (unsorted, with possible duplicates) before disassembly, sorted
+ /// and deduplicated at the start of disassembly, and cleared once disassembly
+ /// of this function is done.
+ std::vector<uint64_t> DebugScopeBoundaryOffsets;
+
+ /// Cursor into the sorted DebugScopeBoundaryOffsets. Disassembly queries
+ /// offsets in monotonically increasing order, so isDebugScopeBoundaryOffset()
+ /// advances this cursor instead of binary-searching from scratch.
+ size_t DebugScopeBoundaryCursor = 0;
+
/// A set of local and global symbols corresponding to secondary entry points.
/// Each additional function entry point has a corresponding entry in the map.
/// The key is a local symbol corresponding to a basic block and the value
@@ -1348,6 +1360,42 @@ class BinaryFunction {
return InternalRefDataRelocations;
}
+ /// Append function-relative \p Offset as a DWARF lexical-scope boundary. The
+ /// list is sorted later (sortDebugScopeBoundaryOffsets) before it is queried.
+ void addDebugScopeBoundaryOffset(uint64_t Offset) {
+ DebugScopeBoundaryOffsets.push_back(Offset);
+ }
+
+ /// Sort and deduplicate the collected scope boundaries and reset the query
+ /// cursor. Call once, before the first isDebugScopeBoundaryOffset() query.
+ void sortDebugScopeBoundaryOffsets() {
+ llvm::sort(DebugScopeBoundaryOffsets);
+ DebugScopeBoundaryOffsets.erase(llvm::unique(DebugScopeBoundaryOffsets),
+ DebugScopeBoundaryOffsets.end());
+ DebugScopeBoundaryCursor = 0;
+ }
+
+ /// Return true if function-relative \p Offset begins/ends a DWARF scope.
+ /// Requires sortDebugScopeBoundaryOffsets() to have been called, and that
+ /// queries arrive with non-decreasing \p Offset. This is designed to be
+ /// used in lock-step with the disassembly loop, don't use it outside of it.
+ bool isDebugScopeBoundaryOffset(uint64_t Offset) {
+ const size_t Size = DebugScopeBoundaryOffsets.size();
+ while (DebugScopeBoundaryCursor < Size &&
+ DebugScopeBoundaryOffsets[DebugScopeBoundaryCursor] < Offset)
+ ++DebugScopeBoundaryCursor;
+ return DebugScopeBoundaryCursor < Size &&
+ DebugScopeBoundaryOffsets[DebugScopeBoundaryCursor] == Offset;
+ }
+
+ /// Return true if an "Offset" annotation should be kept for instruction
+ /// \p Inst located at function-relative \p Offset. Offsets are kept for
+ /// control-flow instructions (profile matching) and for instructions that
+ /// begin/end a DWARF lexical scope (needed to translate scope ranges
+ /// precisely; see DebugScopeBoundaryOffsets).
+ bool keepOffsetForInstruction(const MCInst &Inst,
+ uint64_t Offset);
+
/// Return the name of the section this function originated from.
std::optional<StringRef> getOriginSectionName() const {
if (!OriginSection)
@@ -2439,15 +2487,17 @@ class BinaryFunction {
/// is corrupted. If it is unable to fix it, it returns false.
bool finalizeCFIState();
- /// Return true if this function needs an address-translation table after
- /// its code emission.
- bool requiresAddressTranslation() const;
-
/// Return true if the linker needs to generate an address map for this
/// function. Used for keeping track of the mapping from input to out
/// addresses of basic blocks.
bool requiresAddressMap() const;
+ /// Return true if this function needs an address-translation table after
+ /// its code emission, or to update any metadata accurately (debug info,
+ /// SDT probes). This is gated since it incurs extra cost for the linker
+ /// to keep track of more addresses.
+ bool requiresPreciseAddressMap() const;
+
/// Adjust branch instructions to match the CFG.
///
/// As it comes to internal branches, the CFG represents "the ultimate source
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index 130c523bcda54..9d07775508da6 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -49,6 +49,7 @@ using namespace llvm;
namespace opts {
extern cl::opt<bool> LargeCodeModel;
+extern cl::opt<bool> UpdateDebugSections;
static cl::opt<bool>
NoHugePages("no-huge-pages",
@@ -1962,6 +1963,86 @@ void BinaryContext::preprocessDebugInfo() {
}
}
+void BinaryContext::collectDebugScopeBoundaries() {
+ // Record DWARF lexical-scope boundaries (inlined_subroutine / lexical_block)
+ // into each containing BinaryFunction, so disassembly keeps an offset for the
+ // boundary instructions (see BinaryFunction::DebugScopeBoundaryOffsets) and
+ // translateInputToOutputRange() can map scope ranges precisely.
+
+ auto recordRange = [&](uint64_t LowPC, uint64_t HighPC) {
+ BinaryFunction *BF = getBinaryFunctionContainingAddress(LowPC);
+ if (!BF)
+ return;
+ BF->addDebugScopeBoundaryOffset(LowPC - BF->getAddress());
+ // Mark HighPC only if it lies strictly inside the same function.
+ if (HighPC > LowPC && getBinaryFunctionContainingAddress(HighPC) == BF)
+ BF->addDebugScopeBoundaryOffset(HighPC - BF->getAddress());
+ };
+
+ // Record the boundaries of a single scope DIE.
+ auto processScopeDie = [&](const DWARFDie &Die) {
+ const dwarf::Tag Tag = Die.getTag();
+ if (Tag != dwarf::DW_TAG_inlined_subroutine &&
+ Tag != dwarf::DW_TAG_lexical_block &&
+ Tag != dwarf::DW_TAG_try_block &&
+ Tag != dwarf::DW_TAG_catch_block)
+ return;
+ if (Expected<DWARFAddressRangesVector> Ranges = Die.getAddressRanges()) {
+ for (const DWARFAddressRange &R : *Ranges)
+ recordRange(R.LowPC, R.HighPC);
+ } else {
+ consumeError(Ranges.takeError());
+ }
+ };
+
+ for (const std::unique_ptr<DWARFUnit> &CUPtr : DwCtx->compile_units()) {
+ DWARFUnit *CU = CUPtr.get();
+ if (!ProcessedCUs.count(CU))
+ continue;
+
+ // Extract only the CU DIE (the .dwo's, for split DWARF). This is cheap (one
+ // DIE) and sets the unit's range/addr/str-offset bases that getAddressRanges
+ // needs, without materializing the full DIE array.
+ DWARFDie CUDie = CU->getNonSkeletonUnitDIE(/*ExtractUnitDIEOnly=*/true);
+ if (!CUDie)
+ continue;
+ DWARFUnit *DIEUnit = CUDie.getDwarfUnit();
+
+ // For split DWARF, preprocessDWODebugInfo already fully extracts the .dwo's
+ // DIE array.
+ if (DIEUnit->isDWOUnit()) {
+ for (const DWARFDebugInfoEntry &Entry : DIEUnit->dies())
+ processScopeDie(DWARFDie(DIEUnit, &Entry));
+ continue;
+ }
+ // Walk the unit's DIEs by streaming them one at a time. Track nesting depth
+ // with a counter: a DIE with children descends a level (++), a null entry
+ // (sibling-chain terminator) ascends (--), the unit-end offset limits the
+ // walk. This is done to avoid recording all DIEs in a vector like
+ // DWARFUnit's extractDIEsToVector() does, since that is more work than
+ // needed if we just want to lookup specific tags.
+ DWARFDataExtractor DebugInfoData = DIEUnit->getDebugInfoExtractor();
+ uint64_t DIEOffset = DIEUnit->getOffset() + DIEUnit->getHeaderSize();
+ const uint64_t NextCUOffset = DIEUnit->getNextUnitOffset();
+ DWARFDebugInfoEntry DIEEntry;
+ int32_t CurrentDepth = 1;
+ while (CurrentDepth > 0 && DIEOffset < NextCUOffset &&
+ DIEEntry.extractFast(*DIEUnit, &DIEOffset, DebugInfoData,
+ NextCUOffset, 0)) {
+ const DWARFAbbreviationDeclaration *Abbrev =
+ DIEEntry.getAbbreviationDeclarationPtr();
+ if (!Abbrev) {
+ // End of the current sibling chain.
+ --CurrentDepth;
+ continue;
+ }
+ processScopeDie(DWARFDie(DIEUnit, &DIEEntry));
+ if (Abbrev->hasChildren())
+ ++CurrentDepth;
+ }
+ }
+}
+
bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {
if (Function.isPseudo())
return false;
diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp
index a555c7185448e..9243b6701b918 100644
--- a/bolt/lib/Core/BinaryEmitter.cpp
+++ b/bolt/lib/Core/BinaryEmitter.cpp
@@ -481,8 +481,10 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
}
// Prepare to tag this location with a label if we need to keep track of
- // the location of calls/returns for BOLT address translation maps
- if (BF.requiresAddressTranslation() && BC.MIB->getOffset(Instr)) {
+ // an instruction's output address to augment the IO address map (BAT,
+ // SDT/probe address translation, or --update-debug-sections DWARF range
+ // updates).
+ if (BF.requiresPreciseAddressMap() && BC.MIB->getOffset(Instr)) {
const uint32_t Offset = *BC.MIB->getOffset(Instr);
if (!InstrLabel)
InstrLabel = BC.Ctx->createTempSymbol();
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 200e286d8e80e..6c23bbd1ff8c8 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1302,6 +1302,15 @@ BinaryFunction::getInstructionSequenceLength(uint64_t Offset,
return Current - Offset;
}
+bool BinaryFunction::keepOffsetForInstruction(const MCInst &Inst,
+ uint64_t Offset) {
+ MCPlusBuilder &MIB = *BC.MIB;
+ if (MIB.isCall(Inst) || MIB.isBranch(Inst) || MIB.isReturn(Inst) ||
+ MIB.isPrefix(Inst) || MIB.isIndirectBranch(Inst))
+ return true;
+ return isDebugScopeBoundaryOffset(Offset);
+}
+
Error BinaryFunction::disassemble() {
NamedRegionTimer T("disassemble", "Disassemble function", "buildfuncs",
"Build Binary Functions", opts::TimeBuild);
@@ -1327,6 +1336,10 @@ Error BinaryFunction::disassemble() {
// corresponding %pcrel_hi.
LabelsMapType InstructionLabels;
+ // Scope boundaries were appended unsorted during preprocessDebugInfo(); sort
+ // them so keepOffsetForInstruction() can query them below.
+ sortDebugScopeBoundaryOffsets();
+
uint64_t Size = 0; // instruction size
for (uint64_t Offset = 0; Offset < getSize(); Offset += Size) {
MCInst Instruction;
@@ -1550,8 +1563,9 @@ Error BinaryFunction::disassemble() {
}
}
- // Record offset of the instruction for profile matching.
- if (BC.keepOffsetForInstruction(Instruction))
+ // Record offset of the instruction for profile matching, for control-flow
+ // instructions, and for instructions on a DWARF lexical-scope boundary.
+ if (keepOffsetForInstruction(Instruction, Offset))
MIB->setOffset(Instruction, static_cast<uint32_t>(Offset));
if (BC.isX86() && BC.MIB->isNoop(Instruction)) {
@@ -1564,6 +1578,9 @@ Error BinaryFunction::disassemble() {
addInstruction(Offset, std::move(Instruction));
}
+ // Scope-boundary markers are only consulted while assigning offsets above.
+ clearList(DebugScopeBoundaryOffsets);
+
for (auto [Offset, Label] : InstructionLabels) {
InstrMapType::iterator II = Instructions.find(Offset);
assert(II != Instructions.end() && "reference to non-existing instruction");
@@ -2590,10 +2607,16 @@ void BinaryFunction::postProcessCFG() {
// The final cleanup of intermediate structures.
clearList(IgnoredBranches);
- // Remove "Offset" annotations, unless we need an address-translation table
- // later. This has no cost, since annotations are allocated by a bumpptr
- // allocator and won't be released anyway until late in the pipeline.
- if (!requiresAddressTranslation() && !opts::Instrument) {
+ // Remove "Offset" annotations, unless we need to build an instruction
+ // accurate IO address map later (used for BAT, SDT/pseudo-probe address
+ // translation, or --update-debug-sections, which relies on per-instruction
+ // offsets to translate DWARF scope ranges).
+ // This has no cost in memory for the BF object, since annotations are
+ // allocated by a bumpptr allocator and won't be released anyway until late
+ // in the pipeline, but the IO address map that is derived from these offsets
+ // does add non-trivial overhead and can get expensive -- that's why we don't
+ // add offsets to every single instruction.
+ if (!requiresPreciseAddressMap() && !opts::Instrument) {
for (BinaryBasicBlock &BB : blocks())
for (MCInst &Inst : BB)
BC.MIB->clearOffset(Inst);
@@ -3261,16 +3284,16 @@ bool BinaryFunction::finalizeCFIState() {
return true;
}
-bool BinaryFunction::requiresAddressTranslation() const {
- return opts::EnableBAT || hasSDTMarker() || hasPseudoProbe();
+bool BinaryFunction::requiresPreciseAddressMap() const {
+ return opts::UpdateDebugSections || opts::EnableBAT || hasSDTMarker() ||
+ hasPseudoProbe();
}
bool BinaryFunction::requiresAddressMap() const {
if (isInjected())
return false;
- return opts::UpdateDebugSections || isMultiEntry() ||
- requiresAddressTranslation();
+ return isMultiEntry() || requiresPreciseAddressMap();
}
uint64_t BinaryFunction::getInstructionCount() const {
@@ -4666,8 +4689,6 @@ uint64_t BinaryFunction::translateInputToOutputAddress(uint64_t Address) const {
return *OutputAddress;
}
- // FIXME: #18950828 - we rely on relative offsets inside basic blocks to stay
- // intact. Instead we can use pseudo instructions and/or annotations.
const uint64_t Offset = Address - getAddress();
const BinaryBasicBlock *BB = getBasicBlockContainingOffset(Offset);
if (!BB) {
@@ -4735,6 +4756,15 @@ BinaryFunction::translateInputToOutputRange(DebugAddressRange InRange) const {
// to /p Offset. The output address should fall within the same basic
// block boundaries.
auto translateBlockOffset = [&](const uint64_t Offset) {
+ // Prefer the precise per-instruction input-to-output address map when
+ // available. The block-relative fallback below assumes intra-block byte
+ // offsets are preserved from input to output, which is not true after a
+ // size-changing pass (e.g. PLT optimization growing call at PLT -> call
+ // *@GOT) runs ahead of the boundary, and silently shifts the range.
+ if (BC.hasIOAddressMap())
+ if (std::optional<uint64_t> OutAddr = BC.getIOAddressMap().lookup(
+ getAddress() + BB.getOffset() + Offset))
+ return *OutAddr;
const uint64_t OutAddress = BB.getOutputAddressRange().first + Offset;
return std::min(OutAddress, BB.getOutputAddressRange().second);
};
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 9e00d48e03853..49ea2ec198efe 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -265,6 +265,14 @@ static cl::opt<std::string> DWPPathName("dwp",
cl::Hidden, cl::init(""),
cl::cat(BoltCategory));
+static cl::opt<bool> AccurateDebugRanges(
+ "accurate-debug-ranges",
+ cl::desc("with --update-debug-sections, track DWARF lexical-scope "
+ "boundaries so scope ranges are translated precisely (instead of "
+ "via input-relative block offsets). Disable to trade range "
+ "accuracy for lower memory/time."),
+ cl::init(true), cl::Hidden, cl::cat(BoltCategory));
+
static cl::opt<bool>
UseGnuStack("use-gnu-stack",
cl::desc("use GNU_STACK program header for new segment (workaround for "
@@ -3586,6 +3594,12 @@ void RewriteInstance::readDebugInfo() {
return;
BC->preprocessDebugInfo();
+
+ if (opts::AccurateDebugRanges) {
+ NamedRegionTimer T("readDebugRanges", "read debug ranges", TimerGroupName,
+ TimerGroupDesc, opts::TimeRewrite);
+ BC->collectDebugScopeBoundaries();
+ }
}
void RewriteInstance::preprocessProfileData() {
diff --git a/bolt/test/X86/dwarf-inline-range-plt-shift.s b/bolt/test/X86/dwarf-inline-range-plt-shift.s
new file mode 100644
index 0000000000000..12ef0ddaca0da
--- /dev/null
+++ b/bolt/test/X86/dwarf-inline-range-plt-shift.s
@@ -0,0 +1,614 @@
+## Regression test for inlined_subroutine address-range corruption.
+##
+## BOLT updates DWARF lexical-scope ranges (DW_TAG_inlined_subroutine /
+## lexical_block low_pc/high_pc and DW_AT_ranges) via
+## BinaryFunction::translateInputToOutputRange(), which maps a boundary using
+## its input offset relative to the start of the containing basic block:
+##
+## OutAddr = BB.getOutputAddressRange().first + (InputOffset - BB.getOffset())
+##
+## This assumes intra-block byte offsets are preserved input->output. Any pass
+## that changes instruction sizes within a block with scope boundary breaks that
+## assumption. Here --plt=all rewrites three `call ext at PLT` (5 bytes, e8+rel32)
+## into `call *ext at GOT(%rip)` (6 bytes, ff 15+rel32), growing the block by +3B
+## before the inlined copy of inl() begins. As a result the inlined_subroutine's
+## low_pc is emitted 3 bytes too early -- landing inside the preceding converted
+## call instruction instead of on inl()'s first instruction (the `leaq`).
+##
+## The range stays within the parent, so `llvm-dwarfdump --verify` does not catch
+## it; we check the exact low_pc against the disassembled instruction address.
+##
+## Source (compiled with -O2 -g -gdwarf-4):
+## extern long exta(long), extb(long), extc(long); // resolved from a DSO -> PLT
+## static inline __attribute__((always_inline)) long inl(long x){ return x*3+7; }
+## __attribute__((noinline)) long foo(long a){
+## long t = exta(a); t = extb(t); t = extc(t); return inl(t);
+## }
+## int main(int argc, char **argv){ return (int)foo(argc); }
+##
+## The fix is enabled through --accurate-debug-ranges and should track all dwarf
+## inline scopes, translating them accordingly.
+
+# REQUIRES: system-linux
+
+## Build a DSO so the exta/extb/extc calls go through the PLT.
+# RUN: echo 'long exta(long x){return x+1;} long extb(long x){return x+2;} long extc(long x){return x+3;}' \
+# RUN: | %clang %cflags -fpic -shared -xc - -o %t.so
+# RUN: %clang %cflags -gdwarf-4 %s %t.so -o %t.exe -Wl,-q -no-pie
+# RUN: llvm-bolt %t.exe -o %t.bolt --plt=all --update-debug-sections
+## Concatenate disassembly then debug-info so FileCheck can capture the
+## instruction address and compare it against the inline scope's low_pc.
+# RUN: llvm-objdump -d --no-show-raw-insn %t.bolt > %t.out
+# RUN: llvm-dwarfdump --debug-info ...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/207291
More information about the llvm-commits
mailing list