[Cleanup] Remove member functions added to support nostdlib

No change in functionality.

llvm-svn: 228379
This commit is contained in:
Shankar Easwaran 2015-02-06 05:01:38 +00:00
parent c8299e1f15
commit 2ba4f5d9e3
5 changed files with 14 additions and 21 deletions

View File

@ -80,7 +80,7 @@ public:
/// Public function for testing.
static std::error_code evalLinkerScript(ELFLinkingContext &ctx,
std::unique_ptr<MemoryBuffer> mb,
raw_ostream &diag);
raw_ostream &diag, bool nostdlib);
/// A factory method to create an instance of ELFLinkingContext.
static std::unique_ptr<ELFLinkingContext>

View File

@ -303,10 +303,6 @@ public:
_scripts.push_back(std::move(script));
}
/// \brief nostdlib support.
bool nostdlib() const { return _nostdlib; }
void setNoStdLib(bool nostdlib) { _nostdlib = nostdlib; }
private:
ELFLinkingContext() LLVM_DELETED_FUNCTION;

View File

@ -265,10 +265,10 @@ addFilesFromLinkerScript(ELFLinkingContext &ctx, StringRef scriptPath,
return std::error_code();
}
std::error_code
GnuLdDriver::evalLinkerScript(ELFLinkingContext &ctx,
std::unique_ptr<MemoryBuffer> mb,
raw_ostream &diag) {
std::error_code GnuLdDriver::evalLinkerScript(ELFLinkingContext &ctx,
std::unique_ptr<MemoryBuffer> mb,
raw_ostream &diag,
bool nostdlib) {
// Read the script file from disk and parse.
StringRef path = mb->getBufferIdentifier();
auto parser = llvm::make_unique<script::Parser>(std::move(mb));
@ -293,7 +293,7 @@ GnuLdDriver::evalLinkerScript(ELFLinkingContext &ctx,
ctx.getNodes().push_back(llvm::make_unique<GroupEnd>(groupSize));
}
if (auto *searchDir = dyn_cast<script::SearchDir>(c))
if (!ctx.nostdlib())
if (!nostdlib)
ctx.addSearchPath(searchDir->getSearchPath());
if (auto *entry = dyn_cast<script::Entry>(c))
ctx.setEntrySymbolName(entry->getEntryName());
@ -406,9 +406,6 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
if (!(hasNoStdLib = parsedArgs->hasArg(OPT_nostdlib)))
ctx->addDefaultSearchDirs(baseTriple);
// -nostdlib support.
ctx->setNoStdLib(hasNoStdLib);
// Handle --demangle option(For compatibility)
if (parsedArgs->getLastArg(OPT_demangle))
ctx->setDemangleSymbols(true);
@ -638,7 +635,8 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
diag << "Cannot open " << path << ": " << ec.message() << "\n";
return false;
}
std::error_code ec = evalLinkerScript(*ctx, std::move(mb.get()), diag);
std::error_code ec =
evalLinkerScript(*ctx, std::move(mb.get()), diag, hasNoStdLib);
if (ec) {
diag << path << ": Error parsing linker script: "
<< ec.message() << "\n";

View File

@ -61,8 +61,8 @@ ELFLinkingContext::ELFLinkingContext(
_mergeCommonStrings(false), _useShlibUndefines(true),
_dynamicLinkerArg(false), _noAllowDynamicLibraries(false),
_mergeRODataToTextSegment(true), _demangle(true), _alignSegments(true),
_nostdlib(false), _outputMagic(OutputMagic::DEFAULT),
_initFunction("_init"), _finiFunction("_fini"), _sysrootPath("") {}
_outputMagic(OutputMagic::DEFAULT), _initFunction("_init"),
_finiFunction("_fini"), _sysrootPath("") {}
void ELFLinkingContext::addPasses(PassManager &pm) {
pm.add(std::unique_ptr<Pass>(new elf::OrderPass()));

View File

@ -34,13 +34,13 @@ protected:
_ctx = std::move(GnuLdDriver::createELFLinkingContext(triple));
}
void parse(StringRef script) {
void parse(StringRef script, bool nostdlib = false) {
std::unique_ptr<MemoryBuffer> mb = MemoryBuffer::getMemBuffer(
script, "foo.so");
std::string s;
raw_string_ostream out(s);
std::error_code ec = GnuLdDriver::evalLinkerScript(
*_ctx, std::move(mb), out);
std::error_code ec =
GnuLdDriver::evalLinkerScript(*_ctx, std::move(mb), out, nostdlib);
EXPECT_FALSE(ec);
};
@ -220,8 +220,7 @@ TEST_F(LinkerScriptTest, Output) {
// Test that search paths are ignored when nostdlib is set.
TEST_F(LinkerScriptTest, IgnoreSearchDirNoStdLib) {
_ctx->setNoStdLib(true);
parse("SEARCH_DIR(\"/foo/bar\")");
parse("SEARCH_DIR(\"/foo/bar\")", true /*nostdlib*/);
std::vector<StringRef> paths = _ctx->getSearchPaths();
EXPECT_EQ((size_t)0, paths.size());
}