@@ -35,7 +35,6 @@ using namespace llvm::sys::fs;
35
35
using namespace lld ;
36
36
using namespace lld ::elf;
37
37
38
-
39
38
namespace {
40
39
// In ELF object file all section addresses are zero. If we have multiple
41
40
// .text sections (when using -ffunction-section or comdat group) then
@@ -53,47 +52,46 @@ class ObjectInfo : public LoadedObjectInfo {
53
52
};
54
53
}
55
54
56
- template <class ELFT > DIHelper<ELFT>::DIHelper(InputFile *F) {
57
- Expected<std::unique_ptr<object::ObjectFile>> Obj =
58
- object::ObjectFile::createObjectFile (F->MB );
59
- if (!Obj)
60
- return ;
55
+ template <class ELFT > void ObjectFile<ELFT>::initializeDwarfLine() {
56
+ std::unique_ptr<object::ObjectFile> Obj =
57
+ check (object::ObjectFile::createObjectFile (this ->MB ),
58
+ " createObjectFile failed" );
61
59
62
60
ObjectInfo ObjInfo;
63
61
DWARFContextInMemory Dwarf (*Obj.get (), &ObjInfo);
64
62
DwarfLine.reset (new DWARFDebugLine (&Dwarf.getLineSection ().Relocs ));
65
63
DataExtractor LineData (Dwarf.getLineSection ().Data ,
66
64
ELFT::TargetEndianness == support::little,
67
65
ELFT::Is64Bits ? 8 : 4 );
66
+
68
67
// The second parameter is offset in .debug_line section
69
68
// for compilation unit (CU) of interest. We have only one
70
69
// CU (object file), so offset is always 0.
71
70
DwarfLine->getOrParseLineTable (LineData, 0 );
72
71
}
73
72
74
- template < class ELFT > DIHelper<ELFT>:: ~DIHelper () {}
75
-
73
+ // Returns source line information for a given offset
74
+ // using DWARF debug info.
76
75
template <class ELFT >
77
- std::string DIHelper <ELFT>::getLineInfo(InputSectionBase<ELFT> *S,
78
- uintX_t Offset) {
76
+ std::string ObjectFile <ELFT>::getLineInfo(InputSectionBase<ELFT> *S,
77
+ uintX_t Offset) {
79
78
if (!DwarfLine)
80
- return " " ;
79
+ initializeDwarfLine () ;
81
80
82
- DILineInfo LineInfo;
83
- DILineInfoSpecifier Spec;
84
- // The offset to CU is 0 (see DIHelper constructor).
85
- const DWARFDebugLine::LineTable *LineTbl = DwarfLine->getLineTable (0 );
86
- if (!LineTbl)
81
+ // The offset to CU is 0.
82
+ const DWARFDebugLine::LineTable *Tbl = DwarfLine->getLineTable (0 );
83
+ if (!Tbl)
87
84
return " " ;
88
85
89
86
// Use fake address calcuated by adding section file offset and offset in
90
- // section.
91
- // See comments for ObjectInfo class
92
- LineTbl->getFileLineInfoForAddress (S->Offset + Offset, nullptr , Spec.FLIKind ,
93
- LineInfo);
94
- return LineInfo.Line != 0
95
- ? LineInfo.FileName + " (" + std::to_string (LineInfo.Line ) + " )"
96
- : " " ;
87
+ // section. See comments for ObjectInfo class.
88
+ DILineInfo Info;
89
+ DILineInfoSpecifier Spec;
90
+ Tbl->getFileLineInfoForAddress (S->Offset + Offset, nullptr , Spec.FLIKind ,
91
+ Info);
92
+ if (Info.Line == 0 )
93
+ return " " ;
94
+ return Info.FileName + " (" + std::to_string (Info.Line ) + " )" ;
97
95
}
98
96
99
97
// Returns "(internal)", "foo.a(bar.o)" or "baz.o".
@@ -185,13 +183,6 @@ ArrayRef<SymbolBody *> elf::ObjectFile<ELFT>::getSymbols() {
185
183
return makeArrayRef (this ->SymbolBodies ).slice (1 );
186
184
}
187
185
188
- template <class ELFT > DIHelper<ELFT> *elf::ObjectFile<ELFT>::getDIHelper() {
189
- if (!DIH)
190
- DIH.reset (new DIHelper<ELFT>(this ));
191
-
192
- return DIH.get ();
193
- }
194
-
195
186
template <class ELFT > uint32_t elf::ObjectFile<ELFT>::getMipsGp0() const {
196
187
if (ELFT::Is64Bits && MipsOptions && MipsOptions->Reginfo )
197
188
return MipsOptions->Reginfo ->ri_gp_value ;
@@ -968,8 +959,3 @@ template void BinaryFile::parse<ELF32LE>();
968
959
template void BinaryFile::parse<ELF32BE>();
969
960
template void BinaryFile::parse<ELF64LE>();
970
961
template void BinaryFile::parse<ELF64BE>();
971
-
972
- template class elf ::DIHelper<ELF32LE>;
973
- template class elf ::DIHelper<ELF32BE>;
974
- template class elf ::DIHelper<ELF64LE>;
975
- template class elf ::DIHelper<ELF64BE>;
0 commit comments