Re: BUG: rseq selftests and librseq vs. glibc fail
From: Florian Weimer
Date: Mon Aug 18 2025 - 15:34:18 EST
* Thomas Gleixner:
> On Mon, Aug 18 2025 at 16:15, Florian Weimer wrote:
>> * Thomas Gleixner:
>>> 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 for the explanation!
>
> So the only way to make this actually work is to revert that commit and
> the folks who want to link that statically need to come up with:
>
> #ifdef _BUILD_STATICALLY
> extern ....
>
> #else
> ptr = dlsym(...);
> #endif
>
> or something daft like that. A proper function interface would avoid all
> that nonsense, but we can't have nice things or can we?
I don't understand why a function would be different. Well, a function
*declaration* would be implicitly extern, in a way a variable
declaration is not (without -fcommon). Maybe it's just about the
missing extern keyword?
You could add the extern keyword and check &__rseq_offset for NULL if
you want to probe for the availability of the signal? Or use:
#if __has_include(<sys/rseq.h>)
#include <sys/rseq.h>
/* Code that depends on glibc's rseq support goes here. */
#endif
Thanks,
Florian