Re: [PATCH 0/2] sparc: Fix IFUNC startup and ldd-trace regressions

Adhemerval Zanella Netto <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha
Organization Linaro
Message-ID <[email protected]>

On 15/07/26 09:00, Andreas K. Huettel wrote:
>> Patch 1 fixes BZ#34396: on a static (non-PIE) binary __libc_setup_tls
>> issuse _dl_allocate_tls_init which copies the TLS init image with the
>> IFUNC __mempcpy, which now runs before the static IFUNC (IRELATIVE)
>> relocations are applied, so the call jumps through an unrelocated PLT
>> slot and dies with SIGILL.  It redirects the mem* routines reached on
>> that path to their non-IFUNC ultra1 implementations.
> [...]
>> With an working toolchain, running the sparc testsuite with patch 1 applied
>> exposed two further regressions:
>>
>>   FAIL: elf/tst-ifunc-fault-bindnow
>>   FAIL: elf/tst-ifunc-fault-lazy
>>
>> Patch 2 fixes those by proper handling R_SPARC_JMP_IREL.  I also checked
>> other ABIs for similar issues and powerpc64 (ELFv1) uses a similar second
>> reloc (R_PPC64_JMP_IREL).  The patch fixes it as well.
> 
> Tested on sparc64 (catbus) and improves the situation a lot - down to 12 failures
> from >200. Feel free to add 
> 
> Tested-by: Andreas K. Hüttel <[email protected]>

Thanks, I think I will install them by the end of the week.

> 
> In detail, the remaining failures are:
> 
> FAIL: elf/tst-pldd (*)
> FAIL: elf/tst-thp-1
> FAIL: elf/tst-thp-1-no-s-code
> FAIL: elf/tst-thp-1-no-s-code-pde
> FAIL: elf/tst-thp-1-no-s-code-static
> FAIL: elf/tst-thp-1-pde
> FAIL: elf/tst-thp-1-static

This is because PMD for THP on sparc is 8MB instead of default 2MB, this
should fix it:

diff --git a/sysdeps/unix/sysv/linux/sparc/Makefile b/sysdeps/unix/sysv/linux/sparc/Makefile
index e0056c9413f..57e73d0a14d 100644
--- a/sysdeps/unix/sysv/linux/sparc/Makefile
+++ b/sysdeps/unix/sysv/linux/sparc/Makefile
@@ -14,3 +14,8 @@ endif
 ifeq ($(subdir),signal)
 sysdep_routines += sigreturn_stub
 endif
+
+ifeq ($(subdir),elf)
+# The sparc64 uses an 8KB base page and 8MB PMD transparent huge page
+THP-PAGE-SIZE = 0x800000
+endif

> FAIL: elf/tst-thp-align
> FAIL: math/test-float64x-float128-mul (*)
> FAIL: posix/tst-chmod
> FAIL: socket/tst-socket-timestamp (*)
> FAIL: stdlib/tst-setcontext2 (*)
>                 === Summary of results ===
>      12 FAIL
>    6727 PASS
>      70 UNSUPPORTED
>      17 XFAIL
>       2 XPASS
> 
> This machine was offline for a while; my last baseline is 2.41. 
> All tests marked (*) above already failed back then. About the remaining 
> regressions, all except one seem to be internally an identical problem:
> 
> elf/tst-thp-1.out:
> ===================================
> ../sysdeps/unix/sysv/linux/tst-thp-align-check.h:59: numeric comparison failure (widths 64 and 32)
>    left: 6291456 (0x600000); from: from % thp_size
>   right: 0 (0x0); from: 0
> error: 1 test failures
> 
> elf/tst-thp-1-no-s-code.out:
> ===================================
> ../sysdeps/unix/sysv/linux/tst-thp-align-check.h:59: numeric comparison failure (widths 64 and 32)
>    left: 4194304 (0x400000); from: from % thp_size
>   right: 0 (0x0); from: 0
> ../sysdeps/unix/sysv/linux/tst-thp-align-check.h:59: numeric comparison failure (widths 64 and 32)
>    left: 4194304 (0x400000); from: from % thp_size
>   right: 0 (0x0); from: 0
> error: 2 test failures
> 
> elf/tst-thp-1-no-s-code-pde.out:
> ===================================
> ../sysdeps/unix/sysv/linux/tst-thp-align-check.h:59: numeric comparison failure (widths 64 and 32)
>    left: 2097152 (0x200000); from: from % thp_size
>   right: 0 (0x0); from: 0
> ../sysdeps/unix/sysv/linux/tst-thp-align-check.h:59: numeric comparison failure (widths 64 and 32)
>    left: 2097152 (0x200000); from: from % thp_size
>   right: 0 (0x0); from: 0
> error: 2 test failures
> 
> elf/tst-thp-1-no-s-code-static.out:
> ===================================
> ../sysdeps/unix/sysv/linux/tst-thp-align-check.h:59: numeric comparison failure (widths 64 and 32)
>    left: 2097152 (0x200000); from: from % thp_size
>   right: 0 (0x0); from: 0
> ../sysdeps/unix/sysv/linux/tst-thp-align-check.h:59: numeric comparison failure (widths 64 and 32)
>    left: 2097152 (0x200000); from: from % thp_size
>   right: 0 (0x0); from: 0
> error: 2 test failures
> 
> elf/tst-thp-align.out:
> ===================================
> ../sysdeps/unix/sysv/linux/tst-thp-align-check.h:59: numeric comparison failure (widths 64 and 32)
>    left: 4194304 (0x400000); from: from % thp_size
>   right: 0 (0x0); from: 0
> error: 1 test failures
> 
> posix/tst-chmod.out:
> ===================================
> chmod(".../file",0600) did not set ctime correctly
> 
> 
> 
> 
> 
> 
> 
>>
>> The existing tests do not catch it there because they only take the
>> resolver's *address*, which powerpc64 emits as R_PPC64_IRELATIVE; the
>> JMP_IREL slot is emitted only when the IFUNC is actually *called*. All
>> other ABIs use a single IRELATIVE type and are unaffected.
>>
>> Adhemerval Zanella (2):
>>   sparc: Fix static IFUNC startup crash by redirecting __mempcpy (BZ
>>     #34396)
>>   elf: Defer arch PLT IFUNC relocations in the two-phase relocation
>>     split
>>
>>  elf/do-rel.h                                  |  8 ++++++-
>>  sysdeps/powerpc/powerpc64/dl-machine.h        |  1 +
>>  .../multiarch => }/dl-symbol-redir-ifunc.h    | 13 +++++++++-
>>  sysdeps/sparc/sparc32/dl-machine.h            |  1 +
>>  sysdeps/sparc/sparc64/dl-machine.h            |  1 +
>>  .../sparc64/multiarch/dl-symbol-redir-ifunc.h | 24 -------------------
>>  6 files changed, 22 insertions(+), 26 deletions(-)
>>  rename sysdeps/sparc/{sparc32/sparcv9/multiarch => }/dl-symbol-redir-ifunc.h (70%)
>>  delete mode 100644 sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h
>>
>>
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.