This is the mail archive of the 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 2019-12-27, Cary Coutant wrote:
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 <>
       * (Layout::match_file_name): Handle clang-style
       crtbegin and crtend filenames.

-  if (base_len != match_len + 2 && base_len != match_len + 3)
-    return false;

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@least check for the "-" before the target name. We just want to
minimize the odds of accidentally matching a user-supplied object

(I really wish there were a better way to handle these sections. 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.)


We can use a looser rule which matches GNU ld more closely.

% ld.bfd --verbose | grep -A12 ' .ctors '
  .ctors          :
    /* gcc uses crtbegin.o to find the start of
       the constructors, so we make sure it is
       first.  Because this is a wildcard, it
       doesn't matter if the user does not
       actually link against crtbegin.o; the
       linker won't look for a file to match a
       wildcard.  The wildcard also means that it
       doesn't matter which directory crtbegin.o
       is in.  */
    KEEP (*crtbegin.o(.ctors))
    KEEP (*crtbegin?.o(.ctors))

If divergence from other compiler-rt files (e.g.
libclang_rt.asan-i386.a) is not a concern, clang_rt.i386.crtbegin.o
should just work with GNU ld.

(On the clang side, I've done . Since
clang 10, all Linux builds will default to .init_array .
-fno-use-init-array (not recognized by GCC) is required to produce

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