[PATCH] D17290: [ELF] - Teach input section wildcard patterns to recognize '?' meta character.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 16 05:21:08 PST 2016


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

`?' - matches any single character
https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html 

This is used in few linker scripts I saw. Ex:
```
.init_array     :
  {
    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  }
```

http://reviews.llvm.org/D17290

Files:
  ELF/LinkerScript.cpp

Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -55,25 +55,29 @@
   return I < J ? -1 : 1;
 }
 
-// Returns true if S matches T. S may contain a meta character '*'
-// which matches zero or more occurrences of any character.
-static bool matchStr(StringRef S, StringRef T) {
+// Returns true if wildcard pattern W matches T.
+// W may contain next meta characters:
+// '*' which matches zero or more occurrences of any character.
+// '?' matches any single character.
+// Ex: matchStr(".sec*", ".sec.1") == true
+// Ex: matchStr("crtbegin?.o", "crtbeginS.o") == true
+static bool matchStr(StringRef W, StringRef T) {
   for (;;) {
-    if (S.empty())
+    if (W.empty())
       return T.empty();
-    if (S[0] == '*') {
-      S = S.substr(1);
-      if (S.empty())
+    if (W[0] == '*') {
+      W = W.substr(1);
+      if (W.empty())
         // Fast path. If a pattern is '*', it matches anything.
         return true;
       for (size_t I = 0, E = T.size(); I < E; ++I)
-        if (matchStr(S, T.substr(I)))
+        if (matchStr(W, T.substr(I)))
           return true;
       return false;
     }
-    if (T.empty() || S[0] != T[0])
+    if (T.empty() || (W[0] != T[0] && W[0] != '?'))
       return false;
-    S = S.substr(1);
+    W = W.substr(1);
     T = T.substr(1);
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17290.48067.patch
Type: text/x-patch
Size: 1390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160216/9280b8a5/attachment.bin>


More information about the llvm-commits mailing list