about summary refs log tree commit diff
path: root/elf
Commit message (Collapse)AuthorAgeFilesLines
...
* elf: Add tests for the dl hash funcs (_dl_new_hash and _dl_elf_hash)Noah Goldstein2022-05-233-0/+158
| | | | | If we want to further optimize the functions tests are needed. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* elf: Refactor dl_new_hash so it can be tested / benchmarkedNoah Goldstein2022-05-232-11/+42
| | | | | | No change to the code other than moving the function to dl-new-hash.h. Changed name so its now in the reserved namespace. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* Enable DT_RELR in glibc shared libraries and PIEs automaticallyH.J. Lu2022-05-181-1/+4
| | | | | | Enable DT_RELR in glibc shared libraries and position independent executables (PIE) automatically if linker supports -z pack-relative-relocs. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* rtld: Remove DL_ARGV_NOT_RELRO and make _dl_skip_args constSzabolcs Nagy2022-05-171-8/+2
| | | | | | | | | | | _dl_skip_args is always 0, so the target specific code that modifies argv after relro protection is applied is no longer used. After the patch relro protection is applied to _dl_argv consistently on all targets. Reviewed-by: Florian Weimer <fweimer@redhat.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* rtld: Use generic argv adjustment in ld.so [BZ #23293]Szabolcs Nagy2022-05-171-13/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When an executable is invoked as ./ld.so [ld.so-args] ./exe [exe-args] then the argv is adujusted in ld.so before calling the entry point of the executable so ld.so args are not visible to it. On most targets this requires moving argv, env and auxv on the stack to ensure correct stack alignment at the entry point. This had several issues: - The code for this adjustment on the stack is written in asm as part of the target specific ld.so _start code which is hard to maintain. - The adjustment is done after _dl_start returns, where it's too late to update GLRO(dl_auxv), as it is already readonly, so it points to memory that was clobbered by the adjustment. This is bug 23293. - _environ is also wrong in ld.so after the adjustment, but it is likely not used after _dl_start returns so this is not user visible. - _dl_argv was updated, but for this it was moved out of relro, which changes security properties across targets unnecessarily. This patch introduces a generic _dl_start_args_adjust function that handles the argument adjustments after ld.so processed its own args and before relro protection is applied. The same algorithm is used on all targets, _dl_skip_args is now 0, so existing target specific adjustment code is no longer used. The bug affects aarch64, alpha, arc, arm, csky, ia64, nios2, s390-32 and sparc, other targets don't need the change in principle, only for consistency. The GNU Hurd start code relied on _dl_skip_args after dl_main returned, now it checks directly if args were adjusted and fixes the Hurd startup data accordingly. Follow up patches can remove _dl_skip_args and DL_ARGV_NOT_RELRO. Tested on aarch64-linux-gnu and cross tested on i686-gnu. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Remove dl-librecon.h header.Adhemerval Zanella2022-05-162-29/+2
| | | | | | | | | | | | | | | | | | | | | | | The Linux version used by i686 and m68k provide three overrrides for generic code: 1. DISTINGUISH_LIB_VERSIONS to print additional information when libc5 is used by a dependency. 2. EXTRA_LD_ENVVARS to that enabled LD_LIBRARY_VERSION environment variable. 3. EXTRA_UNSECURE_ENVVARS to add two environment variables related to aout support. None are really requires, it has some decades since libc5 or aout suppported was removed and Linux even remove support for aout files. The LD_LIBRARY_VERSION is also dead code, dl_correct_cache_id is not used anywhere. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Remove ldconfig kernel version checkAdhemerval Zanella2022-05-164-116/+22
| | | | Now that it was removed on libc.so.
* Remove kernel version checkAdhemerval Zanella2022-05-165-109/+15
| | | | | | | | | | | | | | | | | | | | The kernel version check is used to avoid glibc to run on older kernels where some syscall are not available and fallback code are not enabled to handle graciously fail. However, it does not prevent if the kernel does not correctly advertise its version through vDSO note, uname or procfs. Also kernel version checks are sometime not desirable by users, where they want to deploy on different system with different kernel version knowing the minimum set of syscall is always presented on such systems. The kernel version check has been removed along with the LD_ASSUME_KERNEL environment variable. The minimum kernel used to built glibc is still provided through NT_GNU_ABI_TAG ELF note and also printed when libc.so is issued. Checked on x86_64-linux-gnu.
* csu: Implement and use _dl_early_allocate during static startupFlorian Weimer2022-05-163-0/+80
| | | | | | | | | | | This implements mmap fallback for a brk failure during TLS allocation. scripts/tls-elf-edit.py is updated to support the new patching method. The script no longer requires that in the input object is of ET_DYN type. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Update RISC-V specific ELF definitionsAndreas Schwab2022-05-161-0/+15
| | | | The definitions are taken from the 1.0-rc2 version of the ELF psABI.
* elf: Remove fallback to the start of DT_STRTAB for dladdrFangrui Song2022-05-021-11/+5
| | | | | | | | | | | | | When neither DT_HASH nor DT_GNU_HASH is present, the code scans [DT_SYMTAB, DT_STRTAB). However, there is no guarantee that .dynstr immediately follows .dynsym (e.g. lld typically places .gnu.version after .dynsym). In the absence of a hash table, symbol lookup will always fail (map->l_nbuckets == 0 in dl-lookup.c) as if the object has no symbol, so it seems fair for dladdr to do the same. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* Use __ehdr_start rather than _begin in _dl_start_finalAlan Modra2022-04-282-6/+4
| | | | | | | | | | __ehdr_start is already used in rltld.c:dl_main, and can serve the same purpose as _begin. Besides tidying the code, using linker defined section relative symbols rather than "-defsym _begin=0" better reflects the intent of _dl_start_final use of _begin, which is to refer to the load address of ld.so rather than absolute address zero. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Fix DFS sorting algorithm for LD_TRACE_LOADED_OBJECTS with missing ↵Adhemerval Zanella2022-04-2713-1/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | libraries (BZ #28868) On _dl_map_object the underlying file is not opened in trace mode (in other cases where the underlying file can't be opened, _dl_map_object quits with an error). If there any missing libraries being processed, they will not be considered on final nlist size passed on _dl_sort_maps later in the function. And it is then used by _dl_sort_maps_dfs on the stack allocated working maps: 222 /* Array to hold RPO sorting results, before we copy back to maps[]. */ 223 struct link_map *rpo[nmaps]; 224 225 /* The 'head' position during each DFS iteration. Note that we start at 226 one past the last element due to first-decrement-then-store (see the 227 bottom of above dfs_traversal() routine). */ 228 struct link_map **rpo_head = &rpo[nmaps]; However while transversing the 'l_initfini' on dfs_traversal it will still consider the l_faked maps and thus update rpo more times than the allocated working 'rpo', overflowing the stack object. As suggested in bugzilla, one option would be to avoid sorting the maps for trace mode. However I think ignoring l_faked object does make sense (there is one less constraint to call the sorting function), it allows a slight less stack usage for trace, and it is slight simpler solution. The tests does trigger the stack overflow, however I tried to make it more generic to check different scenarios or missing objects. Checked on x86_64-linux-gnu. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* elf: Add more DT_RELR testsH.J. Lu2022-04-2610-3/+286
| | | | | | | | Verify that: 1. A DT_RELR shared library without DT_NEEDED works. 2. A DT_RELR shared library without DT_VERNEED works. 3. A DT_RELR shared library without libc.so on DT_NEEDED works.
* elf: Properly handle zero DT_RELA/DT_REL valuesH.J. Lu2022-04-262-7/+23
| | | | | | With DT_RELR, there may be no relocations in DT_RELA/DT_REL and their entry values are zero. Don't relocate DT_RELA/DT_REL and update the combined relocation start address if their entry values are zero.
* elf: Support DT_RELR relative relocation format [BZ #27924]Fangrui Song2022-04-265-0/+128
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PIE and shared objects usually have many relative relocations. In 2017/2018, SHT_RELR/DT_RELR was proposed on https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/GxjM0L-PBAAJ ("Proposal for a new section type SHT_RELR") and is a pre-standard. RELR usually takes 3% or smaller space than R_*_RELATIVE relocations. The virtual memory size of a mostly statically linked PIE is typically 5~10% smaller. --- Notes I will not include in the submitted commit: Available on https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/maskray/relr "pre-standard": even Solaris folks are happy with the refined generic-abi proposal. Cary Coutant will apply the change https://sourceware.org/pipermail/libc-alpha/2021-October/131781.html This patch is simpler than Chrome OS's glibc patch and makes ELF_DYNAMIC_DO_RELR available to all ports. I don't think the current glibc implementation supports ia64 in an ELFCLASS32 container. That said, the style I used is works with an ELFCLASS32 container for 64-bit machine if ElfW(Addr) is 64-bit. * Chrome OS folks have carried a local patch since 2018 (latest version: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/refs/heads/main/sys-libs/glibc/files/local/glibc-2.32). I.e. this feature has been battle tested. * Android bionic supports 2018 and switched to DT_RELR==36 in 2020. * The Linux kernel has supported CONFIG_RELR since 2019-08 (https://git.kernel.org/linus/5cf896fb6be3effd9aea455b22213e27be8bdb1d). * A musl patch (by me) exists but is not applied: https://www.openwall.com/lists/musl/2019/03/06/3 * rtld-elf from FreeBSD 14 will support DT_RELR. I believe upstream glibc should support DT_RELR to benefit all Linux distributions. I filed some feature requests to get their attention: * Gentoo: https://bugs.gentoo.org/818376 * Arch Linux: https://bugs.archlinux.org/task/72433 * Debian https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=996598 * Fedora https://bugzilla.redhat.com/show_bug.cgi?id=2014699 As of linker support (to the best of my knowledge): * LLD support DT_RELR. * https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/refs/heads/main/sys-devel/binutils/files/ has a gold patch. * GNU ld feature request https://sourceware.org/bugzilla/show_bug.cgi?id=27923 Changes from the original patch: 1. Check the linker option, -z pack-relative-relocs, which add a GLIBC_ABI_DT_RELR symbol version dependency on the shared C library if it provides a GLIBC_2.XX symbol version. 2. Change make variale to have-dt-relr. 3. Rename tst-relr-no-pie to tst-relr-pie for --disable-default-pie. 4. Use TEST_VERIFY in tst-relr.c. 5. Add the check-tst-relr-pie.out test to check for linker generated libc.so version dependency on GLIBC_ABI_DT_RELR. 6. Move ELF_DYNAMIC_DO_RELR before ELF_DYNAMIC_DO_REL.
* Add GLIBC_ABI_DT_RELR for DT_RELR supportH.J. Lu2022-04-263-4/+50
| | | | | | | | | | | | | | | | | | | | The EI_ABIVERSION field of the ELF header in executables and shared libraries can be bumped to indicate the minimum ABI requirement on the dynamic linker. However, EI_ABIVERSION in executables isn't checked by the Linux kernel ELF loader nor the existing dynamic linker. Executables will crash mysteriously if the dynamic linker doesn't support the ABI features required by the EI_ABIVERSION field. The dynamic linker should be changed to check EI_ABIVERSION in executables. Add a glibc version, GLIBC_ABI_DT_RELR, to indicate DT_RELR support so that the existing dynamic linkers will issue an error on executables with GLIBC_ABI_DT_RELR dependency. When there is a DT_VERNEED entry with libc.so on DT_NEEDED, issue an error if there is a DT_RELR entry without GLIBC_ABI_DT_RELR dependency. Support __placeholder_only_for_empty_version_map as the placeholder symbol used only for empty version map to generate GLIBC_ABI_DT_RELR without any symbols.
* elf: Define DT_RELR related macros and typesH.J. Lu2022-04-261-2/+11
|
* elf: Replace PI_STATIC_AND_HIDDEN with opposite HIDDEN_VAR_NEEDS_DYNAMIC_RELOCFangrui Song2022-04-261-1/+1
| | | | | | | | | | | | | | | | | | PI_STATIC_AND_HIDDEN indicates whether accesses to internal linkage variables and hidden visibility variables in a shared object (ld.so) need dynamic relocations (usually R_*_RELATIVE). PI (position independent) in the macro name is a misnomer: a code sequence using GOT is typically position-independent as well, but using dynamic relocations does not meet the requirement. Not defining PI_STATIC_AND_HIDDEN is legacy and we expect that all new ports will define PI_STATIC_AND_HIDDEN. Current ports defining PI_STATIC_AND_HIDDEN are more than the opposite. Change the configure default. No functional change. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* dlfcn: Do not use rtld_active () to determine ld.so state (bug 29078)Florian Weimer2022-04-264-4/+149
| | | | | | | | | | | | | | | | | | | | When audit modules are loaded, ld.so initialization is not yet complete, and rtld_active () returns false even though ld.so is mostly working. Instead, the static dlopen hook is used, but that does not work at all because this is not a static dlopen situation. Commit 466c1ea15f461edb8e3ffaf5d86d708876343bbf ("dlfcn: Rework static dlopen hooks") moved the hook pointer into _rtld_global_ro, which means that separate protection is not needed anymore and the hook pointer can be checked directly. The guard for disabling libio vtable hardening in _IO_vtable_check should stay for now. Fixes commit 8e1472d2c1e25e6eabc2059170731365f6d5b3d1 ("ld.so: Examine GLRO to detect inactive loader [BZ #20204]"). Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Move post-relocation code of _dl_start into _dl_start_finalFangrui Song2022-04-251-15/+10
| | | | | | | | | | | | | | | | On non-PI_STATIC_AND_HIDDEN architectures, getting the address of _rtld_local_ro (for GLRO (dl_final_object)) goes through a GOT entry. The GOT load may be reordered before self relocation, leading to an unrelocated/incorrect _rtld_local_ro address. 84e02af1ebc9988126eebe60bf19226cea835623 tickled GCC powerpc32 to reorder the GOT load before relative relocations, leading to ld.so crash. This is similar to the m68k jump table reordering issue fixed by a8e9b5b8079d18116ca69c9797e77804ecf2ee7e. Move code after self relocation into _dl_start_final to avoid the reordering. This fixes powerpc32 and may help other architectures when ELF_DYNAMIC_RELOCATE is simplified in the future.
* Default to --with-default-link=no (bug 25812)Florian Weimer2022-04-222-0/+170
| | | | | | | | | This is necessary to place the libio vtables into the RELRO segment. New tests elf/tst-relro-ldso and elf/tst-relro-libc are added to verify that this is what actually happens. The new tests fail on ia64 due to lack of (default) RELRO support inbutils, so they are XFAILed there.
* scripts: Add glibcelf.py moduleFlorian Weimer2022-04-222-0/+267
| | | | | | | | | | | | | | | | Hopefully, this will lead to tests that are easier to maintain. The current approach of parsing readelf -W output using regular expressions is not necessarily easier than parsing the ELF data directly. This module is still somewhat incomplete (e.g., coverage of relocation types and versioning information is missing), but it is sufficient to perform basic symbol analysis or program header analysis. The EM_* mapping for architecture-specific constant classes (e.g., SttX86_64) is not yet implemented. The classes are defined for the benefit of elf/tst-glibcelf.py. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* elf: Move elf_dynamic_do_Rel RTLD_BOOTSTRAP branches outsideFangrui Song2022-04-201-21/+28
| | | | | | | | | | | elf_dynamic_do_Rel checks RTLD_BOOTSTRAP in several #ifdef branches. Create an outside RTLD_BOOTSTRAP branch to simplify reasoning about the function at the cost of a few duplicate lines. Since dl_naudit is zero in RTLD_BOOTSTRAP code, the RTLD_BOOTSTRAP branch can avoid _dl_audit_symbind calls to decrease code size. Reviewed-by: Adheemrval Zanella <adhemerval.zanella@linaro.org>
* elf: Remove __libc_init_secureFangrui Song2022-04-191-10/+0
| | | | | | | | | | | | | | After 73fc4e28b9464f0e13edc719a5372839970e7ddb, __libc_enable_secure_decided is always 0 and a statically linked executable may overwrite __libc_enable_secure without considering AT_SECURE. The __libc_enable_secure has been correctly initialized in _dl_aux_init, so just remove __libc_enable_secure_decided and __libc_init_secure. This allows us to remove some startup_get*id functions from 22b79ed7f413cd980a7af0cf258da5bf82b6d5e5. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* S390: Add new s390 platform z16.Stefan Liebler2022-04-142-0/+14
| | | | | | | | | | | | | | The new IBM z16 is added to platform string array. The macro _DL_PLATFORMS_COUNT is incremented. _dl_hwcaps_subdir is extended by "z16" if HWCAP_S390_VXRS_PDE2 is set. HWCAP_S390_NNPA is not tested in _dl_hwcaps_subdirs_active as those instructions may be replaced or removed in future. tst-glibc-hwcaps.c is extended in order to test z16 via new marker5. A fatal glibc error is dumped if glibc was build with architecture level set for z16, but run on an older machine. (See dl-hwcap-check.h)
* Replace {u}int_fast{16|32} with {u}int32_tNoah Goldstein2022-04-135-10/+10
| | | | | | | | | On 32-bit machines this has no affect. On 64-bit machines {u}int_fast{16|32} are set as {u}int64_t which is often not ideal. Particularly x86_64 this change both saves code size and may save instruction cost. Full xcheck passes on x86_64.
* elf: Fix memory leak in _dl_find_object_update (bug 29062)Florian Weimer2022-04-131-2/+3
| | | | | | | | The count can be zero if an object has already been loaded as an indirect dependency (so that l_searchlist.r_list in its link map is still NULL) is promoted to global scope via RTLD_GLOBAL. Fixes commit 5d28a8962dc ("elf: Add _dl_find_object function").
* S390: Fix elf/tst-audit25[ab]Stefan Liebler2022-04-071-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | If glibc is configured with --disable-default-pie and build on s390 with -O3, the tests elf/tst-audit25a and elf/tst-audit25b are failing as there are additional la_symbind lines for free and malloc. It turns out that those belong to the executable. In fact those are the PLT-stubs. Furthermore la_symbind is also called for calloc and realloc symbols, but those belong to libc. Those functions are not called at all, but dlsym'ed in elf/dl-minimal.c: __rtld_malloc_init_real (struct link_map *main_map) { ... void *new_calloc = lookup_malloc_symbol (main_map, "calloc", &version); void *new_free = lookup_malloc_symbol (main_map, "free", &version); void *new_malloc = lookup_malloc_symbol (main_map, "malloc", &version); void *new_realloc = lookup_malloc_symbol (main_map, "realloc", &version); ... } Therefore, this commit just ignored symbols with LA_SYMB_DLSYM flag. Reviewed-by: Adheemrval Zanella <adhemerval.zanella@linaro.org>
* Allow for unpriviledged nested containersDJ Delorie2022-04-041-0/+2
| | | | | | | | | | | | | | | | | If the build itself is run in a container, we may not be able to fully set up a nested container for test-container testing. Notably is the mounting of /proc, since it's critical that it be mounted from within the same PID namespace as its users, and thus cannot be bind mounted from outside the container like other mounts. This patch defaults to using the parent's PID namespace instead of creating a new one, as this is more likely to be allowed. If the test needs an isolated PID namespace, it should add the "pidns" command to its init script. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* elf: Remove unused functions from tst-audit25(a,b)Adhemerval Zanella2022-03-312-16/+0
|
* elf: Remove unused variables in testsAdhemerval Zanella2022-03-313-6/+0
| | | | Checked on x86_64-linux-gnu and i686-linux-gnu.
* elf: Fix wrong fscanf usage on tst-plddAdhemerval Zanella2022-03-311-1/+2
| | | | | | To take in consideration the extra '\0'. Checked on x86_64-linux-gnu.
* Linux: Consolidate auxiliary vector parsing (redo)Florian Weimer2022-02-282-76/+14
| | | | | | | | | | | And optimize it slightly. This is commit 8c8510ab2790039e58995ef3a22309582413d3ff revised. In _dl_aux_init in elf/dl-support.c, use an explicit loop and -fno-tree-loop-distribute-patterns to avoid memset. Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
* build: Properly generate .d dependency files [BZ #28922]H.J. Lu2022-02-251-0/+3
| | | | | | | | | | | | | 1. Also generate .d dependency files for $(tests-container) and $(tests-printers). 2. elf: Add tst-auditmod17.os to extra-test-objs. 3. iconv: Add tst-gconv-init-failure-mod.os to extra-test-objs. 4. malloc: Rename extra-tests-objs to extra-test-objs. 5. linux: Add tst-sysconf-iov_max-uapi.o to extra-test-objs. 6. x86_64: Add tst-x86_64mod-1.o, tst-platformmod-2.o, test-libmvec.o, test-libmvec-avx.o, test-libmvec-avx2.o and test-libmvec-avx512f.o to extra-test-objs. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* elf: Check invalid hole in PT_LOAD segments [BZ #28838]H.J. Lu2022-02-211-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Changes in v2: 1. Update commit log. commit 163f625cf9becbb82dfec63a29e566324129c0cd Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Dec 21 12:35:47 2021 -0800 elf: Remove excessive p_align check on PT_LOAD segments [BZ #28688] removed the p_align check against the page size. It caused the loader error or crash on elf/tst-p_align3 when loading elf/tst-p_alignmod3.so, which has the invalid p_align in PT_LOAD segments, added by commit d8d94863ef125a392b929732b37e07dc927fbcd1 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Dec 21 13:42:28 2021 -0800 The loader failure caused by a negative length passed to __mprotect is random, depending on architecture and toolchain. Update _dl_map_segments to detect invalid holes. This fixes BZ #28838. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* Revert "Linux: Consolidate auxiliary vector parsing"Florian Weimer2022-02-111-4/+76
| | | | | | | | | | | | This reverts commit 8c8510ab2790039e58995ef3a22309582413d3ff. The revert is not perfect because the commit included a bug fix for _dl_sysdep_start with an empty argv, introduced in commit 2d47fa68628e831a692cba8fc9050cef435afc5e ("Linux: Remove DL_FIND_ARG_COMPONENTS"), and this bug fix is kept. The revert is necessary because the reverted commit introduced an early memset call on aarch64, which leads to crash due to lack of TCB initialization.
* elf: Remove LD_USE_LOAD_BIASAdhemerval Zanella2022-02-103-16/+1
| | | | | | | | It is solely for prelink with PIE executables [1]. [1] https://sourceware.org/legacy-ml/libc-hacker/2003-11/msg00127.html Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* malloc: Remove LD_TRACE_PRELINKING usage from mtraceAdhemerval Zanella2022-02-102-9/+16
| | | | | | | | | | | | | | | | | | | | | | The fix for BZ#22716 replacde LD_TRACE_LOADED_OBJECTS with LD_TRACE_PRELINKING so mtrace could record executable address position. To provide the same information, LD_TRACE_LOADED_OBJECTS is extended where a value or '2' also prints the executable address as well. It avoid adding another loader environment variable to be used solely for mtrace. The vDSO will be printed as a default library (with '=>' pointing the same name), which is ok since both mtrace and ldd already handles it. The mtrace script is changed to also parse the new format. To correctly support PIE and non-PIE executables, both the default mtrace address and the one calculated as used (it fixes mtrace for non-PIE exectuable as for BZ#22716 for PIE). Checked on x86_64-linux-gnu. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* elf: Remove prelink supportAdhemerval Zanella2022-02-1010-605/+53
| | | | | | | | | | | | | Prelinked binaries and libraries still work, the dynamic tags DT_GNU_PRELINKED, DT_GNU_LIBLIST, DT_GNU_CONFLICT just ignored (meaning the process is reallocated as default). The loader environment variable TRACE_PRELINKING is also removed, since it used solely on prelink. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* Linux: Consolidate auxiliary vector parsingFlorian Weimer2022-02-101-76/+4
| | | | | | | | | | | | | | | | | | | | And optimize it slightly. The large switch statement in _dl_sysdep_start can be replaced with a large array. This reduces source code and binary size. On i686-linux-gnu: Before: text data bss dec hex filename 7791 12 0 7803 1e7b elf/dl-sysdep.os After: text data bss dec hex filename 7135 12 0 7147 1beb elf/dl-sysdep.os Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Merge dl-sysdep.c into the Linux versionFlorian Weimer2022-02-101-350/+2
| | | | | | | The generic version is the de-facto Linux implementation. It requires an auxiliary vector, so Hurd does not use it. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* hppa: Fix bind-now audit (BZ #28857)Adhemerval Zanella2022-02-095-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | On hppa, a function pointer returned by la_symbind is actually a function descriptor has the plabel bit set (bit 30). This must be cleared to get the actual address of the descriptor. If the descriptor has been bound, the first word of the descriptor is the physical address of theA function, otherwise, the first word of the descriptor points to a trampoline in the PLT. This patch also adds a workaround on tests because on hppa (and it seems to be the only ABI I have see it), some shared library adds a dynamic PLT relocation to am empty symbol name: $ readelf -r elf/tst-audit25mod1.so [...] Relocation section '.rela.plt' at offset 0x464 contains 6 entries: Offset Info Type Sym.Value Sym. Name + Addend 00002008 00000081 R_PARISC_IPLT 508 [...] It breaks some assumptions on the test, where a symbol with an empty name ("") is passed on la_symbind. Checked on x86_64-linux-gnu and hppa-linux-gnu.
* elf: Replace tst-audit24bmod2.so with tst-audit24bmod2H.J. Lu2022-02-061-1/+1
| | | | | | | | Replace tst-audit24bmod2.so with tst-audit24bmod2 to silence: make[2]: Entering directory '/export/gnu/import/git/gitlab/x86-glibc/elf' Makefile:2201: warning: overriding recipe for target '/export/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/tst-audit24bmod2.so' ../Makerules:765: warning: ignoring old recipe for target '/export/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/tst-audit24bmod2.so'
* Fix elf/tst-audit25a with default bind now toolchainsSzabolcs Nagy2022-02-021-0/+1
| | | | | This test relies on lazy binding for the executable so request that explicitly in case the toolchain defaults to bind now.
* elf: Fix runtime linker auditing on aarch64 (BZ #26643)Ben Woodard2022-02-011-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The rtld audit support show two problems on aarch64: 1. _dl_runtime_resolve does not preserve x8, the indirect result location register, which might generate wrong result calls depending of the function signature. 2. The NEON Q registers pushed onto the stack by _dl_runtime_resolve were twice the size of D registers extracted from the stack frame by _dl_runtime_profile. While 2. might result in wrong information passed on the PLT tracing, 1. generates wrong runtime behaviour. The aarch64 rtld audit support is changed to: * Both La_aarch64_regs and La_aarch64_retval are expanded to include both x8 and the full sized NEON V registers, as defined by the ABI. * dl_runtime_profile needed to extract registers saved by _dl_runtime_resolve and put them into the new correctly sized La_aarch64_regs structure. * The LAV_CURRENT check is change to only accept new audit modules to avoid the undefined behavior of not save/restore x8. * Different than other architectures, audit modules older than LAV_CURRENT are rejected (both La_aarch64_regs and La_aarch64_retval changed their layout and there are no requirements to support multiple audit interface with the inherent aarch64 issues). * A new field is also reserved on both La_aarch64_regs and La_aarch64_retval to support variant pcs symbols. Similar to x86, a new La_aarch64_vector type to represent the NEON register is added on the La_aarch64_regs (so each type can be accessed directly). Since LAV_CURRENT was already bumped to support bind-now, there is no need to increase it again. Checked on aarch64-linux-gnu. Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
* elf: Issue la_symbind for bind-now (BZ #23734)Adhemerval Zanella2022-02-0128-37/+1322
| | | | | | | | | | | | | | | | | | | | | | | The audit symbind callback is not called for binaries built with -Wl,-z,now or when LD_BIND_NOW=1 is used, nor the PLT tracking callbacks (plt_enter and plt_exit) since this would change the expected program semantics (where no PLT is expected) and would have performance implications (such as for BZ#15533). LAV_CURRENT is also bumped to indicate the audit ABI change (where la_symbind flags are set by the loader to indicate no possible PLT trace). To handle powerpc64 ELFv1 function descriptor, _dl_audit_symbind requires to know whether bind-now is used so the symbol value is updated to function text segment instead of the OPD (for lazy binding this is done by PPC64_LOAD_FUNCPTR on _dl_runtime_resolve). Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, powerpc64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
* elf: Fix initial-exec TLS access on audit modules (BZ #28096)Adhemerval Zanella2022-02-016-4/+167
| | | | | | | | | | | | | | | | | For audit modules and dependencies with initial-exec TLS, we can not set the initial TLS image on default loader initialization because it would already be set by the audit setup. However, subsequent thread creation would need to follow the default behaviour. This patch fixes it by setting l_auditing link_map field not only for the audit modules, but also for all its dependencies. This is used on _dl_allocate_tls_init to avoid the static TLS initialization at load time. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
* elf: Add la_activity during application exitAdhemerval Zanella2022-02-015-0/+351
| | | | | | | | | | la_activity is not called during application exit, even though la_objclose is. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
* elf: Add <dl-r_debug.h>H.J. Lu2022-01-312-25/+24
| | | | | | | | Add <dl-r_debug.h> to get the adddress of the r_debug structure after relocation and its offset before relocation from the PT_DYNAMIC segment to support DT_DEBUG, DT_MIPS_RLD_MAP_REL and DT_MIPS_RLD_MAP. Co-developed-by: Xi Ruoyao <xry111@mengyan1223.wang>