Re: BUG: rseq selftests and librseq vs. glibc fail
From: Florian Weimer
Date: Mon Aug 18 2025 - 10:42:21 EST
* Thomas Gleixner:
> On Sun, Aug 17 2025 at 23:23, Thomas Gleixner wrote:
>> It survives the self test suite after I wasted a day to figure out why
>> the selftests reliably segfault on a machine which has debian trixie
>> installed. The fix is in the branch.
>
> That's glibc 2.41 FWIW. glibc 2.36 from Debian 12 does not have this
> problem.
>
> The fix unfortunately only works with a dynamically linked libc,
> statically linked libc fails. The fix is basically a revert of
>
> 3bcbc20942db ("selftests/rseq: Play nice with binaries statically linked
> against glibc 2.35+")
>
> which introduced these weak libc symbols to make static libc linking work.
>
> I have no idea why this creates havoc, but in GDB I saw that libc
> manages to overwrite the TLS of the pthread at some place, but I gave up
> decoding it further. If no pthread is created it just works. Removing
> this weak muck makes it work too.
>
> It's trivial to reproduce. All it needs is to have in the source:
>
> __weak ptrdiff_t __rseq_offset;
>
> w/o even being referenced and creating a pthread. Reproducer below.
Well, that's sort of expected. You can't define glibc symbols that are
not intended for interposition and expect things to work. It's kind of
like writing:
int _rtld_global;
That's going to fail rather spectaculary, too. We make an exception for
symbols that are not reserved (you can build in ISO C mode and define
open, close, etc., at least as long as you link to glibc only). But
__rseq_offset is a reserved name, so that is not applicable here.
The real change here is GCC changing from -fcommon (which made a lot of
these things work in the past) to -fno-common.
Thanks,
Florian