[lld] r280069 - [ELF] - Fix for: bug 29115 - linkerscript does not support non-wildcard filename spec.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 30 02:46:59 PDT 2016


Author: grimar
Date: Tue Aug 30 04:46:59 2016
New Revision: 280069

URL: http://llvm.org/viewvc/llvm-project?rev=280069&view=rev
Log:
[ELF] - Fix for: bug 29115 - linkerscript does not support non-wildcard filename spec.

FreeBSD/mips script has non-wildcard filename specifications:
.text :
{
 start.o(.text*)

Patch adds support for that, this is PR29115.

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

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/linkerscript-filename-spec.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=280069&r1=280068&r2=280069&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Aug 30 04:46:59 2016
@@ -604,9 +604,9 @@ private:
   OutputSectionCommand *readOutputSectionDescription(StringRef OutSec);
   std::vector<uint8_t> readOutputSectionFiller();
   std::vector<StringRef> readOutputSectionPhdrs();
-  InputSectionDescription *readInputSectionDescription();
+  InputSectionDescription *readInputSectionDescription(StringRef Tok);
   std::vector<StringRef> readInputFilePatterns();
-  InputSectionDescription *readInputSectionRules();
+  InputSectionDescription *readInputSectionRules(StringRef FilePattern);
   unsigned readPhdrType();
   SortKind readSortKind();
   SymbolAssignment *readProvideHidden(bool Provide, bool Hidden);
@@ -845,9 +845,10 @@ SortKind ScriptParser::readSortKind() {
   return SortNone;
 }
 
-InputSectionDescription *ScriptParser::readInputSectionRules() {
+InputSectionDescription *
+ScriptParser::readInputSectionRules(StringRef FilePattern) {
   auto *Cmd = new InputSectionDescription;
-  Cmd->FilePattern = next();
+  Cmd->FilePattern = FilePattern;
   expect("(");
 
   // Read EXCLUDE_FILE().
@@ -877,19 +878,21 @@ InputSectionDescription *ScriptParser::r
   return Cmd;
 }
 
-InputSectionDescription *ScriptParser::readInputSectionDescription() {
+InputSectionDescription *
+ScriptParser::readInputSectionDescription(StringRef Tok) {
   // Input section wildcard can be surrounded by KEEP.
   // https://sourceware.org/binutils/docs/ld/Input-Section-Keep.html#Input-Section-Keep
-  if (skip("KEEP")) {
+  if (Tok == "KEEP") {
     expect("(");
-    InputSectionDescription *Cmd = readInputSectionRules();
+    StringRef FilePattern = next();
+    InputSectionDescription *Cmd = readInputSectionRules(FilePattern);
     expect(")");
     Opt.KeptSections.insert(Opt.KeptSections.end(),
                             Cmd->SectionPatterns.begin(),
                             Cmd->SectionPatterns.end());
     return Cmd;
   }
-  return readInputSectionRules();
+  return readInputSectionRules(Tok);
 }
 
 void ScriptParser::readSort() {
@@ -938,16 +941,13 @@ ScriptParser::readOutputSectionDescripti
   expect("{");
 
   while (!Error && !skip("}")) {
-    if (peek().startswith("*") || peek() == "KEEP") {
-      Cmd->Commands.emplace_back(readInputSectionDescription());
-      continue;
-    }
-
     StringRef Tok = next();
     if (SymbolAssignment *Assignment = readProvideOrAssignment(Tok))
       Cmd->Commands.emplace_back(Assignment);
     else if (Tok == "SORT")
       readSort();
+    else if (peek() == "(")
+      Cmd->Commands.emplace_back(readInputSectionDescription(Tok));
     else
       setError("unknown command " + Tok);
   }

Modified: lld/trunk/test/ELF/linkerscript/linkerscript-filename-spec.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-filename-spec.s?rev=280069&r1=280068&r2=280069&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-filename-spec.s (original)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-filename-spec.s Tue Aug 30 04:46:59 2016
@@ -33,6 +33,24 @@
 # RUN: ld.lld -o %t4 --script %t4.script %tfirst.o %tsecond.o
 # RUN: llvm-objdump -s %t4 | FileCheck --check-prefix=SECONDFIRST %s
 
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %T/linkerscript-filename-spec1.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
+# RUN:   %p/Inputs/linkerscript-filename-spec.s -o %T/linkerscript-filename-spec2.o
+
+# RUN: echo "SECTIONS { .foo : { \
+# RUN:   linkerscript-filename-spec2.o(.foo) \
+# RUN:   linkerscript-filename-spec1.o(.foo) } }" > %t5.script
+# RUN: ld.lld -o %t5 --script %t5.script \
+# RUN:   %T/linkerscript-filename-spec1.o %T/linkerscript-filename-spec2.o
+# RUN: llvm-objdump -s %t5 | FileCheck --check-prefix=SECONDFIRST %s
+
+# RUN: echo "SECTIONS { .foo : { \
+# RUN:   linkerscript-filename-spec1.o(.foo) \
+# RUN:   linkerscript-filename-spec2.o(.foo) } }" > %t6.script
+# RUN: ld.lld -o %t6 --script %t6.script \
+# RUN:   %T/linkerscript-filename-spec1.o %T/linkerscript-filename-spec2.o
+# RUN: llvm-objdump -s %t6 | FileCheck --check-prefix=FIRSTSECOND %s
+
 .global _start
 _start:
  nop




More information about the llvm-commits mailing list