This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH Gold] Recognize clang-style crtbegin and crtend files
- From: Fangrui Song <i at maskray dot me>
- To: Cary Coutant <ccoutant at gmail dot com>
- Cc: "augustine dot sterling at gmail dot com" <augustine dot sterling at gmail dot com>, Binutils <binutils at sourceware dot org>
- Date: Fri, 27 Dec 2019 21:57:33 -0800
- Subject: Re: [PATCH Gold] Recognize clang-style crtbegin and crtend files
- References: <CAGSvup8i2X19GxpOG2=nBm+JZeFvJjAne8tfWZ0q4nGtXsfqiw@mail.gmail.com> <CAJimCsHjm4BdRCY15jBbCkm7uK0cqZ+UY-hRrEH-4FGxY=uMCw@mail.gmail.com>
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 <augustine.sterling@gmail.com>
* layout.cc (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
file.
(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.)
-cary
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 https://reviews.llvm.org/D71393 . Since
clang 10, all Linux builds will default to .init_array .
-fno-use-init-array (not recognized by GCC) is required to produce
.ctors)