Skip to content

Commit

Permalink
[Dsymutil][Debuginfo][NFC] Reland: Refactor dsymutil to separate DWAR…
Browse files Browse the repository at this point in the history
…F optimizing part. rust-lang#2.

Summary:
This patch relands D71271. The problem with D71271 is that it has cyclic dependency:
CodeGen->AsmPrinter->DebugInfoDWARF->CodeGen. To avoid cyclic dependency this patch
puts implementation for DWARFOptimizer into separate library: lib/DWARFLinker.

Thus the difference between this patch and D71271 is in that DWARFOptimizer renamed into
DWARFLinker and it`s files are put into lib/DWARFLinker.

Reviewers: JDevlieghere, friss, dblaikie, aprantl

Reviewed By: JDevlieghere

Subscribers: thegameg, merge_guards_bot, probinson, mgorny, hiraditya, llvm-commits

Tags: #llvm, #debug-info

Differential Revision: https://reviews.llvm.org/D71839
  • Loading branch information
avl-llvm committed Jan 8, 2020
1 parent 96d2d96 commit 1cf11a4
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 215 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/NonRelocatableStringpool.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- llvm/CodeGen/NonRelocatableStringpool.h - A simple stringpool -----===//
//===- NonRelocatableStringpool.h -------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
86 changes: 86 additions & 0 deletions llvm/include/llvm/DWARFLinker/DWARFLinker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//===- DWARFLinker.h --------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_DWARFLINKER_DWARFLINKER_H
#define LLVM_DWARFLINKER_DWARFLINKER_H

#include "llvm/CodeGen/NonRelocatableStringpool.h"
#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include <map>

namespace llvm {

enum class DwarfLinkerClient { Dsymutil, LLD, General };

/// Partial address range. Besides an offset, only the
/// HighPC is stored. The structure is stored in a map where the LowPC is the
/// key.
struct ObjFileAddressRange {
/// Function HighPC.
uint64_t HighPC;
/// Offset to apply to the linked address.
/// should be 0 for not-linked object file.
int64_t Offset;

ObjFileAddressRange(uint64_t EndPC, int64_t Offset)
: HighPC(EndPC), Offset(Offset) {}

ObjFileAddressRange() : HighPC(0), Offset(0) {}
};

/// Map LowPC to ObjFileAddressRange.
using RangesTy = std::map<uint64_t, ObjFileAddressRange>;

/// AddressesMap represents information about valid addresses used
/// by debug information. Valid addresses are those which points to
/// live code sections. i.e. relocations for these addresses point
/// into sections which would be/are placed into resulting binary.
class AddressesMap {
public:
virtual ~AddressesMap();

/// Returns true if represented addresses are from linked file.
/// Returns false if represented addresses are from not-linked
/// object file.
virtual bool areRelocationsResolved() const = 0;

/// Checks that there are valid relocations against a .debug_info
/// section. Reset current relocation pointer if neccessary.
virtual bool hasValidRelocs(bool ResetRelocsPtr = true) = 0;

/// Checks that there is a relocation against .debug_info
/// table between \p StartOffset and \p NextOffset.
///
/// This function must be called with offsets in strictly ascending
/// order because it never looks back at relocations it already 'went past'.
/// \returns true and sets Info.InDebugMap if it is the case.
virtual bool hasValidRelocationAt(uint64_t StartOffset, uint64_t EndOffset,
CompileUnit::DIEInfo &Info) = 0;

/// Apply the valid relocations to the buffer \p Data, taking into
/// account that Data is at \p BaseOffset in the debug_info section.
///
/// This function must be called with monotonic \p BaseOffset values.
///
/// \returns true whether any reloc has been applied.
virtual bool applyValidRelocs(MutableArrayRef<char> Data, uint64_t BaseOffset,
bool IsLittleEndian) = 0;

/// Returns all valid functions address ranges(i.e., those ranges
/// which points to sections with code).
virtual RangesTy &getValidAddressRanges() = 0;

/// Erases all data.
virtual void clear() = 0;
};

} // end namespace llvm

#endif // LLVM_DWARFLINKER_DWARFLINKER_H
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//===- tools/dsymutil/CompileUnit.h - Dwarf debug info linker ---*- C++ -*-===//
//===- DWARFLinkerCompileUnit.h ---------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_DSYMUTIL_COMPILEUNIT_H
#define LLVM_TOOLS_DSYMUTIL_COMPILEUNIT_H
#ifndef LLVM_DWARFLINKER_DWARFLINKERCOMPILEUNIT_H
#define LLVM_DWARFLINKER_DWARFLINKERCOMPILEUNIT_H

#include "llvm/ADT/IntervalMap.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Support/DataExtractor.h"

namespace llvm {
namespace dsymutil {

class DeclContext;

Expand Down Expand Up @@ -46,7 +46,7 @@ struct PatchLocation {
};

/// Stores all information relating to a compile unit, be it in its original
/// instance in the object file to its brand new cloned and linked DIE tree.
/// instance in the object file to its brand new cloned and generated DIE tree.
class CompileUnit {
public:
/// Information gathered about a DIE in the object file.
Expand Down Expand Up @@ -325,7 +325,6 @@ class CompileUnit {
std::string ClangModuleName;
};

} // end namespace dsymutil
} // end namespace llvm

#endif // LLVM_TOOLS_DSYMUTIL_COMPILEUNIT_H
#endif // LLVM_DWARFLINKER_DWARFLINKERCOMPILEUNIT_H
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
//===- tools/dsymutil/DeclContext.h - Dwarf debug info linker ---*- C++ -*-===//
//===- DWARFLinkerDeclContext.h ---------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_DSYMUTIL_DECLCONTEXT_H
#define LLVM_TOOLS_DSYMUTIL_DECLCONTEXT_H
#ifndef LLVM_DWARFLINKER_DWARFLINKERDECLCONTEXT_H
#define LLVM_DWARFLINKER_DWARFLINKERDECLCONTEXT_H

#include "CompileUnit.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/NonRelocatableStringpool.h"
#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/Support/Path.h"

namespace llvm {
namespace dsymutil {

struct DeclMapInfo;

Expand Down Expand Up @@ -165,7 +164,6 @@ struct DeclMapInfo : private DenseMapInfo<DeclContext *> {
}
};

} // end namespace dsymutil
} // end namespace llvm

#endif // LLVM_TOOLS_DSYMUTIL_DECLCONTEXT_H
#endif // LLVM_DWARFLINKER_DWARFLINKERDECLCONTEXT_H
1 change: 1 addition & 0 deletions llvm/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_subdirectory(CodeGen)
add_subdirectory(BinaryFormat)
add_subdirectory(Bitcode)
add_subdirectory(Bitstream)
add_subdirectory(DWARFLinker)
add_subdirectory(Frontend)
add_subdirectory(Transforms)
add_subdirectory(Linker)
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/NonRelocatableStringpool.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- llvm/CodeGen/NonRelocatableStringpool.cpp - A simple stringpool --===//
//===-- NonRelocatableStringpool.cpp --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/DWARFLinker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_llvm_component_library(LLVMDWARFLinker
DWARFLinkerCompileUnit.cpp
DWARFLinkerDeclContext.cpp
DWARFLinker.cpp

)
15 changes: 15 additions & 0 deletions llvm/lib/DWARFLinker/DWARFLinker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//=== DWARFLinker.cpp -----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/DWARFLinker/DWARFLinker.h"

namespace llvm {

AddressesMap::~AddressesMap() {}

} // namespace llvm
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
//===- tools/dsymutil/CompileUnit.h - Dwarf compile unit ------------------===//
//===- DWARFLinkerCompileUnit.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "CompileUnit.h"
#include "DeclContext.h"
#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"

namespace llvm {
namespace dsymutil {

/// Check if the DIE at \p Idx is in the scope of a function.
static bool inFunctionScope(CompileUnit &U, unsigned Idx) {
Expand Down Expand Up @@ -142,5 +141,4 @@ void CompileUnit::addTypeAccelerator(const DIE *Die,
Pubtypes.emplace_back(Name, Die, QualifiedNameHash, ObjcClassImplementation);
}

} // namespace dsymutil
} // namespace llvm
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
//===- tools/dsymutil/DeclContext.cpp - Declaration context ---------------===//
//===- DWARFLinkerDeclContext.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DeclContext.h"
#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"

namespace llvm {
namespace dsymutil {

/// Set the last DIE/CU a context was seen in and, possibly invalidate the
/// context if it is ambiguous.
Expand Down Expand Up @@ -206,5 +205,5 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(

return PointerIntPair<DeclContext *, 1>(*ContextIter);
}
} // namespace dsymutil

} // namespace llvm
21 changes: 21 additions & 0 deletions llvm/lib/DWARFLinker/LLVMBuild.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
;===- ./lib/DWARFLinker/LLVMBuild.txt ---------------*- Conf -*--===;
;
; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
; See https://llvm.org/LICENSE.txt for license information.
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;

[component_0]
type = Library
name = DWARFLinker
parent = Libraries
required_libraries = DebugInfoDWARF AsmPrinter CodeGen MC Object Support
1 change: 1 addition & 0 deletions llvm/lib/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ subdirectories =
CodeGen
DebugInfo
Demangle
DWARFLinker
ExecutionEngine
Frontend
FuzzMutate
Expand Down
5 changes: 2 additions & 3 deletions llvm/tools/dsymutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS
AllTargetsInfos
AsmPrinter
DebugInfoDWARF
DWARFLinker
MC
Object
CodeGen
Expand All @@ -22,10 +23,8 @@ add_llvm_tool(dsymutil
dsymutil.cpp
BinaryHolder.cpp
CFBundle.cpp
CompileUnit.cpp
DebugMap.cpp
DeclContext.cpp
DwarfLinker.cpp
DwarfLinkerForBinary.cpp
DwarfStreamer.cpp
MachODebugMapParser.cpp
MachOUtils.cpp
Expand Down
Loading

0 comments on commit 1cf11a4

Please sign in to comment.