[lld] r218796 - Add MachOLinkingContext parameter to MachOFileNode constructor.
Nick Kledzik
kledzik at apple.com
Wed Oct 1 13:24:30 PDT 2014
Author: kledzik
Date: Wed Oct 1 15:24:30 2014
New Revision: 218796
URL: http://llvm.org/viewvc/llvm-project?rev=218796&view=rev
Log:
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).
Modified:
lld/trunk/include/lld/Core/LinkingContext.h
lld/trunk/include/lld/Driver/DarwinInputGraph.h
lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/trunk/lib/Core/LinkingContext.cpp
lld/trunk/lib/Driver/DarwinInputGraph.cpp
lld/trunk/lib/Driver/DarwinLdDriver.cpp
lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=218796&r1=218795&r2=218796&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Wed Oct 1 15:24:30 2014
@@ -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.
Modified: lld/trunk/include/lld/Driver/DarwinInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/DarwinInputGraph.h?rev=218796&r1=218795&r2=218796&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/DarwinInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/DarwinInputGraph.h Wed Oct 1 15:24:30 2014
@@ -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;
};
Modified: lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h?rev=218796&r1=218795&r2=218796&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h Wed Oct 1 15:24:30 2014
@@ -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;
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=218796&r1=218795&r2=218796&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Wed Oct 1 15:24:30 2014
@@ -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;
Modified: lld/trunk/lib/Core/LinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/LinkingContext.cpp?rev=218796&r1=218795&r2=218796&view=diff
==============================================================================
--- lld/trunk/lib/Core/LinkingContext.cpp (original)
+++ lld/trunk/lib/Core/LinkingContext.cpp Wed Oct 1 15:24:30 2014
@@ -38,7 +38,7 @@ std::error_code LinkingContext::writeFil
}
bool LinkingContext::createImplicitFiles(
- std::vector<std::unique_ptr<File> > &result) const {
+ std::vector<std::unique_ptr<File> > &result) {
return this->writer().createImplicitFiles(result);
}
Modified: lld/trunk/lib/Driver/DarwinInputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinInputGraph.cpp?rev=218796&r1=218795&r2=218796&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinInputGraph.cpp (original)
+++ lld/trunk/lib/Driver/DarwinInputGraph.cpp Wed Oct 1 15:24:30 2014
@@ -56,8 +56,7 @@ std::error_code MachOFileNode::parse(con
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));
}
Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=218796&r1=218795&r2=218796&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Wed Oct 1 15:24:30 2014
@@ -85,9 +85,9 @@ static std::string canonicalizePath(Stri
}
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(Str
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, con
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, con
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, con
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,
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=218796&r1=218795&r2=218796&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Wed Oct 1 15:24:30 2014
@@ -539,8 +539,8 @@ Writer &MachOLinkingContext::writer() co
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::loa
}
-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::fin
}
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;
Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=218796&r1=218795&r2=218796&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Wed Oct 1 15:24:30 2014
@@ -88,7 +88,7 @@ std::unique_ptr<File> PECOFFLinkingConte
}
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"));
More information about the llvm-commits
mailing list