Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Apr 2026 18:05:45 -0700
From:      Mark Millard <marklmi@yahoo.com>
To:        John Baldwin <jhb@FreeBSD.org>, Andrew Turner <andrew@FreeBSD.org>, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   Re: git: e63eee84cad5 - main - libgcc_s: Add a linker script to link to libgcc
Message-ID:  <cd2ba351-68d6-4186-95ce-714959721ade@yahoo.com>
In-Reply-To: <30459007-56a1-4edf-8b20-2921e8e2e420@FreeBSD.org>
References:  <69ef4ad1.1c7d4.4b8c5d49@gitrepo.freebsd.org> <30459007-56a1-4edf-8b20-2921e8e2e420@FreeBSD.org>

index | next in thread | previous in thread | raw e-mail

On 4/27/26 06:52, John Baldwin wrote:
> On 4/27/26 07:38, Andrew Turner wrote:
>> The branch main has been updated by andrew:
>>
>> URL: https://cgit.FreeBSD.org/src/commit/?
>> id=e63eee84cad59f63338a539e73bed07917932088
>>
>> commit e63eee84cad59f63338a539e73bed07917932088
>> Author:     Andrew Turner <andrew@FreeBSD.org>
>> AuthorDate: 2026-04-27 10:54:18 +0000
>> Commit:     Andrew Turner <andrew@FreeBSD.org>
>> CommitDate: 2026-04-27 11:37:53 +0000
>>
>>      libgcc_s: Add a linker script to link to libgcc
>>           When using outline atomics on arm64 the compiler will create
>> a call to
>>      a function that performs the atomic operation. This allows us to use
>>      the fastest operation depending on the hardware.
>>           As these functions are implemented in libgcc create a linker
>> script
>>      so libraries that link against libgcc_s will include libgcc to pull
>>      them in.
> 
> Some additional notes:
> 
> GCC only links with -lgcc_s (the shared library) when linking C++
> executables
> and libraries, but links with both -lgcc_s and -lgcc when linking C
> executables
> and libraries.  clang does the same on most libgcc-using platforms like
> Linux,
> except that for FreeBSD, clang treats C++ like C and links in both
> libraries
> (this is probably an accidental bug in clang's FreeBSD toolchain driver,
> but
> kind of moot).  Linux distributions use an ldscript for libgcc_s on all
> architectures (not just aarch64) to handle this weirdness of GCC.
> 
> This is all pretty sad as GCC ships with libgcc and should "know" if
> libgcc_s
> needs symbols from libgcc, but matching Linux is probably the path of least
> friction going forward.

An oddity is that the lang/gcc*'s libgcc_s.so.1 and the FreeBSD system
libgcc_s.so.1 do not match, FreeBSD having many symbols missing compared
to GCC --and the other way around as well. It can be required to use
something like -Wl,-rpath=... to force use of the appropriate
lang/gcc*'s libgcc_s.so when using the gcc* or g++* compiler in order to
avoid failures from missing symbols.

modern amd64 examples are listed in:

<https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=294110>;

modern aarch64 examples are listed in:

<https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=294109>;

There are also mismatches like (aarch64 context):
(-: FreeBSD OS, +: lang/gcc15)

+GCC_4.5.0      __unordtf2
-GCC_4.6.0      __unordtf2

and:

+GCC_3.0        __addtf3
-GCC_4.6.0      __addtf3

Even:

int main() {
}

compiled/linked via g++15 gets:

# ./trivial
ld-elf.so.1: /lib/libgcc_s.so.1: version GCC_4.5.0 required by
/usr/local/lib/gcc15/libstdc++.so.6 not found

So there is more to the mismatches in this general area than just -lgcc
being used vs. not.

(I've never checked for -lgcc mismatches.)

> It would only be worth fixing the toolchain driver
> in clang if it meant removing the custom libgcc code, but I suspect we will
> always need it for existing FreeBSD versions, so it's not clear to me
> that it is
> worth doing.
> 


-- 
===
Mark Millard
marklmi at yahoo.com


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?cd2ba351-68d6-4186-95ce-714959721ade>