Index: lld/ELF/OutputSections.cpp =================================================================== --- lld/ELF/OutputSections.cpp +++ lld/ELF/OutputSections.cpp @@ -384,14 +384,21 @@ flags |= SHF_INFO_LINK; } -// Returns true if S matches /Filename.?\.o$/. +// Returns true if S is in one of the many forms the driver may +// pass crtbegin and crtend files. +// +// Gcc uses any of crt[begin|end][|S|T].o. +// Clang uses Gcc's plus clang_rt.crt[begin|end][|S|T][-|].o. static bool isCrtBeginEnd(StringRef s, StringRef filename) { if (!s.endswith(".o")) return false; - s = s.drop_back(2); - if (s.endswith(filename)) - return true; - return !s.empty() && s.drop_back().endswith(filename); + s = llvm::sys::path::filename(s); + s.consume_front("clang_rt."); + if (s.consume_front(filename)) { + char c = s.front(); + return c == '.' || c == 'T' || c == 'S' || c == '-'; + } + return false; } static bool isCrtbegin(StringRef s) { return isCrtBeginEnd(s, "crtbegin"); }