public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: richard clark <richard.xnu.clark@gmail.com>,
	Mark Rutland <mark.rutland@arm.com>,
	gcc-help@gcc.gnu.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: undefined reference to `__aarch64_cas4_sync' error on arm64 native build
Date: Tue, 09 Jan 2024 16:09:20 +0800	[thread overview]
Message-ID: <4ee8067e72028b070d92e10fa33ddde3a498cb48.camel@xry111.site> (raw)
In-Reply-To: <20240109074843.GI19790@gate.crashing.org>

On Tue, 2024-01-09 at 01:48 -0600, Segher Boessenkool wrote:
> On Tue, Jan 09, 2024 at 11:05:57AM +0800, Xi Ruoyao via Gcc-help wrote:
> > But the Linux kernel cannot use neither libc.so nor libgcc.a.
> 
> I have built Linux using libgcc for many years.  It is as easy as
> 
> +LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
> +libs-y += $(LIBGCC)
> 
> > (I know
> > some non-Linux kernel developers are overusing libgcc.a for kernels, but
> > IMO this is just wrong and Linux developers also do not do this.  If the
> > Linux kernel needs a symbol from libgcc the developers just provide
> > their own implementation.)
> 
> Yes, and often they have fallen behind.  When they eventually catch up
> they usually just copy the GCC code anyway.
> 
> Originally the only reasonable argument for not linking against libgcc
> was so kernel code would not accidentally use double-length divisions.
> There are other simple ways to have all uses of __divti3 and similar
> create link errors, so that is not really a good argument.
> 
> libgcc is an essential part of the compiler.  For most targets, for most
> code, GCC will not generate function calls, there usually are faster (or
> smaller) things it can do, but it still is necessary to have libgcc for
> more uncommon things.  Using a partial copy of it, behind the times,
> and maybe even incompatible, is not a great idea.

But for many targets the kernel uses the soft-float ABI while the user
space uses the hard-float ABI and the linker generally refuses to link
them altogether.  You may argue that "hey, build all multilibs" but I'd
say it's stupid and it does not solve all issues:

If GCC is configured with things like --with-arch=something, libgcc can
contain (FP/vector) instructions unsafe to use in kernel w/o special
handling.  Currently this issue is making the process very nasty to
build systemd-boot on LoongArch desktop distros where the toolchain
configured with vector extensions enabled by default.

If libgcc is so vital GCC needs to provide a way to make it work for a
set of compiler switches incompatible with any pre-built multilib.  For
example, installing the source of libgcc into /usr/lib/gcc and provide a
tool to build a libgcc.a with the specified options.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2024-01-09  8:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02  3:29 richard clark
2024-01-02  8:53 ` richard clark
2024-01-04 18:18   ` Mark Rutland
2024-01-08  1:28     ` richard clark
2024-01-08 10:51       ` Mark Rutland
2024-01-08 10:56         ` Xi Ruoyao
2024-01-09  2:55           ` richard clark
2024-01-09  3:05             ` Xi Ruoyao
2024-01-09  6:04               ` richard clark
2024-01-09  7:48               ` Segher Boessenkool
2024-01-09  8:09                 ` Xi Ruoyao [this message]
2024-01-09  8:26                   ` Segher Boessenkool
2024-01-10  5:59                     ` richard clark
2024-01-10 14:10                       ` Segher Boessenkool
2024-01-11  1:42                         ` richard clark
2024-01-11 11:26                           ` Mark Rutland
2024-01-15  9:23                             ` richard clark
2024-01-09  2:52         ` richard clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ee8067e72028b070d92e10fa33ddde3a498cb48.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=gcc-help@gcc.gnu.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=richard.xnu.clark@gmail.com \
    --cc=segher@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).