[PATCH] D69313: Handle more crt*.o filename variants.

Sterling Augustine via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 22 11:05:49 PDT 2019


saugustine created this revision.
saugustine added reviewers: MaskRay, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Crt files are special cased by name when dealing with ctor and dtor
sections, but the current code misses certain variants. In particular, those
named when clang takes the code path in
clang/lib/Driver/ToolChain.cpp:416, where crtfiles are named:

clang_rt.<component>-<arch>-<env>.<suffix>

Previously, the code only handled:
clang_rt.<component>.<suffix>
<component>.<suffix>

This revision fixes that.


Repository:
  rL LLVM

https://reviews.llvm.org/D69313

Files:
  lld/ELF/OutputSections.cpp


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][<empty>|S|T].o.
+// Clang uses Gcc's plus clang_rt.crt[begin|end][<empty>|S|T][-<arch>|<empty>].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"); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69313.226059.patch
Type: text/x-patch
Size: 1034 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191022/9c44c4f0/attachment.bin>


More information about the llvm-commits mailing list