[lld] r358874 - [LLD][ELF] - Handle quoted strings in the linker scripts correctly.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 22 00:57:07 PDT 2019


Author: grimar
Date: Mon Apr 22 00:57:07 2019
New Revision: 358874

URL: http://llvm.org/viewvc/llvm-project?rev=358874&view=rev
Log:
[LLD][ELF] - Handle quoted strings in the linker scripts correctly.

This is the https://bugs.llvm.org/show_bug.cgi?id=41356,

Seems it is kind of unusual case but it is possible to
have sections that require quotes for their namings.
Like "aaa bbb".

This patch adds support for those.

Differential revision: https://reviews.llvm.org/D60901

Added:
    lld/trunk/test/ELF/linkerscript/quoted-section-name.test
Modified:
    lld/trunk/ELF/ScriptParser.cpp

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=358874&r1=358873&r2=358874&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Mon Apr 22 00:57:07 2019
@@ -636,7 +636,7 @@ std::vector<SectionPattern> ScriptParser
 
     std::vector<StringRef> V;
     while (!errorCount() && peek() != ")" && peek() != "EXCLUDE_FILE")
-      V.push_back(next());
+      V.push_back(unquote(next()));
 
     if (!V.empty())
       Ret.push_back({std::move(ExcludeFilePat), StringMatcher(V)});

Added: lld/trunk/test/ELF/linkerscript/quoted-section-name.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/quoted-section-name.test?rev=358874&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/quoted-section-name.test (added)
+++ lld/trunk/test/ELF/linkerscript/quoted-section-name.test Mon Apr 22 00:57:07 2019
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+
+## Handling of quotes is tricky sometimes. Check we do that right and include
+## "foo bar" section into .data as expected.
+
+# RUN: echo '.section "foo bar", "aw"; nop' | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t
+# RUN: ld.lld %t --script %s -o %t2 --print-map | FileCheck %s
+# CHECK:      .data
+# CHECK-NEXT:   {{.*}}(foo bar)
+
+SECTIONS {
+  .data : { *("foo bar") }
+}




More information about the llvm-commits mailing list