[lld] r245792 - [LinkerScript] Fix a crash when matching wildcards.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 22 13:36:19 PDT 2015


Author: davide
Date: Sat Aug 22 15:36:19 2015
New Revision: 245792

URL: http://llvm.org/viewvc/llvm-project?rev=245792&view=rev
Log:
[LinkerScript] Fix a crash when matching wildcards.

Submitted by:	  zan jyu via llvm-dev

Added:
    lld/trunk/test/elf/linkerscript/filename-with-wildcards.test
Modified:
    lld/trunk/lib/ReaderWriter/LinkerScript.cpp

Modified: lld/trunk/lib/ReaderWriter/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/LinkerScript.cpp?rev=245792&r1=245791&r2=245792&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/LinkerScript.cpp (original)
+++ lld/trunk/lib/ReaderWriter/LinkerScript.cpp Sat Aug 22 15:36:19 2015
@@ -2557,7 +2557,7 @@ static bool wildcardMatch(StringRef patt
     switch (*j) {
     case '*':
       while (!wildcardMatch(pattern.drop_front(j - pattern.begin() + 1),
-                            name.drop_front(i - name.begin() + 1))) {
+                            name.drop_front(i - name.begin()))) {
         if (i == name.end())
           return false;
         ++i;
@@ -2565,6 +2565,7 @@ static bool wildcardMatch(StringRef patt
       break;
     case '?':
       // Matches any character
+      ++i;
       break;
     case '[': {
       // Matches a range of characters specified between brackets
@@ -2577,20 +2578,22 @@ static bool wildcardMatch(StringRef patt
         return false;
 
       j = pattern.begin() + end;
+      ++i;
       break;
     }
     case '\\':
       ++j;
       if (*j != *i)
         return false;
+      ++i;
       break;
     default:
       // No wildcard character means we must match exactly the same char
       if (*j != *i)
         return false;
+      ++i;
       break;
     }
-    ++i;
   }
 
   // If our pattern has't consumed the entire string, it is not a match

Added: lld/trunk/test/elf/linkerscript/filename-with-wildcards.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/linkerscript/filename-with-wildcards.test?rev=245792&view=auto
==============================================================================
--- lld/trunk/test/elf/linkerscript/filename-with-wildcards.test (added)
+++ lld/trunk/test/elf/linkerscript/filename-with-wildcards.test Sat Aug 22 15:36:19 2015
@@ -0,0 +1,49 @@
+/*
+Tests a linker script that uses the SECTIONS command with rules containing
+wildcards that matching input object files.
+*/
+
+ENTRY(_start)
+
+SECTIONS
+{
+  . = 0x500000;
+  .foo : { *p1.o(.text .rodata*) }
+  .bar : { *(.text .rodata*) }
+}
+
+/*
+RUN: mkdir -p %T
+RUN: yaml2obj -format=elf %p/Inputs/prog1.o.yaml -o=%T/p1.o
+RUN: yaml2obj -format=elf %p/Inputs/prog2.o.yaml -o=%T/p2.o
+RUN: yaml2obj -format=elf %p/Inputs/prog3.o.yaml -o=%T/p3.o
+RUN: cd %T
+
+RUN: lld -flavor gnu  -target x86_64 -T %s p1.o p2.o p3.o \
+RUN:   -static -o %t1
+RUN: llvm-readobj -s %t1 | FileCheck -check-prefix CHECKSECTIONS %s
+
+CHECKSECTIONS:       Index: 1
+CHECKSECTIONS:       Name: .foo
+CHECKSECTIONS:       Address: 0x500000
+CHECKSECTIONS:       Size: 33
+
+CHECKSECTIONS:       Index: 2
+CHECKSECTIONS:       Name: .bar
+CHECKSECTIONS:       Address: 0x500030
+CHECKSECTIONS:       Size: 52
+
+RUN: llvm-readobj -symbols %t1 | FileCheck -check-prefix CHECKSYMS %s
+
+CHECKSYMS:      Name: main
+CHECKSYMS-NEXT: Value: 0x500000
+
+CHECKSYMS:      Name: prog2
+CHECKSYMS-NEXT: Value: 0x500030
+
+CHECKSYMS:      Name: write
+CHECKSYMS-NEXT: Value: 0x500040
+
+CHECKSYMS:      Name: _start
+CHECKSYMS-NEXT: Value: 0x500048
+*/




More information about the llvm-commits mailing list