[Gold] Recognize clang-style crtbegin and crtend files

Message ID CAGSvup8i2X19GxpOG2=nBm+JZeFvJjAne8tfWZ0q4nGtXsfqiw@mail.gmail.com
State New
Headers show
Series
  • [Gold] Recognize clang-style crtbegin and crtend files
Related show

Commit Message

augustine.sterling@gmail.com Nov. 13, 2019, 10:07 p.m.
For installations of its native implementations of crtbegin and
crtend, Clang uses custom names of the form:

clang_rt.crtbegin[-target-name].o

This patch modifies Layout::match_file_name so that gold treats these
files the same as any other crtbegin and crtend.

2019-11-13  Sterling Augustine <augustine.sterling@gmail.com>
       * layout.cc (Layout::match_file_name): Handle clang-style
       crtbegin and crtend filenames.

OK for trunk?

Comments

augustine.sterling@gmail.com Nov. 15, 2019, 11:24 p.m. | #1
On Wed, Nov 13, 2019 at 2:07 PM augustine.sterling@gmail.com
<augustine.sterling@gmail.com> wrote:
> 2019-11-13  Sterling Augustine <augustine.sterling@gmail.com>

>        * layout.cc (Layout::match_file_name): Handle clang-style

>        crtbegin and crtend filenames.


Ping?
Fangrui Song Nov. 16, 2019, 5:59 a.m. | #2
On 2019-11-15, augustine.sterling@gmail.com wrote:
>On Wed, Nov 13, 2019@2:07 PM augustine.sterling@gmail.com

><augustine.sterling@gmail.com> wrote:

>> 2019-11-13  Sterling Augustine <augustine.sterling@gmail.com>

>>        * layout.cc (Layout::match_file_name): Handle clang-style

>>        crtbegin and crtend filenames.

>

>Ping?


https://sourceware.org/ml/binutils/2019-09/msg00003.html


BTW, the patch looks good to me.

Patch

diff --git a/gold/layout.cc b/gold/layout.cc
index 194d088c2a..dc841b77c8 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -5581,19 +5581,21 @@  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[X]-<target-name>.o.
 
 bool
 Layout::match_file_name(const Relobj* relobj, const char* match)
 {
   const std::string& file_name(relobj->name());
   const char* base_name = lbasename(file_name.c_str());
+  const char* clang_prefix = "clang_rt.";
+  if (strncmp(base_name, clang_prefix, strlen(clang_prefix)) == 0)
+    base_name += strlen(clang_prefix);
   size_t match_len = strlen(match);
   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;
 }