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); } }