[PATCH] D74687: [LLD][ELF] - Linker script: do not fail parsing when "/DISCARD/" follows the fill expression.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 16 03:20:44 PST 2020


grimar created this revision.
grimar added reviewers: MaskRay, ruiu, psmith.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Fixes https://bugs.llvm.org/show_bug.cgi?id=44903

It is about the following case:

  SECTIONS {
    .foo : { *(.foo) } =0x90909090
    /DISCARD/ : { *(.bar) }
  }

Here while parsing the fill expression we treated the
"/" of "/DISCARD/" as operator. We should not
try to split(tokenize) it.


https://reviews.llvm.org/D74687

Files:
  lld/ELF/ScriptLexer.cpp
  lld/test/ELF/linkerscript/fill-with-discard.test


Index: lld/test/ELF/linkerscript/fill-with-discard.test
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/fill-with-discard.test
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: llvm-mc /dev/null -o %t.o -filetype=obj -triple=x86_64-unknown-linux 
+# RUN: ld.lld -o %t --script %s %t.o
+
+## Check we are able to parse scripts where "/DISCARD/" follows a section fill expression.
+
+SECTIONS {
+  .foo : { *(.foo) } =0x90909090
+  /DISCARD/ : { *(.bar) }
+}
Index: lld/ELF/ScriptLexer.cpp
===================================================================
--- lld/ELF/ScriptLexer.cpp
+++ lld/ELF/ScriptLexer.cpp
@@ -176,6 +176,10 @@
   if (s.startswith("\""))
     return {s};
 
+  // "/DISCARD/" is a special directive.
+  if (s == "/DISCARD/")
+    return {s};
+
   // Split S with operators as separators.
   std::vector<StringRef> ret;
   while (!s.empty()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74687.244863.patch
Type: text/x-patch
Size: 930 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200216/8058812a/attachment.bin>


More information about the llvm-commits mailing list