Skip to content

[DWARFLinker] Release input DWARF after object has been linked #7590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions llvm/include/llvm/DWARFLinker/DWARFLinker.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "llvm/CodeGen/AccelTable.h"
#include "llvm/CodeGen/NonRelocatableStringpool.h"
#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include <map>

namespace llvm {
class DWARFContext;
class DWARFExpression;
class DWARFUnit;
class DataExtractor;
Expand Down Expand Up @@ -196,19 +196,26 @@ using UnitListTy = std::vector<std::unique_ptr<CompileUnit>>;
/// and it`s address map.
class DWARFFile {
public:
DWARFFile(StringRef Name, DWARFContext *Dwarf, AddressesMap *Addresses,
DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
std::unique_ptr<AddressesMap> Addresses,
const std::vector<std::string> &Warnings)
: FileName(Name), Dwarf(Dwarf), Addresses(Addresses), Warnings(Warnings) {
}
: FileName(Name), Dwarf(std::move(Dwarf)),
Addresses(std::move(Addresses)), Warnings(Warnings) {}

/// object file name.
StringRef FileName;
/// source DWARF information.
DWARFContext *Dwarf = nullptr;
/// helpful address information(list of valid address ranges, relocations).
AddressesMap *Addresses = nullptr;
/// The source DWARF information.
std::unique_ptr<DWARFContext> Dwarf;
/// Helpful address information(list of valid address ranges, relocations).
std::unique_ptr<AddressesMap> Addresses;
/// warnings for object file.
const std::vector<std::string> &Warnings;

/// Unloads object file and corresponding AddressesMap and Dwarf Context.
void unload() {
Addresses.reset();
Dwarf.reset();
}
};

typedef std::function<void(const Twine &Warning, StringRef Context,
Expand Down Expand Up @@ -445,7 +452,8 @@ class DWARFLinker {
/// the debug object.
void clear() {
CompileUnits.clear();
File.Addresses->clear();
ModuleUnits.clear();
File.unload();
}
};

Expand Down
11 changes: 2 additions & 9 deletions llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,9 @@ DwarfLinkerForBinary::loadObject(const DebugMapObject &Obj,
auto ErrorOrObj = loadObject(Obj, DebugMap.getTriple());

if (ErrorOrObj) {
ContextForLinking.push_back(
std::unique_ptr<DWARFContext>(DWARFContext::create(*ErrorOrObj)));
AddressMapForLinking.push_back(
std::make_unique<AddressManager>(*this, *ErrorOrObj, Obj));

ObjectsForLinking.push_back(std::make_unique<DWARFFile>(
Obj.getObjectFilename(), ContextForLinking.back().get(),
AddressMapForLinking.back().get(),
Obj.getObjectFilename(), DWARFContext::create(*ErrorOrObj),
std::make_unique<AddressManager>(*this, *ErrorOrObj, Obj),
Obj.empty() ? Obj.getWarnings() : EmptyWarnings));

Error E = RL.link(*ErrorOrObj);
Expand Down Expand Up @@ -554,8 +549,6 @@ bool DwarfLinkerForBinary::link(const DebugMap &Map) {
return false;

ObjectsForLinking.clear();
ContextForLinking.clear();
AddressMapForLinking.clear();

DebugMap DebugMap(Map.getTriple(), Map.getBinaryPath());

Expand Down
2 changes: 0 additions & 2 deletions llvm/tools/dsymutil/DwarfLinkerForBinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ class DwarfLinkerForBinary {
LinkOptions Options;
std::unique_ptr<DwarfStreamer> Streamer;
std::vector<std::unique_ptr<DWARFFile>> ObjectsForLinking;
std::vector<std::unique_ptr<DWARFContext>> ContextForLinking;
std::vector<std::unique_ptr<AddressManager>> AddressMapForLinking;
std::vector<std::string> EmptyWarnings;

/// A list of all .swiftinterface files referenced by the debug
Expand Down
7 changes: 2 additions & 5 deletions llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ Error linkDebugInfo(object::ObjectFile &File, const Options &Options,
DebugInfoLinker.setUpdate(!Options.DoGarbageCollection);

std::vector<std::unique_ptr<DWARFFile>> ObjectsForLinking(1);
std::vector<std::unique_ptr<AddressesMap>> AddresssMapForLinking(1);
std::vector<std::string> EmptyWarnings;

// Unknown debug sections would be removed. Display warning
Expand All @@ -319,11 +318,9 @@ Error linkDebugInfo(object::ObjectFile &File, const Options &Options,
}

// Add object files to the DWARFLinker.
AddresssMapForLinking[0] =
std::make_unique<ObjFileAddressMap>(*Context, Options, File);

ObjectsForLinking[0] = std::make_unique<DWARFFile>(
File.getFileName(), &*Context, AddresssMapForLinking[0].get(),
File.getFileName(), DWARFContext::create(File),
std::make_unique<ObjFileAddressMap>(*Context, Options, File),
EmptyWarnings);

for (size_t I = 0; I < ObjectsForLinking.size(); I++)
Expand Down