aboutsummaryrefslogtreecommitdiff
path: root/elf
AgeCommit message (Collapse)AuthorFilesLines
2024-12-18tst-unique3.cc: Add explicit instantiation declaration for S<char>::iH.J. Lu1-0/+3
Add explicit instantiation declaration of S<char>::i to silence Clang error: tst-unique3.cc:6:18: error: instantiation of variable 'S<char>::i' required here, but no definition is available [-Werror,-Wundefined-var-template] 6 | int t = S<char>::i; | ^ ./tst-unique3.h:5:14: note: forward declaration of template entity is here 5 | static int i; | ^ tst-unique3.cc:6:18: note: add an explicit instantiation declaration to suppress this warning if 'S<char>::i' is explicitly instantiated in another translation unit 6 | int t = S<char>::i; | ^ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-12-15Return EXIT_UNSUPPORTED if __builtin_add_overflow unavailableH.J. Lu1-0/+10
Since GCC 4.9 doesn't have __builtin_add_overflow: In file included from tst-stringtable.c:180:0: stringtable.c: In function ‘stringtable_finalize’: stringtable.c:185:7: error: implicit declaration of function ‘__builtin_add_overflow’ [-Werror=implicit-function-declaration] else if (__builtin_add_overflow (previous->offset, ^ return EXIT_UNSUPPORTED for GCC 4.9 or older. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-12-14ifuncmain9.c: Return EXIT_UNSUPPORTED for GCC 5.4 or olderH.J. Lu1-2/+12
Since elf/ifuncmain9.c fails at run-time when compiled with GCC 5.4 or older (PR ipa/81128), return EXIT_UNSUPPORTED for GCC 5.4 or older. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-12-05Fix typo in elf/Makefile:postclean-generatedJoseph Myers1-1/+1
The postclean-generated setting in elf/Makefile lists $(objpfx)/dso-sort-tests-2.generated-makefile twice and $(objpfx)/dso-sort-tests-1.generated-makefile not at all, which looks like a typo; fix it to list each once. Tested for x86_64.
2024-12-05Add further test of TLSJoseph Myers11-0/+381
Add an additional test of TLS variables, with different alignment, accessed from different modules. The idea of the alignment test is similar to tst-tlsalign and the same code is shared for setting up test variables, but unlike the tst-tlsalign code, there are multiple threads and variables are accessed from multiple objects to verify that they get a consistent notion of the address of an object within a thread. Threads are repeatedly created and shut down to verify proper initialization in each new thread. The test is also repeated with TLS descriptors when supported. (However, only initial-exec TLS is covered in this test.) Tested for x86_64.
2024-11-29Add test of ELF hash collisionsJoseph Myers19-1/+1364
Add tests that the dynamic linker works correctly with symbol names involving hash collisions, for both choices of hash style (and --hash-style=both as well). I note that there weren't actually any previous tests using --hash-style (so tests would only cover the default linker configuration in that regard). Also test symbol versions involving hash collisions. Tested for x86_64.
2024-11-25Silence most -Wzero-as-null-pointer-constant diagnosticsAlejandro Colomar9-14/+14
Replace 0 by NULL and {0} by {}. Omit a few cases that aren't so trivial to fix. Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059> Link: <https://software.codidact.com/posts/292718/292759#answer-292759> Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-22elf: Handle static PIE with non-zero load address [BZ #31799]H.J. Lu4-7/+90
For a static PIE with non-zero load address, its PT_DYNAMIC segment entries contain the relocated values for the load address in static PIE. Since static PIE usually doesn't have PT_PHDR segment, use p_vaddr of the PT_LOAD segment with offset == 0 as the load address in static PIE and adjust the entries of PT_DYNAMIC segment in static PIE by properly setting the l_addr field for static PIE. This fixes BZ #31799. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
2024-11-13elf: handle addition overflow in _dl_find_object_update_1 [BZ #32245]Aurelien Jarno1-0/+8
The remaining_to_add variable can be 0 if (current_used + count) wraps, This is caught by GCC 14+ on hppa, which determines from there that target_seg could be be NULL when remaining_to_add is zero, which in turns causes a -Wstringop-overflow warning: In file included from ../include/atomic.h:49, from dl-find_object.c:20: In function '_dlfo_update_init_seg', inlined from '_dl_find_object_update_1' at dl-find_object.c:689:30, inlined from '_dl_find_object_update' at dl-find_object.c:805:13: ../sysdeps/unix/sysv/linux/hppa/atomic-machine.h:44:4: error: '__atomic_store_4' writing 4 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=] 44 | __atomic_store_n ((mem), (val), __ATOMIC_RELAXED); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dl-find_object.c:644:3: note: in expansion of macro 'atomic_store_relaxed' 644 | atomic_store_relaxed (&seg->size, new_seg_size); | ^~~~~~~~~~~~~~~~~~~~ In function '_dl_find_object_update': cc1: note: destination object is likely at address zero In practice, this is not possible as it represent counts of link maps. Link maps have sizes larger than 1 byte, so the sum of any two link map counts will always fit within a size_t without wrapping around. This patch therefore adds a check on remaining_to_add == 0 and tell GCC that this can not happen using __builtin_unreachable. Thanks to Andreas Schwab for the investigation. Closes: BZ #32245 Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> Tested-by: John David Anglin <dave.anglin@bell.net> Reviewed-by: Florian Weimer <fweimer@redhat.com>
2024-11-12linux: Add support for getrandom vDSOAdhemerval Zanella1-0/+3
Linux 6.11 has getrandom() in vDSO. It operates on a thread-local opaque state allocated with mmap using flags specified by the vDSO. Multiple states are allocated at once, as many as fit into a page, and these are held in an array of available states to be doled out to each thread upon first use, and recycled when a thread terminates. As these states run low, more are allocated. To make this procedure async-signal-safe, a simple guard is used in the LSB of the opaque state address, falling back to the syscall if there's reentrancy contention. Also, _Fork() is handled by blocking signals on opaque state allocation (so _Fork() always sees a consistent state even if it interrupts a getrandom() call) and by iterating over the thread stack cache on reclaim_stack. Each opaque state will be in the free states list (grnd_alloc.states) or allocated to a running thread. The cancellation is handled by always using GRND_NONBLOCK flags while calling the vDSO, and falling back to the cancellable syscall if the kernel returns EAGAIN (would block). Since getrandom is not defined by POSIX and cancellation is supported as an extension, the cancellation is handled as 'may occur' instead of 'shall occur' [1], meaning that if vDSO does not block (the expected behavior) getrandom will not act as a cancellation entrypoint. It avoids a pthread_testcancel call on the fast path (different than 'shall occur' functions, like sem_wait()). It is currently enabled for x86_64, which is available in Linux 6.11, and aarch64, powerpc32, powerpc64, loongarch64, and s390x, which are available in Linux 6.12. Link: https://pubs.opengroup.org/onlinepubs/9799919799/nframe.html [1] Co-developed-by: Jason A. Donenfeld <Jason@zx2c4.com> Tested-by: Jason A. Donenfeld <Jason@zx2c4.com> # x86_64 Tested-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> # x86_64, aarch64 Tested-by: Xi Ruoyao <xry111@xry111.site> # x86_64, aarch64, loongarch64 Tested-by: Stefan Liebler <stli@linux.ibm.com> # s390x
2024-11-07elf: avoid jumping over a needed declarationDJ Delorie1-3/+3
The declaration of found_other_class could be jumped over via the goto just above it, but the code jumped to uses found_other_class. Move the declaration up a bit to ensure it's properly declared and initialized.
2024-11-06elf: Switch to main malloc after final ld.so self-relocationFlorian Weimer6-16/+99
Before commit ee1ada1bdb8074de6e1bdc956ab19aef7b6a7872 ("elf: Rework exception handling in the dynamic loader [BZ #25486]"), the previous order called the main calloc to allocate a shadow GOT/PLT array for auditing support. This happened before libc.so.6 ELF constructors were run, so a user malloc could run without libc.so.6 having been initialized fully. One observable effect was that environ was NULL at this point. It does not seem to be possible at present to trigger such an allocation, but it seems more robust to delay switching to main malloc after ld.so self-relocation is complete. The elf/tst-rtld-no-malloc-audit test case fails with a 2.34-era glibc that does not have this fix. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-06elf: Introduce _dl_relocate_object_no_relroFlorian Weimer1-10/+14
And make _dl_protect_relro apply RELRO conditionally. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-06elf: Do not define consider_profiling, consider_symbind as macrosFlorian Weimer1-6/+2
This avoids surprises when refactoring the code if these identifiers are re-used later in the file. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-06elf: rtld_multiple_ref is always trueFlorian Weimer1-56/+48
For a long time, libc.so.6 has dependend on ld.so, which means that there is a reference to ld.so in all processes, and rtld_multiple_ref is always true. In fact, if rtld_multiple_ref were false, some of the ld.so setup code would not run. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-10-28Revert "elf: Run constructors on cyclic recursive dlopen (bug 31986)"Florian Weimer7-167/+7
This reverts commit 9897ced8e78db5d813166a7ccccfd5a42c69ef20. Adjust the test expectations in elf/tst-dlopen-auditdup-auditmod.c accordingly.
2024-10-28elf: Change ldconfig auxcache magic number (bug 32231)Florian Weimer1-1/+1
In commit c628c2296392ed3bf2cb8d8470668e64fe53389f (elf: Remove ldconfig kernel version check), the layout of auxcache entries changed because the osversion field was removed from struct aux_cache_file_entry. However, AUX_CACHEMAGIC was not changed, so existing files are still used, potentially leading to unintended ldconfig behavior. This commit changes AUX_CACHEMAGIC, so that the file is regenerated. Reported-by: DJ Delorie <dj@redhat.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-10-25elf: Fix map_complete Systemtap probe in dl_open_workerFlorian Weimer1-1/+1
The refactoring did not take the change of variable into account. Fixes commit 43db5e2c0672cae7edea7c9685b22317eae25471 ("elf: Signal RT_CONSISTENT after relocation processing in dlopen (bug 31986)").
2024-10-25elf: Signal RT_CONSISTENT after relocation processing in dlopen (bug 31986)Florian Weimer5-15/+219
Previously, a la_activity audit event was generated before relocation processing completed. This does did not match what happened during initial startup in elf/rtld.c (towards the end of dl_main). It also caused various problems if an auditor tried to open the same shared object again using dlmopen: If it was the directly loaded object, it had a search scope associated with it, so the early exit in dl_open_worker_begin was taken even though the object was unrelocated. This caused the r_state == RT_CONSISTENT assert to fail. Avoidance of the assert also depends on reversing the order of r_state update and auditor event (already implemented in a previous commit). At the later point, args->map can be NULL due to failure, so use the assigned namespace ID instead if that is available. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-10-25elf: Signal LA_ACT_CONSISTENT to auditors after RT_CONSISTENT switchFlorian Weimer3-13/+13
Auditors can call into the dynamic loader again if LA_ACT_CONSISTENT, and those recursive calls could observe r_state != RT_CONSISTENT. We should consider failing dlopen/dlmopen/dlclose if r_state != RT_CONSISTENT. The dynamic linker is probably not in a state in which it can handle reentrant calls. This needs further investigation. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-10-25elf: Run constructors on cyclic recursive dlopen (bug 31986)Florian Weimer6-0/+165
This is conceptually similar to the reported bug, but does not depend on auditing. The fix is simple: just complete execution of the constructors. This exposed the fact that the link map for statically linked executables does not have l_init_called set, even though constructors have run. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-09-24elf: Move __rtld_malloc_init_stubs call into _dl_start_finalFlorian Weimer1-2/+2
Calling an extern function in a different translation unit before self-relocation is brittle. The compiler may load the address at an earlier point in _dl_start, before self-relocation. In _dl_start_final, the call is behind a compiler barrier, so this cannot happen.
2024-09-24elf: Eliminate alloca in open_verifyFlorian Weimer1-7/+5
With the two-stage approach for exception handling, the name can be freed after it has been copied into the exception, but before it is raised.
2024-09-24elf: Remove version assert in check_match in elf/dl-lookup.cFlorian Weimer3-36/+5
This case is detected early in the elf/dl-version.c consistency checks. (These checks could be disabled in the future to allow the removal of symbol versioning from objects.) Commit f0b2132b35 ("ld.so: Support moving versioned symbols between sonames [BZ #24741]) removed another call to _dl_name_match_p. The _dl_check_caller function no longer exists, and the remaining calls to _dl_name_match_p happen under the loader lock. This means that atomic accesses are no longer required for the l_libname list. This supersedes commit 395be7c218 ("elf: Fix data race in _dl_name_match_p [BZ #21349]").
2024-09-24elf: In rtld_setup_main_map, assume ld.so has a DYNAMIC segmentFlorian Weimer1-24/+0
The way we build ld.so, it always has a dynamic segment, so checking for its absence is unnecessary.
2024-09-20Test that errno is set to 0 at program startupAaron Merey2-0/+59
Add new testcase elf/tst-startup-errno.c which tests that errno is set to 0 at first ELF constructor execution and at the start of the program's main function. Tested for x86_64 Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2024-09-09elf: Fix tst-dlopen-tlsreinit1.out test dependencyFlorian Weimer1-1/+1
Fixes commit 5097cd344fd243fb8deb6dec96e8073753f962f9 ("elf: Avoid re-initializing already allocated TLS in dlopen (bug 31717)"). Reported-by: Patsy Griffin <patsy@redhat.com> Reviewed-by: Patsy Griffin <patsy@redhat.com>
2024-08-23nptl: Fix Race conditions in pthread cancellation [BZ#12683]Adhemerval Zanella1-4/+1
The current racy approach is to enable asynchronous cancellation before making the syscall and restore the previous cancellation type once the syscall returns, and check if cancellation has happen during the cancellation entrypoint. As described in BZ#12683, this approach shows 2 problems: 1. Cancellation can act after the syscall has returned from the kernel, but before userspace saves the return value. It might result in a resource leak if the syscall allocated a resource or a side effect (partial read/write), and there is no way to program handle it with cancellation handlers. 2. If a signal is handled while the thread is blocked at a cancellable syscall, the entire signal handler runs with asynchronous cancellation enabled. This can lead to issues if the signal handler call functions which are async-signal-safe but not async-cancel-safe. For the cancellation to work correctly, there are 5 points at which the cancellation signal could arrive: [ ... )[ ... )[ syscall ]( ... 1 2 3 4 5 1. Before initial testcancel, e.g. [*... testcancel) 2. Between testcancel and syscall start, e.g. [testcancel...syscall start) 3. While syscall is blocked and no side effects have yet taken place, e.g. [ syscall ] 4. Same as 3 but with side-effects having occurred (e.g. a partial read or write). 5. After syscall end e.g. (syscall end...*] And libc wants to act on cancellation in cases 1, 2, and 3 but not in cases 4 or 5. For the 4 and 5 cases, the cancellation will eventually happen in the next cancellable entrypoint without any further external event. The proposed solution for each case is: 1. Do a conditional branch based on whether the thread has received a cancellation request; 2. It can be caught by the signal handler determining that the saved program counter (from the ucontext_t) is in some address range beginning just before the "testcancel" and ending with the syscall instruction. 3. SIGCANCEL can be caught by the signal handler and determine that the saved program counter (from the ucontext_t) is in the address range beginning just before "testcancel" and ending with the first uninterruptable (via a signal) syscall instruction that enters the kernel. 4. In this case, except for certain syscalls that ALWAYS fail with EINTR even for non-interrupting signals, the kernel will reset the program counter to point at the syscall instruction during signal handling, so that the syscall is restarted when the signal handler returns. So, from the signal handler's standpoint, this looks the same as case 2, and thus it's taken care of. 5. For syscalls with side-effects, the kernel cannot restart the syscall; when it's interrupted by a signal, the kernel must cause the syscall to return with whatever partial result is obtained (e.g. partial read or write). 6. The saved program counter points just after the syscall instruction, so the signal handler won't act on cancellation. This is similar to 4. since the program counter is past the syscall instruction. So The proposed fixes are: 1. Remove the enable_asynccancel/disable_asynccancel function usage in cancellable syscall definition and instead make them call a common symbol that will check if cancellation is enabled (__syscall_cancel at nptl/cancellation.c), call the arch-specific cancellable entry-point (__syscall_cancel_arch), and cancel the thread when required. 2. Provide an arch-specific generic system call wrapper function that contains global markers. These markers will be used in SIGCANCEL signal handler to check if the interruption has been called in a valid syscall and if the syscalls has side-effects. A reference implementation sysdeps/unix/sysv/linux/syscall_cancel.c is provided. However, the markers may not be set on correct expected places depending on how INTERNAL_SYSCALL_NCS is implemented by the architecture. It is expected that all architectures add an arch-specific implementation. 3. Rewrite SIGCANCEL asynchronous handler to check for both canceling type and if current IP from signal handler falls between the global markers and act accordingly. 4. Adjust libc code to replace LIBC_CANCEL_ASYNC/LIBC_CANCEL_RESET to use the appropriate cancelable syscalls. 5. Adjust 'lowlevellock-futex.h' arch-specific implementations to provide cancelable futex calls. Some architectures require specific support on syscall handling: * On i386 the syscall cancel bridge needs to use the old int80 instruction because the optimized vDSO symbol the resulting PC value for an interrupted syscall points to an address outside the expected markers in __syscall_cancel_arch. It has been discussed in LKML [1] on how kernel could help userland to accomplish it, but afaik discussion has stalled. Also, sysenter should not be used directly by libc since its calling convention is set by the kernel depending of the underlying x86 chip (check kernel commit 30bfa7b3488bfb1bb75c9f50a5fcac1832970c60). * mips o32 is the only kABI that requires 7 argument syscall, and to avoid add a requirement on all architectures to support it, mips support is added with extra internal defines. Checked on aarch64-linux-gnu, arm-linux-gnueabihf, powerpc-linux-gnu, powerpc64-linux-gnu, powerpc64le-linux-gnu, i686-linux-gnu, and x86_64-linux-gnu. [1] https://lkml.org/lkml/2016/3/8/1105 Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2024-08-19elf: Make dl-fptr and dl-symaddr hppa specificAdhemerval Zanella2-355/+0
With ia64 removal, the function descriptor supports is only used by HPPA and new architectures do not seem leaning towards this design. Reviewed-by: Florian Weimer <fweimer@redhat.com>
2024-08-16support: Use macros for *stat wrappersFlorian Weimer1-1/+1
Macros will automatically use the correct types, without having to fiddle with internal glibc macros. It's also impossible to get the types wrong due to aliasing because support_check_stat_fd and support_check_stat_path do not depend on the struct stat* types. The changes reveal some inconsistencies in tests. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-08-08elf: Remove struct dl_init_args from elf/dl-open.cFlorian Weimer1-23/+3
It is completely redundant with struct dl_open_args.
2024-08-06rtld: Add test case for '--' optionHenrik Lindström2-0/+48
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-08-06rtld: Fix handling of '--' optionHenrik Lindström1-6/+10
It always resulted in the error `unrecognized option '--'` previously. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-08-05elf: Avoid re-initializing already allocated TLS in dlopen (bug 31717)Florian Weimer10-37/+307
The old code used l_init_called as an indicator for whether TLS initialization was complete. However, it is possible that TLS for an object is initialized, written to, and then dlopen for this object is called again, and l_init_called is not true at this point. Previously, this resulted in TLS being initialized twice, discarding any interim writes (technically introducing a use-after-free bug even). This commit introduces an explicit per-object flag, l_tls_in_slotinfo. It indicates whether _dl_add_to_slotinfo has been called for this object. This flag is used to avoid double-initialization of TLS. In update_tls_slotinfo, the first_static_tls micro-optimization is removed because preserving the initalization flag for subsequent use by the second loop for static TLS is a bit complicated, and another per-object flag does not seem to be worth it. Furthermore, the l_init_called flag is dropped from the second loop (for static TLS initialization) because l_need_tls_init on its own prevents double-initialization. The remaining l_init_called usage in resize_scopes and update_scopes is just an optimization due to the use of scope_has_map, so it is not changed in this commit. The isupper check ensures that libc.so.6 is TLS is not reverted. Such a revert happens if l_need_tls_init is not cleared in _dl_allocate_tls_init for the main_thread case, now that l_init_called is not checked anymore in update_tls_slotinfo in elf/dl-open.c. Reported-by: Jonathon Anderson <janderson@rice.edu> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2024-08-05elf: Clarify and invert second argument of _dl_allocate_tls_initFlorian Weimer2-5/+10
Also remove an outdated comment: _dl_allocate_tls_init is called as part of pthread_create. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2024-07-19elf: Parse the auxv values as unsigned on tst-tunables-enable_secure-env.c ↵Adhemerval Zanella1-1/+1
(BZ 31890) AT_HWCAP on some architecture can indeed use all bits. Checked on x86_64-linux-gnu and powerpc-linux-gnu. Reviewed-By: Andreas K. Hüttel <dilfridge@gentoo.org>
2024-07-19elf/tst-rtld-does-not-exist: Pass --inhibit-cache to rtldXi Ruoyao1-1/+3
This avoids a test failure when the system has no /etc/ld.so.cache. Tested on x86_64-linux-gnu. Signed-off-by: Xi Ruoyao <xry111@xry111.site> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-07-08ldconfig: Ignore all GDB extension filesAdam Sampson1-4/+6
ldconfig already ignores files with the -gdb.py suffix, but GDB also looks for -gdb.gdb and -gdb.scm files. These aren't as widely used, but libguile at least comes with a -gdb.scm file. Rename is_gdb_python_file to is_gdb_extension_file, and make it recognise all three types of GDB extension. Signed-off-by: Adam Sampson <ats@offog.org> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-07-08ldconfig: Move endswithn into a new header fileAdam Sampson3-12/+36
is_gdb_python_file is doing a similar test, so it can use this helper function as well. Signed-off-by: Adam Sampson <ats@offog.org> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-07-04elf: Make dl-rseq-symbols Linux onlyAdhemerval Zanella2-65/+0
And avoid a Hurd build failures. Checked on x86_64-linux-gnu.
2024-07-03nptl: fix potential merge of __rseq_* relro symbolsMichael Jeanson2-0/+65
While working on a patch to add support for the extensible rseq ABI, we came across an issue where a new 'const' variable would be merged with the existing '__rseq_size' variable. We tracked this to the use of '-fmerge-all-constants' which allows the compiler to merge identical constant variables. This means that all 'const' variables in a compile unit that are of the same size and are initialized to the same value can be merged. In this specific case, on 32 bit systems 'unsigned int' and 'ptrdiff_t' are both 4 bytes and initialized to 0 which should trigger the merge. However for reasons we haven't delved into when the attribute 'section (".data.rel.ro")' is added to the mix, only variables of the same exact types are merged. As far as we know this behavior is not specified anywhere and could change with a new compiler version, hence this patch. Move the definitions of these variables into an assembler file and add hidden writable aliases for internal use. This has the added bonus of removing the asm workaround to set the values on rseq registration. Tested on Debian 12 with GCC 12.2. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Reviewed-by: Florian Weimer <fweimer@redhat.com>
2024-07-03elf/rtld: Fix auxiliary vector for enable_secureStefan Liebler3-12/+126
Starting with commit 59974938fe1f4add843f5325f78e2a7ccd8db853 elf/rtld: Count skipped environment variables for enable_secure The new testcase elf/tst-tunables-enable_secure-env segfaults on s390 (31bit). There _start parses the auxiliary vector for some additional checks. Therefore it skips over the zeros after the environment variables ... 0x7fffac20: 0x7fffbd17 0x7fffbd32 0x7fffbd69 0x00000000 ------------------------------------------------^^^last environment variable ... and then it parses the auxiliary vector and stops at AT_NULL. 0x7fffac30: 0x00000000 0x00000021 0x00000000 0x00000000 --------------------------------^^^AT_SYSINFO_EHDR--------------^^^AT_NULL ----------------^^^newp-----------------------------------------^^^oldp Afterwards it tries to access AT_PHDR which points to somewhere and segfaults. Due to not incorporating the skip_env variable in the computation of oldp when shuffling down the auxv in rtld.c, it just copies one entry with AT_NULL and value 0x00000021 and stops the loop. In reality we have skipped GLIBC_TUNABLES environment variable (=> skip_env=1). Thus we should copy from here: 0x7fffac40: 0x00000021 0x7ffff000 0x00000010 0x007fffff ----------------^^^fixed-oldp This patch fixes the computation of oldp when shuffling down auxiliary vector. It also adds some checks in the testcase. Those checks also fail on s390x (64bit) and x86_64 without the fix. Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-07-01elf: Support recursive use of dynamic TLS in interposed mallocFlorian Weimer6-9/+266
It turns out that quite a few applications use bundled mallocs that have been built to use global-dynamic TLS (instead of the recommended initial-exec TLS). The previous workaround from commit afe42e935b3ee97bac9a7064157587777259c60e ("elf: Avoid some free (NULL) calls in _dl_update_slotinfo") does not fix all encountered cases unfortunatelly. This change avoids the TLS generation update for recursive use of TLS from a malloc that was called during a TLS update. This is possible because an interposed malloc has a fixed module ID and TLS slot. (It cannot be unloaded.) If an initially-loaded module ID is encountered in __tls_get_addr and the dynamic linker is already in the middle of a TLS update, use the outdated DTV, thus avoiding another call into malloc. It's still necessary to update the DTV to the most recent generation, to get out of the slow path, which is why the check for recursion is needed. The bookkeeping is done using a global counter instead of per-thread flag because TLS access in the dynamic linker is tricky. All this will go away once the dynamic linker stops using malloc for TLS, likely as part of a change that pre-allocates all TLS during pthread_create/dlopen. Fixes commit d2123d68275acc0f061e73d5f86ca504e0d5a344 ("elf: Fix slow tls access after dlopen [BZ #19924]"). Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2024-07-01Fix conditionals on mtrace-based tests (bug 31892)Carlos O'Donell1-2/+8
The conditionals for several mtrace-based tests in catgets, elf, libio, malloc, misc, nptl, posix, and stdio-common were incorrect leading to test failures when bootstrapping glibc without perl. The correct conditional for mtrace-based tests requires three checks: first checking for run-built-tests, then build-shared, and lastly that PERL is not equal to "no" (missing perl). Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-06-18elf: Remove HWCAP_IMPORTANTStefan Liebler1-1/+0
Remove the definitions of HWCAP_IMPORTANT after removal of LD_HWCAP_MASK / tunable glibc.cpu.hwcap_mask. There HWCAP_IMPORTANT was used as default value. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-06-18elf: Remove LD_HWCAP_MASK / tunable glibc.cpu.hwcap_maskStefan Liebler2-8/+0
Remove the environment variable LD_HWCAP_MASK and the tunable glibc.cpu.hwcap_mask as those are not used anymore in common-code after removal in elf/dl-cache.c:search_cache(). The only remaining user is sparc32 where it is used in elf_machine_matches_host(). If sparc32 does not need it anymore, we can get rid of it at all. Otherwise we could also move LD_HWCAP_MASK / tunable glibc.cpu.hwcap_mask to be sparc32 specific. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-06-18elf: Remove _dl_string_platformStefan Liebler1-2/+0
Despite of powerpc where the returned integer is stored in tcb, and the diagnostics output, there is no user anymore. Thus this patch removes the diagnostics output and _dl_string_platform for all other platforms. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-06-18elf: Remove loading legacy hwcaps/platform entries in dynamic loaderStefan Liebler1-19/+3
The legacy hwcaps mechanism was removed with glibc 2.37: See this commit series: - d178c67535f0d159df73843e7c18cbdb39b4d25d x86_64: Remove platform directory library loading test - 6099908fb84debee4c3bcb05d88769410c2aecd1 elf: Remove legacy hwcaps support from the dynamic loader - b78ff5a25dc8ba9d8c6df10bb0a533254bdd193f elf: Remove legacy hwcaps support from ldconfig - 4a7094119ce05cadf927f52cc5d723e2195e65f9 elf: Remove hwcap parameter from add_to_cache signature - cfbf883db36727a84ef7929af49ef68c195b5972 elf: Remove hwcap and bits_hwcap fields from struct cache_entry - 78d9a1620b840deb0880686e4159eaf70708866a Add NEWS entry for legacy hwcaps removal - ab40f20364f4a417a63dd51fdd943742070bfe96 elf: Remove _dl_string_hwcap - e76369ed6371734f77f468eab097ef4e5b5db1c5 elf: Simplify output of hwcap subdirectories in ld.so help According to Florian Weimer, this was an oversight and should also have been removed. As ldconfig does not generate ld.so.cache entries with hwcap/platform bits in the hwcap-field anymore, this patch now skips those entries. Thus currently only named-hwcap-entries and the default entries are allowed. For named-hwcap entries bit 62 is set and also the isa-level bits can be set. For the default entries the hwcap-field is 0. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-06-14elf: Change module-names to modules-names in commentsH.J. Lu1-1/+1
module-names should be modules-names. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-06-12linux: Remove __stack_protAdhemerval Zanella1-45/+1
The __stack_prot is used by Linux to make the stack executable if a modules requires it. It is also marked as RELRO, which requires to change the segment permission to RW to update it. Also, there is no need to keep track of the flags: either the stack will have the default permission of the ABI or should be change to PROT_READ | PROT_WRITE | PROT_EXEC. The only additional flag, PROT_GROWSDOWN or PROT_GROWSUP, is Linux only and can be deducted from _STACK_GROWS_DOWN/_STACK_GROWS_UP. Also, the check_consistency function was already removed some time ago. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>