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 Tue, Jan 7, 2020 at 5:26 PM Cary Coutant <ccoutant@gmail.com> wrote:
> +    if (*(base_name + match_len) != '.' &&
> +        *(base_name + match_len) != '-')
> +      return false;
>
> Please write these as base_name[match_len].

Updated.

> This seems to imply that the filename convention is not
> clang_rt.crtbegin-<target>.o, but instead
> clang_rt.<target>.crtbegin.o.

To the best of my knowledge, clang never uses this form. I haven't
seen it in the wild.

> Can you clarify which of these two naming conventions you intend to
> support? If it's the former, this patch is OK with the above change.
> If the latter, I think you'll need to adjust this patch.

Clang uses two forms of its own (plus all of the gcc ones), which can
be found in clang/lib/Driver/ToolChain.cpp:416:

$(target_directory)/clang_rt.crtbegin.o
clang_rt.crtbegin-$target.o

This updated patch supports both of those forms.
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..ebd82df146 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -5581,17 +5581,30 @@ 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]