aboutsummaryrefslogtreecommitdiffstats
path: root/COFF/InputFiles.h
diff options
context:
space:
mode:
Diffstat (limited to 'COFF/InputFiles.h')
-rw-r--r--COFF/InputFiles.h59
1 files changed, 52 insertions, 7 deletions
diff --git a/COFF/InputFiles.h b/COFF/InputFiles.h
index dfad9814a397..672461cd84ba 100644
--- a/COFF/InputFiles.h
+++ b/COFF/InputFiles.h
@@ -10,10 +10,12 @@
#define LLD_COFF_INPUT_FILES_H
#include "Config.h"
+#include "lld/Common/DWARF.h"
#include "lld/Common/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/BinaryFormat/Magic.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Object/Archive.h"
@@ -24,6 +26,7 @@
#include <vector>
namespace llvm {
+struct DILineInfo;
namespace pdb {
class DbiModuleDescriptorBuilder;
}
@@ -47,7 +50,6 @@ class Defined;
class DefinedImportData;
class DefinedImportThunk;
class DefinedRegular;
-class Lazy;
class SectionChunk;
class Symbol;
class Undefined;
@@ -56,7 +58,13 @@ class TpiSource;
// The root class of input files.
class InputFile {
public:
- enum Kind { ArchiveKind, ObjectKind, ImportKind, BitcodeKind };
+ enum Kind {
+ ArchiveKind,
+ ObjectKind,
+ LazyObjectKind,
+ ImportKind,
+ BitcodeKind
+ };
Kind kind() const { return fileKind; }
virtual ~InputFile() {}
@@ -96,17 +104,35 @@ public:
// Enqueues an archive member load for the given symbol. If we've already
// enqueued a load for the same archive member, this function does nothing,
// which ensures that we don't load the same member more than once.
- void addMember(const Archive::Symbol *sym);
+ void addMember(const Archive::Symbol &sym);
private:
std::unique_ptr<Archive> file;
llvm::DenseSet<uint64_t> seen;
};
+// .obj or .o file between -start-lib and -end-lib.
+class LazyObjFile : public InputFile {
+public:
+ explicit LazyObjFile(MemoryBufferRef m) : InputFile(LazyObjectKind, m) {}
+ static bool classof(const InputFile *f) {
+ return f->kind() == LazyObjectKind;
+ }
+ // Makes this object file part of the link.
+ void fetch();
+ // Adds the symbols in this file to the symbol table as LazyObject symbols.
+ void parse() override;
+
+private:
+ std::vector<Symbol *> symbols;
+};
+
// .obj or .o file. This may be a member of an archive file.
class ObjFile : public InputFile {
public:
explicit ObjFile(MemoryBufferRef m) : InputFile(ObjectKind, m) {}
+ explicit ObjFile(MemoryBufferRef m, std::vector<Symbol *> &&symbols)
+ : InputFile(ObjectKind, m), symbols(std::move(symbols)) {}
static bool classof(const InputFile *f) { return f->kind() == ObjectKind; }
void parse() override;
MachineTypes getMachineType() override;
@@ -135,6 +161,10 @@ public:
return symbols.size() - 1;
}
+ void includeResourceChunks();
+
+ bool isResourceObjFile() const { return !resourceChunks.empty(); }
+
static std::vector<ObjFile *> instances;
// Flags in the absolute @feat.00 symbol if it is present. These usually
@@ -162,9 +192,6 @@ public:
// precompiled object. Any difference indicates out-of-date objects.
llvm::Optional<uint32_t> pchSignature;
- // Whether this is an object file created from .res files.
- bool isResourceObjFile = false;
-
// Whether this file was compiled with /hotpatch.
bool hotPatchable = false;
@@ -177,6 +204,12 @@ public:
// The .debug$T stream if there's one.
llvm::Optional<llvm::codeview::CVTypeArray> debugTypes;
+ llvm::Optional<std::pair<StringRef, uint32_t>>
+ getVariableLocation(StringRef var);
+
+ llvm::Optional<llvm::DILineInfo> getDILineInfo(uint32_t offset,
+ uint32_t sectionIndex);
+
private:
const coff_section* getSection(uint32_t i);
const coff_section *getSection(COFFSymbolRef sym) {
@@ -234,6 +267,8 @@ private:
// chunks and non-section chunks for common symbols.
std::vector<Chunk *> chunks;
+ std::vector<SectionChunk *> resourceChunks;
+
// CodeView debug info sections.
std::vector<SectionChunk *> debugChunks;
@@ -258,6 +293,8 @@ private:
// index. Nonexistent indices (which are occupied by auxiliary
// symbols in the real symbol table) are filled with null pointers.
std::vector<Symbol *> symbols;
+
+ DWARFCache *dwarf = nullptr;
};
// This type represents import library members that contain DLL names
@@ -299,7 +336,11 @@ public:
class BitcodeFile : public InputFile {
public:
BitcodeFile(MemoryBufferRef mb, StringRef archiveName,
- uint64_t offsetInArchive);
+ uint64_t offsetInArchive)
+ : BitcodeFile(mb, archiveName, offsetInArchive, {}) {}
+ explicit BitcodeFile(MemoryBufferRef m, StringRef archiveName,
+ uint64_t offsetInArchive,
+ std::vector<Symbol *> &&symbols);
static bool classof(const InputFile *f) { return f->kind() == BitcodeKind; }
ArrayRef<Symbol *> getSymbols() { return symbols; }
MachineTypes getMachineType() override;
@@ -312,6 +353,10 @@ private:
std::vector<Symbol *> symbols;
};
+inline bool isBitcode(MemoryBufferRef mb) {
+ return identify_magic(mb.getBuffer()) == llvm::file_magic::bitcode;
+}
+
std::string replaceThinLTOSuffix(StringRef path);
} // namespace coff