[llvm] 8c6d48b - [llvm-readobj] Construct relocation-aware DWARFDataExtractor to decode .eh_frame addresses correctly
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 21 08:33:39 PDT 2020
Author: Fangrui Song
Date: 2020-07-21T08:33:19-07:00
New Revision: 8c6d48baf67bcd4e351ab32ef2fc801523db05db
URL: https://github.com/llvm/llvm-project/commit/8c6d48baf67bcd4e351ab32ef2fc801523db05db
DIFF: https://github.com/llvm/llvm-project/commit/8c6d48baf67bcd4e351ab32ef2fc801523db05db.diff
LOG: [llvm-readobj] Construct relocation-aware DWARFDataExtractor to decode .eh_frame addresses correctly
In an object file, a "PC Begin" field in a FDE is usually relocated by a
PC-relative relocation. Use a relocation-aware DWARFDataExtractor overload (with
DWARFContext and a reference to its internal .eh_frame representation) to decode
addresses correctly. In an object file, most sections have addresses of zero. So
the displayed addresses are almost always offsets relative to the start of the
associated text section.
DWARFContext::create handles .eh_frame and .rela.eh_frame by itself, so if there
are more than one .eh_frame (technically possible, but almost always erronerous
in practice), this will only handle the first one. Supporting multiple
.eh_frame is beyond the scope of this patch.
Reviewed By: grimar, jhenderson
Differential Revision: https://reviews.llvm.org/D84106
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/AArch64/dwarf-cfi.s
llvm/test/tools/llvm-readobj/ELF/ARM/dwarf-cfi.s
llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/AArch64/dwarf-cfi.s b/llvm/test/tools/llvm-readobj/ELF/AArch64/dwarf-cfi.s
index 59522afc0bc2..d20673f3a40b 100644
--- a/llvm/test/tools/llvm-readobj/ELF/AArch64/dwarf-cfi.s
+++ b/llvm/test/tools/llvm-readobj/ELF/AArch64/dwarf-cfi.s
@@ -10,10 +10,9 @@
# CHECK: Program:
# CHECK-NEXT: DW_CFA_def_cfa: reg31 +0
-## FIXME Use getEHFrameSection() so that the address is decoded correctly.
# CHECK: [0x14] FDE length=16 cie=[0x0]
-# CHECK-NEXT: initial_location: 0x1c
-# CHECK-NEXT: address_range: 0x4 (end : 0x20)
+# CHECK-NEXT: initial_location: 0x0
+# CHECK-NEXT: address_range: 0x4 (end : 0x4)
# CHECK: Program:
# CHECK-NEXT: DW_CFA_nop:
diff --git a/llvm/test/tools/llvm-readobj/ELF/ARM/dwarf-cfi.s b/llvm/test/tools/llvm-readobj/ELF/ARM/dwarf-cfi.s
index ad6e8d4c5785..72b192fe2028 100644
--- a/llvm/test/tools/llvm-readobj/ELF/ARM/dwarf-cfi.s
+++ b/llvm/test/tools/llvm-readobj/ELF/ARM/dwarf-cfi.s
@@ -10,10 +10,9 @@
# CHECK: Program:
# CHECK-NEXT: DW_CFA_def_cfa: reg13 +0
-## FIXME Use getEHFrameSection() so that the address is decoded correctly.
# CHECK: [0x14] FDE length=16 cie=[0x0]
-# CHECK-NEXT: initial_location: 0x1c
-# CHECK-NEXT: address_range: 0x4 (end : 0x20)
+# CHECK-NEXT: initial_location: 0x0
+# CHECK-NEXT: address_range: 0x4 (end : 0x4)
# CHECK: Program:
# CHECK-NEXT: DW_CFA_nop:
diff --git a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
index 284fbb447329..a82eca080cc9 100644
--- a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
+++ b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
@@ -13,6 +13,7 @@
#include "llvm-readobj.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/BinaryFormat/Dwarf.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
#include "llvm/Object/ELF.h"
@@ -185,7 +186,10 @@ void PrinterContext<ELFT>::printEHFrame(const Elf_Shdr *EHFrameShdr) const {
if (!DataOrErr)
reportError(DataOrErr.takeError(), ObjF->getFileName());
- DWARFDataExtractor DE(*DataOrErr,
+ // Construct DWARFDataExtractor to handle relocations ("PC Begin" fields).
+ std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*ObjF, nullptr);
+ DWARFDataExtractor DE(DICtx->getDWARFObj(),
+ DICtx->getDWARFObj().getEHFrameSection(),
ELFT::TargetEndianness == support::endianness::little,
ELFT::Is64Bits ? 8 : 4);
DWARFDebugFrame EHFrame(Triple::ArchType(ObjF->getArch()), /*IsEH=*/true,
More information about the llvm-commits
mailing list