This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH Gold] Recognize clang-style crtbegin and crtend files


On Fri, Dec 27, 2019 at 4:50 PM Cary Coutant <ccoutant@gmail.com> wrote:
> By removing this, you're allowing the "-<target-name>" part on
> gcc-style filenames as well as clang-style. Unless you need to match
> that part even without the "clang_rt." prefix, I'd prefer to keep the
> stricter matching for gcc-style filenames. And it might be a good idea
> to at least check for the "-" before the target name. We just want to
> minimize the odds of accidentally matching a user-supplied object
> file.

Thanks for the review.

Enclosed is a patch that handles clang-style names completely
separately, and also
checks for the "-" before the target name.

> (I really wish there were a better way to handle these sections.
+1

> I
> hope you need this only to support section sorting, and not for the
> special treatment of .ctors and .dtors sections, which is a legacy you
> shouldn't be saddled with in clang.)

Unfortunately, we are saddled with this for certain legacy situations,
even with clang. I
wish it weren't so as well.
diff --git a/gold/ChangeLog b/gold/ChangeLog
index cc5da7d964..63d6dbeb50 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,7 @@
+2019-11-13  Sterling Augustine <augustine.sterling@gmail.com>
+	* layout.cc (Layout::match_file_name): Handle clang-style
+	crtbegin and crtend filenames.
+
 2019-11-11  Miguel Saldivar  <saldivarcher@gmail.com>
 
 	PR 24996
diff --git a/gold/layout.cc b/gold/layout.cc
index 194d088c2a..801e48aa40 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -5581,17 +5581,31 @@ Layout::output_section_name(const Relobj* relobj, const char* name,
 // to match crtbegin.o as well as crtbeginS.o without getting confused
 // by other possibilities.  Overall matching the file name this way is
 // a dreadful hack, but the GNU linker does it in order to better
-// support gcc, and we need to be compatible.
+// support gcc, and we need to be compatible. Also handle llvm style
+// clang_rt.crtbegin.o and clang_rt.crtbegin-<target-name>.o.
 
 bool
 Layout::match_file_name(const Relobj* relobj, const char* match)
 {
+  size_t match_len = strlen(match);
   const std::string& file_name(relobj->name());
   const char* base_name = lbasename(file_name.c_str());
-  size_t match_len = strlen(match);
+  size_t base_len = strlen(base_name);
+
+  const char* clang_prefix = "clang_rt.";
+  size_t clang_len = strlen(clang_prefix);
+  if (strncmp(base_name, clang_prefix, clang_len) == 0) {
+    base_name += clang_len;
+    base_len -= clang_len;
+    if (strncmp(base_name, match, match_len) != 0)
+      return false;
+    if (*(base_name + match_len) != '.' &&
+        *(base_name + match_len) != '-')
+      return false;
+    return memcmp(base_name + base_len - 2, ".o", 2) == 0;
+  }
   if (strncmp(base_name, match, match_len) != 0)
     return false;
-  size_t base_len = strlen(base_name);
   if (base_len != match_len + 2 && base_len != match_len + 3)
     return false;
   return memcmp(base_name + base_len - 2, ".o", 2) == 0;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]