forked from OSchip/llvm-project
Add MachOLinkingContext parameter to MachOFileNode constructor.
No functionality change. This removes a down-cast from LinkingContext to MachOLinkingContext. Also, remove const from LinkingContext::createImplicitFiles() to remove the need for another const cast. Seems reasonable for createImplicitFiles() to need to modify the context (MachOLinkingContext does). llvm-svn: 218796
This commit is contained in:
parent
fbba2fa8d9
commit
22c9073ada
|
@ -307,7 +307,7 @@ public:
|
|||
/// This method is called by core linking to give the Writer a chance
|
||||
/// to add file format specific "files" to set of files to be linked. This is
|
||||
/// how file format specific atoms can be added to the link.
|
||||
virtual bool createImplicitFiles(std::vector<std::unique_ptr<File> > &) const;
|
||||
virtual bool createImplicitFiles(std::vector<std::unique_ptr<File> > &);
|
||||
|
||||
/// This method is called by core linking to build the list of Passes to be
|
||||
/// run on the merged/linked graph of all input files.
|
||||
|
|
|
@ -18,14 +18,15 @@
|
|||
#define LLD_DRIVER_DARWIN_INPUT_GRAPH_H
|
||||
|
||||
#include "lld/Core/InputGraph.h"
|
||||
#include "lld/ReaderWriter/MachOLinkingContext.h"
|
||||
|
||||
namespace lld {
|
||||
|
||||
/// \brief Represents a MachO File
|
||||
class MachOFileNode : public FileNode {
|
||||
public:
|
||||
MachOFileNode(StringRef path, bool isWholeArchive)
|
||||
: FileNode(path), _isWholeArchive(isWholeArchive) {}
|
||||
MachOFileNode(StringRef path, bool isWholeArchive, MachOLinkingContext &ctx)
|
||||
: FileNode(path), _context(ctx), _isWholeArchive(isWholeArchive) {}
|
||||
|
||||
/// \brief Parse the input file to lld::File.
|
||||
std::error_code parse(const LinkingContext &ctx,
|
||||
|
@ -42,6 +43,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
MachOLinkingContext &_context;
|
||||
bool _isWholeArchive;
|
||||
};
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
bool validateImpl(raw_ostream &diagnostics) override;
|
||||
std::string demangle(StringRef symbolName) const override;
|
||||
|
||||
bool createImplicitFiles(std::vector<std::unique_ptr<File>> &) const override;
|
||||
bool createImplicitFiles(std::vector<std::unique_ptr<File>> &) override;
|
||||
|
||||
uint32_t getCPUType() const;
|
||||
uint32_t getCPUSubType() const;
|
||||
|
@ -231,7 +231,7 @@ public:
|
|||
/// Used to find indirect dylibs. Instantiates a MachODylibFile if one
|
||||
/// has not already been made for the requested dylib. Uses -L and -F
|
||||
/// search paths to allow indirect dylibs to be overridden.
|
||||
mach_o::MachODylibFile* findIndirectDylib(StringRef path) const;
|
||||
mach_o::MachODylibFile* findIndirectDylib(StringRef path);
|
||||
|
||||
/// Creates a copy (owned by this MachOLinkingContext) of a string.
|
||||
StringRef copy(StringRef str) { return str.copy(_allocator); }
|
||||
|
@ -252,7 +252,7 @@ public:
|
|||
|
||||
private:
|
||||
Writer &writer() const override;
|
||||
mach_o::MachODylibFile* loadIndirectDylib(StringRef path) const;
|
||||
mach_o::MachODylibFile* loadIndirectDylib(StringRef path);
|
||||
void checkExportWhiteList(const DefinedAtom *atom) const;
|
||||
void checkExportBlackList(const DefinedAtom *atom) const;
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ public:
|
|||
void addPasses(PassManager &pm) override;
|
||||
|
||||
bool createImplicitFiles(
|
||||
std::vector<std::unique_ptr<File> > &result) const override;
|
||||
std::vector<std::unique_ptr<File> > &result) override;
|
||||
|
||||
bool is64Bit() const {
|
||||
return _machineType == llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
|
||||
|
|
|
@ -38,7 +38,7 @@ std::error_code LinkingContext::writeFile(const File &linkedFile) const {
|
|||
}
|
||||
|
||||
bool LinkingContext::createImplicitFiles(
|
||||
std::vector<std::unique_ptr<File> > &result) const {
|
||||
std::vector<std::unique_ptr<File> > &result) {
|
||||
return this->writer().createImplicitFiles(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,8 +56,7 @@ std::error_code MachOFileNode::parse(const LinkingContext &ctx,
|
|||
for (std::unique_ptr<File> &pf : parsedFiles) {
|
||||
// If a dylib was parsed, inform LinkingContext about it.
|
||||
if (SharedLibraryFile *shl = dyn_cast<SharedLibraryFile>(pf.get())) {
|
||||
MachOLinkingContext *mctx = (MachOLinkingContext*)(&ctx);
|
||||
mctx->registerDylib(reinterpret_cast<mach_o::MachODylibFile*>(shl));
|
||||
_context.registerDylib(reinterpret_cast<mach_o::MachODylibFile*>(shl));
|
||||
}
|
||||
_files.push_back(std::move(pf));
|
||||
}
|
||||
|
|
|
@ -85,9 +85,9 @@ static std::string canonicalizePath(StringRef path) {
|
|||
}
|
||||
|
||||
static void addFile(StringRef path, std::unique_ptr<InputGraph> &inputGraph,
|
||||
bool forceLoad) {
|
||||
bool forceLoad, MachOLinkingContext &ctx) {
|
||||
inputGraph->addInputElement(std::unique_ptr<InputElement>(
|
||||
new MachOFileNode(path, forceLoad)));
|
||||
new MachOFileNode(path, forceLoad, ctx)));
|
||||
}
|
||||
|
||||
// Export lists are one symbol per line. Blank lines are ignored.
|
||||
|
@ -163,7 +163,7 @@ static std::error_code parseFileList(StringRef fileListPath,
|
|||
if (ctx.testingFileUsage()) {
|
||||
diagnostics << "Found filelist entry " << canonicalizePath(path) << '\n';
|
||||
}
|
||||
addFile(path, inputGraph, forceLoad);
|
||||
addFile(path, inputGraph, forceLoad, ctx);
|
||||
buffer = lineAndRest.second;
|
||||
}
|
||||
return std::error_code();
|
||||
|
@ -631,7 +631,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[],
|
|||
default:
|
||||
continue;
|
||||
case OPT_INPUT:
|
||||
addFile(arg->getValue(), inputGraph, globalWholeArchive);
|
||||
addFile(arg->getValue(), inputGraph, globalWholeArchive, ctx);
|
||||
break;
|
||||
case OPT_l:
|
||||
resolvedPath = ctx.searchLibrary(arg->getValue());
|
||||
|
@ -642,7 +642,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[],
|
|||
diagnostics << "Found library "
|
||||
<< canonicalizePath(resolvedPath.get()) << '\n';
|
||||
}
|
||||
addFile(resolvedPath.get(), inputGraph, globalWholeArchive);
|
||||
addFile(resolvedPath.get(), inputGraph, globalWholeArchive, ctx);
|
||||
break;
|
||||
case OPT_framework:
|
||||
resolvedPath = ctx.findPathForFramework(arg->getValue());
|
||||
|
@ -653,7 +653,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[],
|
|||
diagnostics << "Found framework "
|
||||
<< canonicalizePath(resolvedPath.get()) << '\n';
|
||||
}
|
||||
addFile(resolvedPath.get(), inputGraph, globalWholeArchive);
|
||||
addFile(resolvedPath.get(), inputGraph, globalWholeArchive, ctx);
|
||||
break;
|
||||
case OPT_filelist:
|
||||
if (std::error_code ec = parseFileList(arg->getValue(), inputGraph,
|
||||
|
|
|
@ -539,8 +539,8 @@ Writer &MachOLinkingContext::writer() const {
|
|||
return *_writer;
|
||||
}
|
||||
|
||||
MachODylibFile* MachOLinkingContext::loadIndirectDylib(StringRef path) const {
|
||||
std::unique_ptr<MachOFileNode> node(new MachOFileNode(path, false));
|
||||
MachODylibFile* MachOLinkingContext::loadIndirectDylib(StringRef path) {
|
||||
std::unique_ptr<MachOFileNode> node(new MachOFileNode(path, false, *this));
|
||||
std::error_code ec = node->parse(*this, llvm::errs());
|
||||
if (ec)
|
||||
return nullptr;
|
||||
|
@ -558,7 +558,7 @@ MachODylibFile* MachOLinkingContext::loadIndirectDylib(StringRef path) const {
|
|||
}
|
||||
|
||||
|
||||
MachODylibFile* MachOLinkingContext::findIndirectDylib(StringRef path) const {
|
||||
MachODylibFile* MachOLinkingContext::findIndirectDylib(StringRef path) {
|
||||
// See if already loaded.
|
||||
auto pos = _pathToDylibMap.find(path);
|
||||
if (pos != _pathToDylibMap.end())
|
||||
|
@ -593,7 +593,7 @@ MachODylibFile* MachOLinkingContext::findIndirectDylib(StringRef path) const {
|
|||
}
|
||||
|
||||
bool MachOLinkingContext::createImplicitFiles(
|
||||
std::vector<std::unique_ptr<File> > &result) const {
|
||||
std::vector<std::unique_ptr<File> > &result) {
|
||||
// Add indirect dylibs by asking each linked dylib to add its indirects.
|
||||
// Iterate until no more dylibs get loaded.
|
||||
size_t dylibCount = 0;
|
||||
|
|
|
@ -88,7 +88,7 @@ std::unique_ptr<File> PECOFFLinkingContext::createUndefinedSymbolFile() const {
|
|||
}
|
||||
|
||||
bool PECOFFLinkingContext::createImplicitFiles(
|
||||
std::vector<std::unique_ptr<File>> &) const {
|
||||
std::vector<std::unique_ptr<File>> &) {
|
||||
// Create a file for __ImageBase.
|
||||
std::unique_ptr<SimpleFileNode> fileNode(
|
||||
new SimpleFileNode("Implicit Files"));
|
||||
|
|
Loading…
Reference in New Issue