[PATCH] D25826: [ELF] Show error location for 'undefined symbol' errors

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 25 11:53:40 PDT 2016


I actually didn't see any error when I simply converted it to unique_ptr
and removed the dtor, so I'm wondering what error you saw. In any case,
doesn't this work?

diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp
index 497f946..01f8be9 100644
--- a/ELF/InputFiles.cpp
+++ b/ELF/InputFiles.cpp
@@ -43,7 +43,7 @@ template <class ELFT>
DIHelper<ELFT>::DIHelper(elf::InputFile *F) {
     return;

   DWARFContextInMemory Dwarf(*Obj.get());
-  DwarfLine = new DWARFDebugLine(&Dwarf.getLineSection().Relocs);
+  DwarfLine.reset(new DWARFDebugLine(&Dwarf.getLineSection().Relocs));
   DataExtractor lineData(Dwarf.getLineSection().Data,
                          ELFT::TargetEndianness == support::little,
                          ELFT::Is64Bits ? 8 : 4);
@@ -53,7 +53,7 @@ template <class ELFT>
DIHelper<ELFT>::DIHelper(elf::InputFile *F) {
   DwarfLine->getOrParseLineTable(lineData, 0);
 }

-template <class ELFT> DIHelper<ELFT>::~DIHelper() { delete DwarfLine; }
+template <class ELFT> DIHelper<ELFT>::~DIHelper() {}

 template <class ELFT> std::string DIHelper<ELFT>::getLineInfo(uintX_t
Offset) {
   DILineInfo LineInfo;
diff --git a/ELF/InputFiles.h b/ELF/InputFiles.h
index a1a63b8..6c0f5cb 100644
--- a/ELF/InputFiles.h
+++ b/ELF/InputFiles.h
@@ -58,7 +58,7 @@ public:
   std::string getLineInfo(uintX_t Offset);

 private:
-  llvm::DWARFDebugLine *DwarfLine = nullptr;
+  std::unique_ptr<llvm::DWARFDebugLine> DwarfLine;
 };

 // The root class of input files.

On Tue, Oct 25, 2016 at 11:35 AM, Eugene Leviant <evgeny.leviant at gmail.com>
wrote:

> I might not be catching your idea, but if you have the following line
> in InputFiles.h:
>
> std::unique_ptr<DWARFDebugLine> DwarfLine;
>
> you will either have to:
> a) #include <llvm/DebugInfo/DWARFDebugLine.h>
> or
> b) std::unique_ptr<DWARFDebugLine, MyDeleter> DwarfLine;
>
> This is because std::default_deleter<T> checks sizeof(T) in
> static_assert (where T is DWARFDebugLine)
>
> 2016-10-25 21:26 GMT+03:00 Rui Ueyama <ruiu at google.com>:
> > On Tue, Oct 25, 2016 at 11:08 AM, Eugene Leviant <
> evgeny.leviant at gmail.com>
> > wrote:
> >>
> >> evgeny777 added inline comments.
> >>
> >>
> >> ================
> >> Comment at: ELF/InputFiles.cpp:56
> >> +
> >> +template <class ELFT> DIHelper<ELFT>::~DIHelper() { delete DwarfLine; }
> >> +
> >> ----------------
> >> ruiu wrote:
> >> > Use unique_ptr to remove this dtor.
> >> It's not possible unless you include DWARFContext.h to InputFiles.h or
> >> override unique_ptr deleter (second template parameter). Is this better?
> >
> >
> > You can have an empty dtor in InputFiles.cpp like `template <class ELFT>
> > DIHelper<ELFT>::~DIHelper() {}` to write a definition of the dtor in the
> cpp
> > file instead of in the header so that you don't need to include the
> > DWARFContext.h, can't you?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161025/088eedf6/attachment.html>


More information about the llvm-commits mailing list