1 //===- DWARFDataExtractor.cpp ---------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
10 #include "llvm/BinaryFormat/Dwarf.h"
11 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
15 uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size
, uint64_t *Off
,
19 *SecNdx
= object::SectionedAddress::UndefSection
;
21 return getUnsigned(Off
, Size
, Err
);
22 Optional
<RelocAddrEntry
> E
= Obj
->find(*Section
, *Off
);
23 uint64_t A
= getUnsigned(Off
, Size
, Err
);
27 *SecNdx
= E
->SectionIndex
;
28 uint64_t R
= E
->Resolver(E
->Reloc
, E
->SymbolValue
, A
);
30 R
= E
->Resolver(*E
->Reloc2
, E
->SymbolValue2
, R
);
35 DWARFDataExtractor::getEncodedPointer(uint64_t *Offset
, uint8_t Encoding
,
36 uint64_t PCRelOffset
) const {
37 if (Encoding
== dwarf::DW_EH_PE_omit
)
41 uint64_t OldOffset
= *Offset
;
43 switch (Encoding
& 0x0F) {
44 case dwarf::DW_EH_PE_absptr
:
45 switch (getAddressSize()) {
49 Result
= getUnsigned(Offset
, getAddressSize());
55 case dwarf::DW_EH_PE_uleb128
:
56 Result
= getULEB128(Offset
);
58 case dwarf::DW_EH_PE_sleb128
:
59 Result
= getSLEB128(Offset
);
61 case dwarf::DW_EH_PE_udata2
:
62 Result
= getUnsigned(Offset
, 2);
64 case dwarf::DW_EH_PE_udata4
:
65 Result
= getUnsigned(Offset
, 4);
67 case dwarf::DW_EH_PE_udata8
:
68 Result
= getUnsigned(Offset
, 8);
70 case dwarf::DW_EH_PE_sdata2
:
71 Result
= getSigned(Offset
, 2);
73 case dwarf::DW_EH_PE_sdata4
:
74 Result
= getSigned(Offset
, 4);
76 case dwarf::DW_EH_PE_sdata8
:
77 Result
= getSigned(Offset
, 8);
82 // Then add relative offset, if required
83 switch (Encoding
& 0x70) {
84 case dwarf::DW_EH_PE_absptr
:
87 case dwarf::DW_EH_PE_pcrel
:
88 Result
+= PCRelOffset
;
90 case dwarf::DW_EH_PE_datarel
:
91 case dwarf::DW_EH_PE_textrel
:
92 case dwarf::DW_EH_PE_funcrel
:
93 case dwarf::DW_EH_PE_aligned
: