[PATCH] Implement semantic action for SEARCH_DIR linker script command

Davide Italiano davide at freebsd.org
Tue Jan 27 18:52:32 PST 2015


Hi ruiu, rafaelauler,

The title says almost everything. As a side note, this is needed, among others by the FreeBSD kernel linker script.

http://reviews.llvm.org/D7220

Files:
  lib/Driver/GnuLdDriver.cpp

Index: lib/Driver/GnuLdDriver.cpp
===================================================================
--- lib/Driver/GnuLdDriver.cpp
+++ lib/Driver/GnuLdDriver.cpp
@@ -267,6 +267,15 @@
 }

 static std::error_code
+evaluateLinkerScriptSearchDir(ELFLinkingContext &ctx,
+                              const script::SearchDir *searchDir)
+{
+
+  ctx.addSearchPath(searchDir->getSearchPath());
+  return std::error_code();
+}
+
+static std::error_code
 evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path,
                      raw_ostream &diag) {
   // Read the script file from disk and parse.
@@ -281,11 +290,17 @@
     return LinkerScriptReaderError::parse_error;

   // Evaluate script commands.
-  // Currently we only recognize GROUP() command.
-  for (const script::Command *c : script->_commands)
+  // Currently we only recognize a subset of the commands:
+  // - GROUP()
+  // - SEARCH_DIR()
+  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))
         return ec;
+    if (auto *searchDir = dyn_cast<script::SearchDir>(c))
+      if (std::error_code ec = evaluateLinkerScriptSearchDir(ctx, searchDir))
+        return ec;
+   }
   return std::error_code();
 }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7220.18802.patch
Type: text/x-patch
Size: 1315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150128/6f258316/attachment.bin>


More information about the llvm-commits mailing list