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

Sterling Augustine via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 24 12:18:56 PDT 2019


saugustine updated this revision to Diff 226310.
saugustine marked 3 inline comments as done.
saugustine added a comment.

- Add test. Address other comments.
- remove llvm namespace.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69313/new/

https://reviews.llvm.org/D69313

Files:
  lld/ELF/OutputSections.cpp
  lld/test/ELF/ctors_dtors_priority.s


Index: lld/test/ELF/ctors_dtors_priority.s
===================================================================
--- lld/test/ELF/ctors_dtors_priority.s
+++ lld/test/ELF/ctors_dtors_priority.s
@@ -3,15 +3,27 @@
 // Test .ctors* and .dtors* are sorted by priority.
 
 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
+// RUN: mkdir -p %t
 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
-// RUN:   %p/Inputs/ctors_dtors_priority1.s -o %t-crtbegin.o
+// RUN:   %p/Inputs/ctors_dtors_priority1.s -o %t/crtbegin.o
 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
 // RUN:   %p/Inputs/ctors_dtors_priority2.s -o %t2
 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
-// RUN:   %p/Inputs/ctors_dtors_priority3.s -o %t-crtend.o
-// RUN: ld.lld %t1 %t2 %t-crtend.o %t-crtbegin.o -o %t.exe
+// RUN:   %p/Inputs/ctors_dtors_priority3.s -o %t/crtend.o
+// RUN: ld.lld %t1 %t2 %t/crtend.o %t/crtbegin.o -o %t.exe
 // RUN: llvm-objdump -s %t.exe | FileCheck %s
 
+// RUN: cp %t/crtbegin.o %t/clang_rt.crtbegin.o
+// RUN: cp %t/crtend.o %t/clang_rt.crtend.o
+// RUN: ld.lld %t1 %t2 %t/clang_rt.crtend.o %t/clang_rt.crtbegin.o -o %t.clang_rt.exe
+// RUN: llvm-objdump -s %t.clang_rt.exe | FileCheck %s
+
+// RUN: cp %t/crtbegin.o %t/clang_rt.crtbegin-x86_64.o
+// RUN: cp %t/crtend.o %t/clang_rt.crtend-x86_64.o
+// RUN: ld.lld %t1 %t2 %t/clang_rt.crtend-x86_64.o %t/clang_rt.crtbegin-x86_64.o -o %t.clang_rt-arch.exe
+// RUN: llvm-objdump -s %t.clang_rt-arch.exe | FileCheck %s
+
+	
 .globl _start
 _start:
   nop
Index: lld/ELF/OutputSections.cpp
===================================================================
--- lld/ELF/OutputSections.cpp
+++ lld/ELF/OutputSections.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/SHA1.h"
+#include <regex>
 
 using namespace llvm;
 using namespace llvm::dwarf;
@@ -384,18 +385,23 @@
   flags |= SHF_INFO_LINK;
 }
 
-// Returns true if S matches /Filename.?\.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);
+// Returns true if S is in one of the many forms the compiler driver may pass
+// crtbegin files.
+//
+// Gcc uses any of crtbegin[<empty>|S|T].o.
+// Clang uses Gcc's plus clang_rt.crtbegin[<empty>|S|T][-<arch>|<empty>].o.
+
+static bool isCrtbegin(StringRef s) {
+  static std::regex re(R"((clang_rt\.)?crtbegin[ST]?(-.*)?\.o)");
+  std::string F = sys::path::filename(s);
+  return std::regex_match(F, re);
 }
 
-static bool isCrtbegin(StringRef s) { return isCrtBeginEnd(s, "crtbegin"); }
-static bool isCrtend(StringRef s) { return isCrtBeginEnd(s, "crtend"); }
+static bool isCrtend(StringRef s) {
+  static std::regex re(R"((clang_rt\.)?crtend[ST]?(-.*)?\.o)");
+  std::string F = sys::path::filename(s);
+  return std::regex_match(F, re);
+}
 
 // .ctors and .dtors are sorted by this priority from highest to lowest.
 //


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69313.226310.patch
Type: text/x-patch
Size: 3080 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191024/7d6ad48a/attachment.bin>


More information about the llvm-commits mailing list