Index: lib/Driver/GnuLdDriver.cpp =================================================================== --- lib/Driver/GnuLdDriver.cpp +++ lib/Driver/GnuLdDriver.cpp @@ -280,9 +280,7 @@ 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(c)) if (std::error_code ec = evaluateLinkerScriptGroup(ctx, path, group, diag)) @@ -291,6 +289,8 @@ ctx.addSearchPath(searchDir->getSearchPath()); if (auto *entry = dyn_cast(c)) ctx.setEntrySymbolName(entry->getEntryName()); + if (auto *output = dyn_cast(c)) + ctx.setOutputPath(output->getOutputFileName()); } return std::error_code(); } Index: unittests/DriverTests/GnuLdDriverTest.cpp =================================================================== --- unittests/DriverTests/GnuLdDriverTest.cpp +++ unittests/DriverTests/GnuLdDriverTest.cpp @@ -204,3 +204,16 @@ StringRef entrySymbol = _context->entrySymbolName(); EXPECT_EQ("blah", entrySymbol); } + +TEST_F(GnuLdParserTest, LinkerScriptOutput) { + parse("ld", "a.o", nullptr); + std::unique_ptr 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); +}