[PATCH] D74773: [LLD][Debuginfo] create DWARFContext only once for the same object file.

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 09:32:43 PST 2020


avl marked an inline comment as done.
avl added inline comments.


================
Comment at: lld/ELF/InputFiles.cpp:269
+  llvm::call_once(initDwarf, [this]() {
+    dwarf = std::make_unique<DWARFCache>(std::make_unique<DWARFContext>(
+        std::make_unique<LLDDwarfObj<ELFT>>(this), "",
----------------
ruiu wrote:
> `make` is an lld's way of memory management, and I don't think you need to change this, so replace `std::make_unique<DWARFCache>` with `make<DWARFCache>`.
Right. But in this concrete case, there is a memory error because of data inter-dependency(if "make" is used).

The problem that DWARFCache::variableLoc references sections which are deleted first:

DWARFCache {

llvm::DenseMap<StringRef, VarLoc> variableLoc;
}

variableLoc has StringRef as a key which uses data from corresponding InputSection. 

When destructor of llvm::DenseMap is called, it checks some keys. 
But since data referenced by key are already deleted, there is a memory error.
The problem is that InputSections are already deallocated at this time. 

freeArena() function starts from the first allocated object and goes till the last allocated object.
DWARFCache was allocated after InputSections.
Thus, when ~DWARFCache() is called - the sections, it references to, are already deleted. 

To avoid that problem, I used std::unique_ptr for DWARFCache so that it would be deleted from the destructor of ObjFile. ObjFile is allocated before InputSections. 
As a result, ~DWARFCache() is called first, and the problem does not happen.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74773/new/

https://reviews.llvm.org/D74773





More information about the llvm-commits mailing list