[PATCH 2.43] csu: Include dl-symbol-redir-ifunc.h in libc-start.c (BZ 34744)

Pandey, Sunil K sunil.k.pandey@intel.com
Mon Oct 19 23:49:28 GMT 2026


Yes. First on master, then backport to relevant branches.

-----Original Message-----
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> 
Sent: Monday, October 19, 2026 3:52 PM
To: Pandey, Sunil K <sunil.k.pandey@intel.com>; Fernando Sanchez <fernando.sanchez@chainguard.dev>
Cc: libc-alpha@sourceware.org; libc-stable@sourceware.org; Fabian Rast <fabian.rast@tum.de>
Subject: Re: [PATCH 2.43] csu: Include dl-symbol-redir-ifunc.h in libc-start.c (BZ 34744)

IMHO this is an additional fix/optimization and for backport I think it would be better to use an already deployed strategy. We can add the uninitialized attribute on master and then also backport it.

On 19/10/26 18:04, Pandey, Sunil K wrote:
> Yes, we have to guard this under __GNUC_PREREQ (12, 0).
> -ftrivial-auto-var-init option is supported in GCC 12 and newer versions, so it should be fine.
> 
> 
> -----Original Message-----
> From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
> Sent: Monday, October 19, 2026 1:34 PM
> To: Pandey, Sunil K <sunil.k.pandey@intel.com>; Fernando Sanchez 
> <fernando.sanchez@chainguard.dev>
> Cc: libc-alpha@sourceware.org; libc-stable@sourceware.org; Fabian Rast 
> <fabian.rast@tum.de>
> Subject: Re: [PATCH 2.43] csu: Include dl-symbol-redir-ifunc.h in 
> libc-start.c (BZ 34744)
> 
> But it fixes only one variable, not the full code patch. Any other local in init_cpu_features, update_active, get_common_cache_info or the tunable callbacks can cross that threshold now or after a later change, and the bug comes back.
> 
> Also, the cpuid cache (df83fa8813e) was backported to release/2.39 through 2.43.
> The attribute exists only since GCC 12, and glibc 2.41 or older accept GCC 6.2.
> It would need a __GNUC_PREREQ (12, 0) / __glibc_has_attribute guard on older branches.
> 
> 
> On 19/10/26 16:29, Pandey, Sunil K wrote:
>> Array is getting initialized anyway, no need for memset call in this case.
>>
>> -----Original Message-----
>> From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
>> Sent: Monday, October 19, 2026 10:22 AM
>> To: Fernando Sanchez <fernando.sanchez@chainguard.dev>; Pandey, Sunil 
>> K <sunil.k.pandey@intel.com>
>> Cc: libc-alpha@sourceware.org; libc-stable@sourceware.org; Fabian 
>> Rast <fabian.rast@tum.de>
>> Subject: Re: [PATCH 2.43] csu: Include dl-symbol-redir-ifunc.h in 
>> libc-start.c (BZ 34744)
>>
>> Well, the idea of the dl-symbol-redir-ifunc.h is exactly to avoid trying to figure out where the compiler would add such calls. Also this call is done once, so I don't consider this a performance-critical.
>>
>> On 19/10/26 14:10, Fernando Sanchez wrote:
>>> I tried the suggested patch and that passed our tests successfully.
>>>
>>> Thank you for the suggestion.
>>>
>>>> On Oct 18, 2026, at 1:10 PM, Pandey, Sunil K <sunil.k.pandey@intel.com> wrote:
>>>>
>>>> How about this patch.
>>>>
>>>> $ git diff
>>>> diff --git a/sysdeps/x86/dl-cacheinfo.h 
>>>> b/sysdeps/x86/dl-cacheinfo.h index 674545c796..c3d081e307 100644
>>>> --- a/sysdeps/x86/dl-cacheinfo.h
>>>> +++ b/sysdeps/x86/dl-cacheinfo.h
>>>> @@ -1041,7 +1041,7 @@ dl_init_cacheinfo (struct cpu_features
>>>> *cpu_features)
>>>>
>>>>   if (cpu_features->basic.kind == arch_kind_intel)
>>>>     {
>>>> -      struct intel_cpuid_cache cache;
>>>> +      struct intel_cpuid_cache cache __attribute__ 
>>>> + ((uninitialized));
>>>>       cache.leaf2_valid = cache.leaf4_valid = 0;
>>>>
>>>>       data = handle_intel (_SC_LEVEL1_DCACHE_SIZE, cpu_features, 
>>>> &cache);
>>>>
>>>> --Sunil
>>>>
>>>> -----Original Message-----
>>>> From: Fernando Sanchez <fernando.sanchez@chainguard.dev>
>>>> Sent: Tuesday, October 13, 2026 9:18 AM
>>>> To: libc-alpha@sourceware.org
>>>> Cc: libc-stable@sourceware.org; Adhemerval Zanella 
>>>> <adhemerval.zanella@linaro.org>; Pandey, Sunil K 
>>>> <sunil.k.pandey@intel.com>; Fabian Rast <fabian.rast@tum.de>
>>>> Subject: [PATCH 2.43] csu: Include dl-symbol-redir-ifunc.h in 
>>>> libc-start.c (BZ 34744)
>>>>
>>>> From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>>>>
>>>> 1c9988e525 ("rtld: cache cpuid results on the stack for intel") adds struct intel_cpuid_cache (276 bytes) to the stack in dl_init_cacheinfo.
>>>> With -ftrivial-auto-var-init=zero (here enabled by gcc -fhardened), gcc zeroes it with a call to memset.  In static PIE, init_cpu_features runs from __libc_start_main before IRELATIVE relocations are applied, so the call goes through the unresolved memset PLT slot and faults.  Any static-pie program linked against a glibc built this way crashes at startup on Intel CPUs, including elf/ldconfig.
>>>>
>>>> On master, csu/libc-start.c includes dl-symbol-redir-ifunc.h since 6adb7400fd ("aarch64: Fix static PIE CPU feature detection (BZ 34205)"), which maps memset to the baseline implementation.  This is the csu/libc-start.c hunk of that commit; the rest of 6adb7400fd does not apply to release/2.43/master.
>>>>
>>>> Signed-off-by: Fernando Sanchez <fernando.sanchez@chainguard.dev> 
>>>> (cherry picked from commit 
>>>> 6adb7400fd9de486b5fb3db799c9fabee1ab5786)
>>>> ---
>>>> Tested on x86_64 (Intel Xeon Platinum 8581C), gcc 16.2 with -fhardened on by default, binutils 2.47, configured with --enable-bind-now --enable-cet --enable-stack-protector=strong:
>>>>
>>>>  - without the patch: elf/ldconfig crashes at startup, and in our CI
>>>>    builds of the branch gmon/tst-gmon-static-pie segfaults
>>>>  - with the patch: ldconfig exits 0, the memset call in
>>>>    init_cpu_features binds to __memset_sse2_unaligned, and
>>>>    gmon/tst-gmon-static-pie passes; the 53 remaining FAILs also fail in
>>>>    our 2.44 x86_64 build in the same environment
>>>>
>>>> df83fa8813 was also backported to release/2.40, 2.41 and 2.42 (cb21f7144e, 30164ba504, 5492954033), and none of them include dl-symbol-redir-ifunc.h in csu/libc-start.c.  This patch applies to all three.  I have built and tested it only on 2.43.
>>>>
>>>> csu/libc-start.c | 1 +
>>>> 1 file changed, 1 insertion(+)
>>>>
>>>> diff --git a/csu/libc-start.c b/csu/libc-start.c index
>>>> 1c58561bce..6e7f6b7054 100644
>>>> --- a/csu/libc-start.c
>>>> +++ b/csu/libc-start.c
>>>> @@ -59,6 +59,7 @@ uintptr_t __pointer_chk_guard_local 
>>>> attribute_relro attribute_hidden;  #ifndef SHARED  # include 
>>>> <link.h>  # include <dl-irel.h>
>>>> +# include <dl-symbol-redir-ifunc.h>
>>>>
>>>> # ifdef ELF_MACHINE_IRELA
>>>> #  define IREL_T	ElfW(Rela)
>>>> --
>>>> 2.54.0 (Apple Git-157)
>>>>
>>>
>>
> 



More information about the Libc-stable mailing list