[PATCH] D13668: [ELF2/LinkerScript] Fix OUTPUT_FORMAT directive parsing

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 12 13:00:56 PDT 2015


davide created this revision.
davide added reviewers: ruiu, rafael.
davide added a subscriber: llvm-commits.

Right now the parser recognizes 
OUTPUT_ARCH("foo")
but not OUTPUT_ARCH("foo", "goo", "blah")
This patch is an attempt to fix. 

Side note:
Also, the diagnostic we emit is currently very uninformative. 
In the future, I think we could improve this aspect showing which directive failed to parse -- or even better, line/column of failure. I would like to discuss design further.

http://reviews.llvm.org/D13668

Files:
  ELF/LinkerScript.cpp
  test/elf2/linkerscript-ouputgroup.s

Index: test/elf2/linkerscript-ouputgroup.s
===================================================================
--- test/elf2/linkerscript-ouputgroup.s
+++ test/elf2/linkerscript-ouputgroup.s
@@ -0,0 +1,5 @@
+# REQUIRES: x86
+# RUN: echo "OUTPUT_FORMAT(\"elf64-x86-64\")" > %t.script
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t1
+# RUN: ld.lld2 -shared -o %t2 %t1 %t.script
+# RUN: llvm-readobj %t2 > /dev/null
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -211,8 +211,17 @@
 void LinkerScript::readOutputFormat() {
   // Error checking only for now.
   expect("(");
-  next();
-  expect(")");
+  StringRef Tok = next();
+  for (;;) {
+    Tok = next();
+    if (Tok == ")")
+      return;
+    if (Tok == ",")
+      // Parse the identifier now.
+      next();
+      continue;
+    error("unexpected token: " + Tok);
+  }
 }
 
 void LinkerScript::readSearchDir() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13668.37151.patch
Type: text/x-patch
Size: 995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151012/18b861eb/attachment-0001.bin>


More information about the llvm-commits mailing list