[PATCH] [ELF] Implement action for OUTPUT linker script command

Davide Italiano davide at freebsd.org
Sun Feb 1 21:52:12 PST 2015


Hi shankar.easwaran, ruiu, rafaelauler,

Parsing is in D7326

http://reviews.llvm.org/D7328

Files:
  lib/Driver/GnuLdDriver.cpp
  unittests/DriverTests/GnuLdDriverTest.cpp

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<script::Group>(c))
       if (std::error_code ec = evaluateLinkerScriptGroup(ctx, path, group, diag))
@@ -291,6 +289,8 @@
       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();
 }
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<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);
+}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7328.19127.patch
Type: text/x-patch
Size: 1748 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150202/ff17f04c/attachment.bin>


More information about the llvm-commits mailing list