[PATCH v7 4/5] Fix assert during static startup

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Mar 2 16:30:06 GMT 2026



On 27/02/26 15:37, Adhemerval Zanella wrote:
> The BZ#33326 testcase triggers an assertion during process startup,
> which results in a segmentation fault instead of an error message
> and process termination with a SIGABRT.  The assert issues
> __libc_message_impl, which in turn might call string functions
> depending on the ABI (strchrnul, strlen, memcpy/mempcpy), system
> calls (writev and mmap), and finally the abort call.
> 
> Since each function may be called during process startup, before
> self-relocation and/or the thread pointer being set up, the
> functions should be built without stack protection.
> 
> The dl-symbol-redir-ifunc.h is also expanded to cover
> strlen/memcpy/mempcpy/strchrnul on multiple architectures that implement
> ifunc.
> 
> On i386, syscalls should not use the vDSO ("call *%gs:SYSINFO_OFFSET")
> during program statuup because thread pointer is not yet initialized.  This
> requires __raise_direct, _dl_writev, and _dl_mmap to use I386_USE_SYSENTER.
> To avoid possible sysdep.h I386_USE_SYSENTER redefinition, all
> implementations are done on their own translation unit.
> 
> The s390x requires not calling libgcc for the generic strchrnul-c (via
> ctz/clz macros) due to a libgcc issue: the __clzdi2 builtin is not built
> against a hidden reference to __clz_tab, which creates a GOT reference
> for static-pie (and it cannot be called before self-relocation).
> 
> Creating a test case is challenging. For static-pie, the assert is only
> called for ill-formed ELF files on elf_get_dynamic_info and by some targets
> on ELF_DYNAMIC_RELOCATE (although not all targets use assert in their
> dl-machine.h).  Some targets also issue __libc_fatal on ARCH_SETUP_IREL,
> but also only for ill-formatted ELF files.
> 
> The test employs a different strategy and overrides the __tunables_init
> symbol, which is invoked immediately before self-relocation and TLS setup.
> The test is built with -Wl,-z,muldefs to avoid linker issues.
> 
> I checked on aarch64, x86_64, i686, s390x (qemu), sparc (qemu),
> mips64el (qemu), armhf, riscv, and powerpc.

It fails on Linaro CI because it defaults to armv7-a and it has ifunc support
for memcpy.  I will need to send a new version that adds a proper
dl-symbol-redir-ifunc.h.


More information about the Libc-alpha mailing list