[PATCH] D100328: Fixed bug in eh_frame PC offset calculation for DW_EH_PE_pcrel
Alex Orlov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 12 10:34:11 PDT 2021
aorlov created this revision.
aorlov added reviewers: dblaikie, RKSimon, kazu.
aorlov added a project: LLVM.
Herald added subscribers: cmtice, rupprecht, hiraditya.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
aorlov requested review of this revision.
Herald added a subscriber: llvm-commits.
To calculate a correct PC offset we need to apply the target address from the eh_frame.
This fixes the following bugs:
https://bugs.llvm.org/show_bug.cgi?id=27249
https://bugs.llvm.org/show_bug.cgi?id=46414
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100328
Files:
llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
llvm/test/tools/llvm-objdump/MachO/eh_frame-arm64.test
Index: llvm/test/tools/llvm-objdump/MachO/eh_frame-arm64.test
===================================================================
--- llvm/test/tools/llvm-objdump/MachO/eh_frame-arm64.test
+++ llvm/test/tools/llvm-objdump/MachO/eh_frame-arm64.test
@@ -12,7 +12,7 @@
# CHECK: DW_CFA_def_cfa: reg31 +0
-# CHECK: 00000014 00000020 00000018 FDE cie=00000000 pc=00000000...00000020
+# CHECK: 00000014 00000020 00000018 FDE cie=00000000 pc=00000050...00000070
# CHECK: DW_CFA_advance_loc: 8
# CHECK: DW_CFA_def_cfa_offset: +16
# CHECK: DW_CFA_offset: reg30 -8
Index: llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
===================================================================
--- llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
+++ llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
@@ -9,7 +9,7 @@
RUN: llvm-dwarfdump %p/../../dsymutil/Inputs/basic1.macho.x86_64.o \
RUN: -eh-frame=0x00000018 | FileCheck %s --check-prefix=EH
EH: .eh_frame contents:
-EH-NEXT: 00000018 00000024 0000001c FDE cie=00000000 pc=fffffffffffffd20...fffffffffffffd44
+EH-NEXT: 00000018 00000024 0000001c FDE cie=00000000 pc=00000000...00000024
EH-NEXT: Format: DWARF32
EH-NEXT: DW_CFA_advance_loc: 1
EH-NOT: pc
Index: llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -823,6 +823,8 @@
if (DebugFrame)
return DebugFrame.get();
+ const DWARFSection &DS = DObj->getFrameSection();
+
// There's a "bug" in the DWARFv3 standard with respect to the target address
// size within debug frame sections. While DWARF is supposed to be independent
// of its container, FDEs have fields with size being "target address size",
@@ -832,9 +834,10 @@
// provides this information). This problem is fixed in DWARFv4
// See this dwarf-discuss discussion for more details:
// http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html
- DWARFDataExtractor debugFrameData(*DObj, DObj->getFrameSection(),
- isLittleEndian(), DObj->getAddressSize());
- auto DF = std::make_unique<DWARFDebugFrame>(getArch(), /*IsEH=*/false);
+ DWARFDataExtractor debugFrameData(*DObj, DS, isLittleEndian(),
+ DObj->getAddressSize());
+ auto DF =
+ std::make_unique<DWARFDebugFrame>(getArch(), /*IsEH=*/false, DS.Address);
if (Error E = DF->parse(debugFrameData))
return std::move(E);
@@ -846,10 +849,12 @@
if (EHFrame)
return EHFrame.get();
- DWARFDataExtractor debugFrameData(*DObj, DObj->getEHFrameSection(),
- isLittleEndian(), DObj->getAddressSize());
+ const DWARFSection &DS = DObj->getEHFrameSection();
+ DWARFDataExtractor debugFrameData(*DObj, DS, isLittleEndian(),
+ DObj->getAddressSize());
- auto DF = std::make_unique<DWARFDebugFrame>(getArch(), /*IsEH=*/true);
+ auto DF =
+ std::make_unique<DWARFDebugFrame>(getArch(), /*IsEH=*/true, DS.Address);
if (Error E = DF->parse(debugFrameData))
return std::move(E);
DebugFrame.swap(DF);
@@ -1707,6 +1712,9 @@
if (Name == "debug_ranges") {
// FIXME: Use the other dwo range section when we emit it.
RangesDWOSection.Data = Data;
+ } else if (Name == "debug_frame" || Name == "eh_frame") {
+ if (DWARFSection *S = mapNameToDWARFSection(Name))
+ S->Address = Section.getAddress();
}
} else if (InfoSectionMap *Sections =
StringSwitch<InfoSectionMap *>(Name)
Index: llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
===================================================================
--- llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
+++ llvm/include/llvm/DebugInfo/DWARF/DWARFSection.h
@@ -15,6 +15,7 @@
struct DWARFSection {
StringRef Data;
+ uint64_t Address = {};
};
struct SectionName {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100328.336886.patch
Type: text/x-patch
Size: 4064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210412/285aa445/attachment-0001.bin>
More information about the llvm-commits
mailing list