[PATCH] D25094: [ELF] - Linkerscript: cleanup and introduce nextJoined().

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 08:04:56 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.

Patch do 2 things:

1. It removes "section header name is empty" error. It looks not possible to get it. I think the only way to have Tok.empty() condition is when next() returns empty token because of error, in that case setError() will do nothing and itself useless.
2. There are cases when tokens can go in pairs, like "=0xFF" vs "= 0xFF". And we should handle combined and separate forms. I suggest to have some function like nextJoined() to proccess such cases to simplify parsing.


https://reviews.llvm.org/D25094

Files:
  ELF/LinkerScript.cpp
  ELF/ScriptParser.cpp
  ELF/ScriptParser.h


Index: ELF/ScriptParser.h
===================================================================
--- ELF/ScriptParser.h
+++ ELF/ScriptParser.h
@@ -28,6 +28,7 @@
   static StringRef skipSpace(StringRef S);
   bool atEOF();
   StringRef next();
+  StringRef nextJoined();
   StringRef peek();
   bool skip(StringRef Tok);
   void expect(StringRef Expect);
Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -129,6 +129,13 @@
   return Tokens[Pos++];
 }
 
+StringRef ScriptParserBase::nextJoined() {
+  StringRef Tok = next();
+  if (Tok.size() == 1)
+    return next();
+  return Tok.drop_front(std::min(Tok.size(), (size_t)1));
+}
+
 StringRef ScriptParserBase::peek() {
   StringRef Tok = next();
   if (Error)
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -1328,10 +1328,8 @@
   }
   Cmd->Phdrs = readOutputSectionPhdrs();
 
-  if (skip("="))
-    Cmd->Filler = readOutputSectionFiller(next());
-  else if (peek().startswith("="))
-    Cmd->Filler = readOutputSectionFiller(next().drop_front());
+  if (peek().startswith("="))
+    Cmd->Filler = readOutputSectionFiller(nextJoined());
 
   return Cmd;
 }
@@ -1652,15 +1650,8 @@
 
 std::vector<StringRef> ScriptParser::readOutputSectionPhdrs() {
   std::vector<StringRef> Phdrs;
-  while (!Error && peek().startswith(":")) {
-    StringRef Tok = next();
-    Tok = (Tok.size() == 1) ? next() : Tok.substr(1);
-    if (Tok.empty()) {
-      setError("section header name is empty");
-      break;
-    }
-    Phdrs.push_back(Tok);
-  }
+  while (!Error && peek().startswith(":"))
+    Phdrs.push_back(nextJoined());
   return Phdrs;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25094.73053.patch
Type: text/x-patch
Size: 1785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160930/8410014e/attachment.bin>


More information about the llvm-commits mailing list