forked from OSchip/llvm-project
[ELF] Implement action for OUTPUT linker script command
Reviewed by: ruiu, shankarke llvm-svn: 227787
This commit is contained in:
parent
5cbde851ed
commit
104949df73
|
@ -280,9 +280,7 @@ GnuLdDriver::evalLinkerScript(ELFLinkingContext &ctx,
|
|||
if (!script)
|
||||
return LinkerScriptReaderError::parse_error;
|
||||
// Evaluate script commands.
|
||||
// Currently we only recognize this subset of linker script commands:
|
||||
// - GROUP()
|
||||
// - SEARCH_DIR()
|
||||
// Currently we only recognize this subset of linker script commands.
|
||||
for (const script::Command *c : script->_commands) {
|
||||
if (auto *group = dyn_cast<script::Group>(c))
|
||||
if (std::error_code ec = evaluateLinkerScriptGroup(ctx, path, group, diag))
|
||||
|
@ -291,6 +289,8 @@ GnuLdDriver::evalLinkerScript(ELFLinkingContext &ctx,
|
|||
ctx.addSearchPath(searchDir->getSearchPath());
|
||||
if (auto *entry = dyn_cast<script::Entry>(c))
|
||||
ctx.setEntrySymbolName(entry->getEntryName());
|
||||
if (auto *output = dyn_cast<script::Output>(c))
|
||||
ctx.setOutputPath(output->getOutputFileName());
|
||||
}
|
||||
return std::error_code();
|
||||
}
|
||||
|
|
|
@ -204,3 +204,16 @@ TEST_F(GnuLdParserTest, LinkerScriptEntry) {
|
|||
StringRef entrySymbol = _context->entrySymbolName();
|
||||
EXPECT_EQ("blah", entrySymbol);
|
||||
}
|
||||
|
||||
TEST_F(GnuLdParserTest, LinkerScriptOutput) {
|
||||
parse("ld", "a.o", nullptr);
|
||||
std::unique_ptr<MemoryBuffer> mb = MemoryBuffer::getMemBuffer(
|
||||
"OUTPUT(\"/path/to/output\")", "foo.so");
|
||||
std::string s;
|
||||
raw_string_ostream out(s);
|
||||
std::error_code ec = GnuLdDriver::evalLinkerScript(
|
||||
*_context, std::move(mb), out);
|
||||
EXPECT_FALSE(ec);
|
||||
StringRef output = _context->outputPath();
|
||||
EXPECT_EQ("/path/to/output", output);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue