|
20 | 20 | #include "llvm/Support/MD5.h"
|
21 | 21 | #include "llvm/Support/MathExtras.h"
|
22 | 22 | #include "llvm/Support/SHA1.h"
|
| 23 | +#include <regex> |
23 | 24 |
|
24 | 25 | using namespace llvm;
|
25 | 26 | using namespace llvm::dwarf;
|
@@ -384,18 +385,23 @@ void OutputSection::finalize() {
|
384 | 385 | flags |= SHF_INFO_LINK;
|
385 | 386 | }
|
386 | 387 |
|
387 |
| -// Returns true if S matches /Filename.?\.o$/. |
388 |
| -static bool isCrtBeginEnd(StringRef s, StringRef filename) { |
389 |
| - if (!s.endswith(".o")) |
390 |
| - return false; |
391 |
| - s = s.drop_back(2); |
392 |
| - if (s.endswith(filename)) |
393 |
| - return true; |
394 |
| - return !s.empty() && s.drop_back().endswith(filename); |
| 388 | +// Returns true if S is in one of the many forms the compiler driver may pass |
| 389 | +// crtbegin files. |
| 390 | +// |
| 391 | +// Gcc uses any of crtbegin[<empty>|S|T].o. |
| 392 | +// Clang uses Gcc's plus clang_rt.crtbegin[<empty>|S|T][-<arch>|<empty>].o. |
| 393 | + |
| 394 | +static bool isCrtbegin(StringRef s) { |
| 395 | + static std::regex re(R"((clang_rt\.)?crtbegin[ST]?(-.*)?\.o)"); |
| 396 | + s = sys::path::filename(s); |
| 397 | + return std::regex_match(s.begin(), s.end(), re); |
395 | 398 | }
|
396 | 399 |
|
397 |
| -static bool isCrtbegin(StringRef s) { return isCrtBeginEnd(s, "crtbegin"); } |
398 |
| -static bool isCrtend(StringRef s) { return isCrtBeginEnd(s, "crtend"); } |
| 400 | +static bool isCrtend(StringRef s) { |
| 401 | + static std::regex re(R"((clang_rt\.)?crtend[ST]?(-.*)?\.o)"); |
| 402 | + s = sys::path::filename(s); |
| 403 | + return std::regex_match(s.begin(), s.end(), re); |
| 404 | +} |
399 | 405 |
|
400 | 406 | // .ctors and .dtors are sorted by this priority from highest to lowest.
|
401 | 407 | //
|
|
0 commit comments