| 
 | 1 | +//===- DWARFLinker.h --------------------------------------------*- C++ -*-===//  | 
 | 2 | +//  | 
 | 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.  | 
 | 4 | +// See https://llvm.org/LICENSE.txt for license information.  | 
 | 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception  | 
 | 6 | +//  | 
 | 7 | +//===----------------------------------------------------------------------===//  | 
 | 8 | + | 
 | 9 | +#ifndef LLVM_DWARFLINKER_DWARFLINKER_H  | 
 | 10 | +#define LLVM_DWARFLINKER_DWARFLINKER_H  | 
 | 11 | + | 
 | 12 | +#include "llvm/CodeGen/NonRelocatableStringpool.h"  | 
 | 13 | +#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"  | 
 | 14 | +#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"  | 
 | 15 | +#include "llvm/DebugInfo/DWARF/DWARFContext.h"  | 
 | 16 | +#include <map>  | 
 | 17 | + | 
 | 18 | +namespace llvm {  | 
 | 19 | + | 
 | 20 | +enum class DwarfLinkerClient { Dsymutil, LLD, General };  | 
 | 21 | + | 
 | 22 | +/// Partial address range. Besides an offset, only the  | 
 | 23 | +/// HighPC is stored. The structure is stored in a map where the LowPC is the  | 
 | 24 | +/// key.  | 
 | 25 | +struct ObjFileAddressRange {  | 
 | 26 | +  /// Function HighPC.  | 
 | 27 | +  uint64_t HighPC;  | 
 | 28 | +  /// Offset to apply to the linked address.  | 
 | 29 | +  /// should be 0 for not-linked object file.  | 
 | 30 | +  int64_t Offset;  | 
 | 31 | + | 
 | 32 | +  ObjFileAddressRange(uint64_t EndPC, int64_t Offset)  | 
 | 33 | +      : HighPC(EndPC), Offset(Offset) {}  | 
 | 34 | + | 
 | 35 | +  ObjFileAddressRange() : HighPC(0), Offset(0) {}  | 
 | 36 | +};  | 
 | 37 | + | 
 | 38 | +/// Map LowPC to ObjFileAddressRange.  | 
 | 39 | +using RangesTy = std::map<uint64_t, ObjFileAddressRange>;  | 
 | 40 | + | 
 | 41 | +/// AddressesMap represents information about valid addresses used  | 
 | 42 | +/// by debug information. Valid addresses are those which points to  | 
 | 43 | +/// live code sections. i.e. relocations for these addresses point  | 
 | 44 | +/// into sections which would be/are placed into resulting binary.  | 
 | 45 | +class AddressesMap {  | 
 | 46 | +public:  | 
 | 47 | +  virtual ~AddressesMap();  | 
 | 48 | + | 
 | 49 | +  /// Returns true if represented addresses are from linked file.  | 
 | 50 | +  /// Returns false if represented addresses are from not-linked  | 
 | 51 | +  /// object file.  | 
 | 52 | +  virtual bool areRelocationsResolved() const = 0;  | 
 | 53 | + | 
 | 54 | +  /// Checks that there are valid relocations against a .debug_info  | 
 | 55 | +  /// section. Reset current relocation pointer if neccessary.  | 
 | 56 | +  virtual bool hasValidRelocs(bool ResetRelocsPtr = true) = 0;  | 
 | 57 | + | 
 | 58 | +  /// Checks that there is a relocation against .debug_info  | 
 | 59 | +  /// table between \p StartOffset and \p NextOffset.  | 
 | 60 | +  ///  | 
 | 61 | +  /// This function must be called with offsets in strictly ascending  | 
 | 62 | +  /// order because it never looks back at relocations it already 'went past'.  | 
 | 63 | +  /// \returns true and sets Info.InDebugMap if it is the case.  | 
 | 64 | +  virtual bool hasValidRelocationAt(uint64_t StartOffset, uint64_t EndOffset,  | 
 | 65 | +                                    CompileUnit::DIEInfo &Info) = 0;  | 
 | 66 | + | 
 | 67 | +  /// Apply the valid relocations to the buffer \p Data, taking into  | 
 | 68 | +  /// account that Data is at \p BaseOffset in the debug_info section.  | 
 | 69 | +  ///  | 
 | 70 | +  /// This function must be called with monotonic \p BaseOffset values.  | 
 | 71 | +  ///  | 
 | 72 | +  /// \returns true whether any reloc has been applied.  | 
 | 73 | +  virtual bool applyValidRelocs(MutableArrayRef<char> Data, uint64_t BaseOffset,  | 
 | 74 | +                                bool IsLittleEndian) = 0;  | 
 | 75 | + | 
 | 76 | +  /// Returns all valid functions address ranges(i.e., those ranges  | 
 | 77 | +  /// which points to sections with code).  | 
 | 78 | +  virtual RangesTy &getValidAddressRanges() = 0;  | 
 | 79 | + | 
 | 80 | +  /// Erases all data.  | 
 | 81 | +  virtual void clear() = 0;  | 
 | 82 | +};  | 
 | 83 | + | 
 | 84 | +} // end namespace llvm  | 
 | 85 | + | 
 | 86 | +#endif // LLVM_DWARFLINKER_DWARFLINKER_H  | 
0 commit comments