2013-08-06 22:31:59 +00:00
|
|
|
//===- lib/Core/LinkingContext.cpp - Linker Context Object Interface ------===//
|
2013-01-22 02:15:30 +00:00
|
|
|
//
|
|
|
|
|
// The LLVM Linker
|
|
|
|
|
//
|
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2013-08-06 22:31:59 +00:00
|
|
|
#include "lld/Core/LinkingContext.h"
|
2016-11-04 17:39:46 +00:00
|
|
|
#include "lld/Core/File.h"
|
|
|
|
|
#include "lld/Core/Node.h"
|
2014-06-11 21:47:51 +00:00
|
|
|
#include "lld/Core/Simple.h"
|
2015-01-21 22:54:56 +00:00
|
|
|
#include "lld/Core/Writer.h"
|
2016-11-04 17:39:46 +00:00
|
|
|
#include <algorithm>
|
2013-01-22 02:15:30 +00:00
|
|
|
|
|
|
|
|
namespace lld {
|
2013-04-04 18:59:24 +00:00
|
|
|
|
2016-11-04 17:39:46 +00:00
|
|
|
LinkingContext::LinkingContext() = default;
|
2013-04-04 18:59:24 +00:00
|
|
|
|
2016-11-04 17:39:46 +00:00
|
|
|
LinkingContext::~LinkingContext() = default;
|
2013-01-22 02:15:30 +00:00
|
|
|
|
2018-06-12 02:34:04 +00:00
|
|
|
bool LinkingContext::validate() {
|
|
|
|
|
return validateImpl();
|
2013-06-11 12:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-30 23:10:39 +00:00
|
|
|
llvm::Error LinkingContext::writeFile(const File &linkedFile) const {
|
2013-08-06 22:31:59 +00:00
|
|
|
return this->writer().writeFile(linkedFile, _outputPath);
|
2013-01-22 02:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-07 02:47:09 +00:00
|
|
|
std::unique_ptr<File> LinkingContext::createEntrySymbolFile() const {
|
2014-03-28 19:02:06 +00:00
|
|
|
return createEntrySymbolFile("<command line option -e>");
|
2013-12-26 06:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<File>
|
|
|
|
|
LinkingContext::createEntrySymbolFile(StringRef filename) const {
|
2013-08-31 05:27:38 +00:00
|
|
|
if (entrySymbolName().empty())
|
|
|
|
|
return nullptr;
|
2016-01-14 22:55:38 +00:00
|
|
|
std::unique_ptr<SimpleFile> entryFile(new SimpleFile(filename,
|
|
|
|
|
File::kindEntryObject));
|
2013-08-31 05:27:38 +00:00
|
|
|
entryFile->addAtom(
|
|
|
|
|
*(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbolName())));
|
|
|
|
|
return std::move(entryFile);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-07 02:47:09 +00:00
|
|
|
std::unique_ptr<File> LinkingContext::createUndefinedSymbolFile() const {
|
2014-03-28 19:02:06 +00:00
|
|
|
return createUndefinedSymbolFile("<command line option -u or --defsym>");
|
2013-12-26 06:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<File>
|
|
|
|
|
LinkingContext::createUndefinedSymbolFile(StringRef filename) const {
|
2013-08-31 05:27:38 +00:00
|
|
|
if (_initialUndefinedSymbols.empty())
|
|
|
|
|
return nullptr;
|
2016-01-14 22:55:38 +00:00
|
|
|
std::unique_ptr<SimpleFile> undefinedSymFile(
|
|
|
|
|
new SimpleFile(filename, File::kindUndefinedSymsObject));
|
2014-05-02 21:48:01 +00:00
|
|
|
for (StringRef undefSym : _initialUndefinedSymbols)
|
2013-08-31 05:27:38 +00:00
|
|
|
undefinedSymFile->addAtom(*(new (_allocator) SimpleUndefinedAtom(
|
2014-05-02 21:48:01 +00:00
|
|
|
*undefinedSymFile, undefSym)));
|
2013-08-31 05:27:38 +00:00
|
|
|
return std::move(undefinedSymFile);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-31 19:15:42 +00:00
|
|
|
void LinkingContext::createInternalFiles(
|
2016-11-04 17:39:46 +00:00
|
|
|
std::vector<std::unique_ptr<File>> &result) const {
|
2014-05-22 00:36:36 +00:00
|
|
|
if (std::unique_ptr<File> file = createEntrySymbolFile())
|
|
|
|
|
result.push_back(std::move(file));
|
|
|
|
|
if (std::unique_ptr<File> file = createUndefinedSymbolFile())
|
|
|
|
|
result.push_back(std::move(file));
|
2013-10-07 02:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-22 02:15:30 +00:00
|
|
|
} // end namespace lld
|