2013-08-07 06:31:59 +08:00
|
|
|
//===- lib/Core/LinkingContext.cpp - Linker Context Object Interface ------===//
|
2013-01-22 10:15:30 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-01-22 10:15:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-08-07 06:31:59 +08:00
|
|
|
#include "lld/Core/LinkingContext.h"
|
2016-11-05 01:39:46 +08:00
|
|
|
#include "lld/Core/File.h"
|
|
|
|
#include "lld/Core/Node.h"
|
2014-06-12 05:47:51 +08:00
|
|
|
#include "lld/Core/Simple.h"
|
2015-01-22 06:54:56 +08:00
|
|
|
#include "lld/Core/Writer.h"
|
2016-11-05 01:39:46 +08:00
|
|
|
#include <algorithm>
|
2013-01-22 10:15:30 +08:00
|
|
|
|
|
|
|
namespace lld {
|
2013-04-05 02:59:24 +08:00
|
|
|
|
2016-11-05 01:39:46 +08:00
|
|
|
LinkingContext::LinkingContext() = default;
|
2013-04-05 02:59:24 +08:00
|
|
|
|
2016-11-05 01:39:46 +08:00
|
|
|
LinkingContext::~LinkingContext() = default;
|
2013-01-22 10:15:30 +08:00
|
|
|
|
2018-06-12 10:34:04 +08:00
|
|
|
bool LinkingContext::validate() {
|
|
|
|
return validateImpl();
|
2013-06-11 20:36:05 +08:00
|
|
|
}
|
|
|
|
|
2016-03-31 07:10:39 +08:00
|
|
|
llvm::Error LinkingContext::writeFile(const File &linkedFile) const {
|
2013-08-07 06:31:59 +08:00
|
|
|
return this->writer().writeFile(linkedFile, _outputPath);
|
2013-01-22 10:15:30 +08:00
|
|
|
}
|
|
|
|
|
2013-10-07 10:47:09 +08:00
|
|
|
std::unique_ptr<File> LinkingContext::createEntrySymbolFile() const {
|
2014-03-29 03:02:06 +08:00
|
|
|
return createEntrySymbolFile("<command line option -e>");
|
2013-12-26 14:35:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<File>
|
|
|
|
LinkingContext::createEntrySymbolFile(StringRef filename) const {
|
2013-08-31 13:27:38 +08:00
|
|
|
if (entrySymbolName().empty())
|
|
|
|
return nullptr;
|
2016-01-15 06:55:38 +08:00
|
|
|
std::unique_ptr<SimpleFile> entryFile(new SimpleFile(filename,
|
|
|
|
File::kindEntryObject));
|
2013-08-31 13:27:38 +08:00
|
|
|
entryFile->addAtom(
|
|
|
|
*(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbolName())));
|
|
|
|
return std::move(entryFile);
|
|
|
|
}
|
|
|
|
|
2013-10-07 10:47:09 +08:00
|
|
|
std::unique_ptr<File> LinkingContext::createUndefinedSymbolFile() const {
|
2014-03-29 03:02:06 +08:00
|
|
|
return createUndefinedSymbolFile("<command line option -u or --defsym>");
|
2013-12-26 14:35:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<File>
|
|
|
|
LinkingContext::createUndefinedSymbolFile(StringRef filename) const {
|
2013-08-31 13:27:38 +08:00
|
|
|
if (_initialUndefinedSymbols.empty())
|
|
|
|
return nullptr;
|
2016-01-15 06:55:38 +08:00
|
|
|
std::unique_ptr<SimpleFile> undefinedSymFile(
|
|
|
|
new SimpleFile(filename, File::kindUndefinedSymsObject));
|
2014-05-03 05:48:01 +08:00
|
|
|
for (StringRef undefSym : _initialUndefinedSymbols)
|
2013-08-31 13:27:38 +08:00
|
|
|
undefinedSymFile->addAtom(*(new (_allocator) SimpleUndefinedAtom(
|
2014-05-03 05:48:01 +08:00
|
|
|
*undefinedSymFile, undefSym)));
|
2013-08-31 13:27:38 +08:00
|
|
|
return std::move(undefinedSymFile);
|
|
|
|
}
|
|
|
|
|
2014-01-01 03:15:42 +08:00
|
|
|
void LinkingContext::createInternalFiles(
|
2016-11-05 01:39:46 +08:00
|
|
|
std::vector<std::unique_ptr<File>> &result) const {
|
2014-05-22 08:36:36 +08: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 10:47:09 +08:00
|
|
|
}
|
|
|
|
|
2013-01-22 10:15:30 +08:00
|
|
|
} // end namespace lld
|