#include "lld/Core/LinkingContext.h"
#include "lld/Core/Reader.h"
#include "lld/Core/Writer.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/ErrorHandling.h"
void createImplicitFiles(std::vector<std::unique_ptr<File>> &) override;
+ /// Creates a new file which is owned by the context. Returns a pointer to
+ /// the new file.
+ template <class T, class... Args>
+ typename std::enable_if<!std::is_array<T>::value, T *>::type
+ make_file(Args &&... args) const {
+ auto file = std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+ auto *filePtr = file.get();
+ auto *ctx = const_cast<MachOLinkingContext *>(this);
+ ctx->getNodes().push_back(llvm::make_unique<FileNode>(std::move(file)));
+ return filePtr;
+ }
+
uint32_t getCPUType() const;
uint32_t getCPUSubType() const;
public:
CompactUnwindPass(const MachOLinkingContext &context)
: _ctx(context), _archHandler(_ctx.archHandler()),
- _file("<mach-o Compact Unwind Pass>"),
+ _file(*_ctx.make_file<MachOFile>("<mach-o Compact Unwind Pass>")),
_isBig(MachOLinkingContext::isBigEndian(_ctx.arch())) {
_file.setOrdinal(_ctx.getNextOrdinalAndIncrement());
}
const MachOLinkingContext &_ctx;
mach_o::ArchHandler &_archHandler;
- MachOFile _file;
+ MachOFile &_file;
bool _isBig;
};
public:
GOTPass(const MachOLinkingContext &context)
: _ctx(context), _archHandler(_ctx.archHandler()),
- _file("<mach-o GOT Pass>") {
+ _file(*_ctx.make_file<MachOFile>("<mach-o GOT Pass>")) {
_file.setOrdinal(_ctx.getNextOrdinalAndIncrement());
}
const MachOLinkingContext &_ctx;
mach_o::ArchHandler &_archHandler;
- MachOFile _file;
+ MachOFile &_file;
llvm::DenseMap<const Atom*, const GOTEntryAtom*> _targetToGOT;
};
public:
ObjCPass(const MachOLinkingContext &context)
: _ctx(context),
- _file("<mach-o objc pass>") {
+ _file(*_ctx.make_file<MachOFile>("<mach-o objc pass>")) {
_file.setOrdinal(_ctx.getNextOrdinalAndIncrement());
}
}
const MachOLinkingContext &_ctx;
- MachOFile _file;
+ MachOFile &_file;
};
public:
ShimPass(const MachOLinkingContext &context)
: _ctx(context), _archHandler(_ctx.archHandler()),
- _stubInfo(_archHandler.stubInfo()), _file("<mach-o shim pass>") {
+ _stubInfo(_archHandler.stubInfo()),
+ _file(*_ctx.make_file<MachOFile>("<mach-o shim pass>")) {
_file.setOrdinal(_ctx.getNextOrdinalAndIncrement());
}
const MachOLinkingContext &_ctx;
mach_o::ArchHandler &_archHandler;
const ArchHandler::StubInfo &_stubInfo;
- MachOFile _file;
+ MachOFile &_file;
llvm::DenseMap<const Atom*, const DefinedAtom*> _targetToShim;
};
public:
StubsPass(const MachOLinkingContext &context)
: _ctx(context), _archHandler(_ctx.archHandler()),
- _stubInfo(_archHandler.stubInfo()), _file("<mach-o Stubs pass>") {
+ _stubInfo(_archHandler.stubInfo()),
+ _file(*_ctx.make_file<MachOFile>("<mach-o Stubs pass>")) {
_file.setOrdinal(_ctx.getNextOrdinalAndIncrement());
}
const MachOLinkingContext &_ctx;
mach_o::ArchHandler &_archHandler;
const ArchHandler::StubInfo &_stubInfo;
- MachOFile _file;
+ MachOFile &_file;
TargetToUses _targetToUses;
};
public:
TLVPass(const MachOLinkingContext &context)
: _ctx(context), _archHandler(_ctx.archHandler()),
- _file("<mach-o TLV Pass>") {
+ _file(*_ctx.make_file<MachOFile>("<mach-o TLV pass>")) {
_file.setOrdinal(_ctx.getNextOrdinalAndIncrement());
}
const MachOLinkingContext &_ctx;
mach_o::ArchHandler &_archHandler;
- MachOFile _file;
+ MachOFile &_file;
llvm::DenseMap<const Atom*, const TLVPEntryAtom*> _targetToTLVP;
};