elf: Do not duplicate the GLIBC_TUNABLES string
commit2a969b53c0b02fed7e43473a92f219d737fd217a
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 6 Dec 2023 13:24:01 +0000 (6 10:24 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 19 Dec 2023 16:25:45 +0000 (19 13:25 -0300)
treeb55eda5dc496c260e9757a5fc3856838d85b38fd
parent5275fc784c8113c84c85ca028ce621f68fe6642b
elf: Do not duplicate the GLIBC_TUNABLES string

The tunable parsing duplicates the tunable environment variable so it
null-terminates each one since it simplifies the later parsing. It has
the drawback of adding another point of failure (__minimal_malloc
failing), and the memory copy requires tuning the compiler to avoid mem
operations calls.

The parsing now tracks the tunable start and its size. The
dl-tunable-parse.h adds helper functions to help parsing, like a strcmp
that also checks for size and an iterator for suboptions that are
comma-separated (used on hwcap parsing by x86, powerpc, and s390x).

Since the environment variable is allocated on the stack by the kernel,
it is safe to keep the references to the suboptions for later parsing
of string tunables (as done by set_hwcaps by multiple architectures).

Checked on x86_64-linux-gnu, powerpc64le-linux-gnu, and
aarch64-linux-gnu.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
elf/dl-tunables.c
elf/dl-tunables.h
elf/tst-tunables.c
sysdeps/generic/dl-tunables-parse.h [new file with mode: 0644]
sysdeps/s390/cpu-features.c
sysdeps/unix/sysv/linux/aarch64/cpu-features.c
sysdeps/unix/sysv/linux/powerpc/cpu-features.c
sysdeps/unix/sysv/linux/powerpc/tst-hwcap-tunables.c
sysdeps/x86/Makefile
sysdeps/x86/cpu-tunables.c
sysdeps/x86/tst-hwcap-tunables.c [new file with mode: 0644]