about summary refs log tree commit diff
path: root/elf
Commit message (Collapse)AuthorAgeFilesLines
...
* elf.h: Add ELFCOMPRESS_ZSTDFangrui Song2022-08-101-0/+1
| | | | | | | | From the approved generic ABI proposal https://groups.google.com/g/generic-abi/c/satyPkuMisk ("Add new ch_type value: ELFCOMPRESS_ZSTD"). Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Replace `strcpy` call with `memcpy` [BZ #29454]Noah Goldstein2022-08-091-2/+3
| | | | | | | GCC normally does this optimization for us in strlen_pass::handle_builtin_strcpy but only for optimized build. To avoid needing to include strcpy.S in the rtld build to support the debug build, just do the optimization by hand.
* malloc: Correct the documentation of the top_pad defaultFlorian Weimer2022-08-042-1/+2
| | | | | DEFAULT_TOP_PAD is defined as 131072 in sysdeps/generic/malloc-machine.h.
* Assume only FLAG_ELF_LIBC6 suportLucas A. M. Magalhaes2022-08-044-126/+14
| | | | | | | | | | | The older libc versions are obsolete for over twenty years now. This patch removes the special flags for libc5 and libc4 and assumes that all libraries cached are libc6 compatible and use FLAG_ELF_LIBC6. Checked with a build for all affected architectures. Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* assert: Do not use stderr in libc-internal assertFlorian Weimer2022-08-031-0/+1
| | | | | | | | | | | | | | | | | | | | Redirect internal assertion failures to __libc_assert_fail, based on based on __libc_message, which writes directly to STDERR_FILENO and calls abort. Also disable message translation and reword the error message slightly (adjusting stdlib/tst-bz20544 accordingly). As a result of these changes, malloc no longer needs its own redefinition of __assert_fail. __libc_assert_fail needs to be stubbed out during rtld dependency analysis because the rtld rebuilds turn __libc_assert_fail into __assert_fail, which is unconditionally provided by elf/dl-minimal.c. This change is not possible for the public assert macro and its __assert_fail function because POSIX requires that the diagnostic is written to stderr. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Don't use unsupported format string in ld.so (bug 29427)Andreas Schwab2022-08-021-1/+1
| | | | | The dynamic loader does not support printf format strings that contain a literal field width or precision, they have to be specified indirectly.
* LoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.pycaiyinyu2022-07-261-1/+67
|
* elf: Fix wrong fscanf usage on tst-plddAdhemerval Zanella2022-07-151-4/+5
| | | | | | | | The fix done b2cd93fce666fdc8c9a5c64af2741a8a6940ac99 does not really work since macro strification does not expand the sizeof nor the arithmetic operation. Checked on x86_64-linux-gnu.
* elf: Rename tst-audit26 to tst-audit28Florian Weimer2022-07-083-5/+5
| | | | | | tst-audit26 and tst-audit27 are already used by aarch64. Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
* elf: Fix direction of NODELETE log messages during symbol lookupFlorian Weimer2022-07-051-2/+2
| | | | | | | | NODELETE status is propagated from the referencing object to the referenced object, not the other way round. The code is correct, only the log message has the wrong direction. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Fix -DNDEBUG warning in _dl_start_args_adjustFlorian Weimer2022-06-281-1/+1
| | | | | This is another blocker for building glibc with the default -Werror setting and -DNDEBUG.
* elf: Fix compile error with -Werror and -DNDEBUGYang Yanchao2022-06-281-1/+2
| | | | | | | | | | | | | Using -Werror and -DNDEBUG at the same time will trigger the following compiler error: cache.c: In function 'save_cache': cache.c:758:15: error: unused variable 'old_offset' [-Werror=unused-variable] 758 | off64_t old_offset = lseek64 (fd, extension_offset, SEEK_SET); | ^~~~~~~~~~ -DNDEBUG disables the assertion, making old_offset unused. Use __attribute__ ((unused)) to disable this warning.
* misc: Optimize internal usage of __libc_single_threadedAdhemerval Zanella2022-06-241-1/+1
| | | | | | | | | | | | | | | By adding an internal alias to avoid the GOT indirection. On some architecture, __libc_single_thread may be accessed through copy relocations and thus it requires to update also the copies default copy. This is done by adding a new internal macro, libc_hidden_data_{proto,def}, which has an addition argument that specifies the alias name (instead of default __GI_ one). Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Fangrui Song <maskray@google.com>
* elf: Silence GCC 11/12 false positive warningH.J. Lu2022-06-171-0/+10
| | | | | | | | | | Silence GCC 11/12 false positive warning with -mavx512f on dl-load.c: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106008 $ gcc -O2 -fPIC -march=x86-64 -mavx512f -S -Wall ... dl-load.c: In function ‘_dl_map_object_from_fd.constprop’: dl-load.c:1158:30: warning: ‘(((char *)loadcmds.113_68 + _933 + 16))[329406144173384849].mapend’ may be used uninitialized [-Wmaybe-uninitialized]
* elf: Remove ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATAFangrui Song2022-06-151-59/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | If an executable has copy relocations for extern protected data, that can only work if the library containing the definition is built with assumptions (a) the compiler emits GOT-generating relocations (b) the linker produces R_*_GLOB_DAT instead of R_*_RELATIVE. Otherwise the library uses its own definition directly and the executable accesses a stale copy. Note: the GOT relocations defeat the purpose of protected visibility as an optimization, but allow rtld to make the executable and library use the same copy when copy relocations are present, but it turns out this never worked perfectly. ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA has strange semantics when both a.so and b.so define protected var and the executable copy relocates var: b.so accesses its own copy even with GLOB_DAT. The behavior change is from commit 62da1e3b00b51383ffa7efc89d8addda0502e107 (x86) and then copied to nios2 (ae5eae7cfc9c4a8297ff82ec6b794faca1976ecc) and arc (0e7d930c4c11de896fe807f67fa1eb756c9c1e05). Without ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA, b.so accesses the copy relocated data like a.so. There is now a warning for copy relocation on protected symbol since commit 7374c02b683b7110b853a32496a619410364d70b. It's extremely unlikely anyone relies on the ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA behavior, so let's remove it: this removes a check in the symbol lookup code.
* elf: add missing newlines in lateglobal testAndreas Schwab2022-06-081-3/+3
|
* Add PT_AARCH64_MEMTAG_MTE from Linux 5.18 to elf.hJoseph Myers2022-06-061-0/+3
| | | | | | | Linux 5.18 defines a new AArch64 ELF segment type PT_AARCH64_MEMTAG_MTE; add it to elf.h. Tested with build-many-glibcs.py for aarch64-linux-gnu.
* grep: egrep -> grep -E, fgrep -> grep -FSam James2022-06-052-2/+2
| | | | | | | | | | | Newer versions of GNU grep (after grep 3.7, not inclusive) will warn on 'egrep' and 'fgrep' invocations. Convert usages within the tree to their expanded non-aliased counterparts to avoid irritating warnings during ./configure and the test suite. Signed-off-by: Sam James <sam@gentoo.org> Reviewed-by: Fangrui Song <maskray@google.com>
* elf: Add #include <errno.h> for use of E* constants.Carlos O'Donell2022-06-021-1/+1
| | | | | | In __strerror_r we use errno constants and must include errno.h. Tested on x86_64 and i686 without regression.
* elf: Add #include <sys/param.h> for MAX usage.Carlos O'Donell2022-06-021-0/+1
| | | | | | In _dl_audit_pltenter we use MAX and so need to include param.h. Tested on x86_64 and i686 without regression.
* elf: Remove _dl_skip_argsAdhemerval Zanella2022-05-301-2/+0
| | | | | | Now that no architecture uses it anymore. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* dlsym: Make RTLD_NEXT prefer default version definition [BZ #14932]Fangrui Song2022-05-275-1/+77
| | | | | | | | | | | | | When the first object providing foo defines both foo@v1 and foo@@v2, dlsym(RTLD_NEXT, "foo") returns foo@v1 while dlsym(RTLD_DEFAULT, "foo") returns foo@@v2. The issue is that RTLD_DEFAULT uses the DL_LOOKUP_RETURN_NEWEST flag while RTLD_NEXT doesn't. Fix the RTLD_NEXT branch to use DL_LOOKUP_RETURN_NEWEST. Note: the new behavior matches FreeBSD rtld. Future sanitizers will not need to add versioned interceptors like https://reviews.llvm.org/D96348 Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf/dl-reloc.c: Copyright The GNU Toolchain AuthorsFangrui Song2022-05-231-0/+1
| | | | | | | | | by following 3.5. Update copyright information on https://sourceware.org/glibc/wiki/Contribution%20checklist . The change is advised by Carlos O'Donell. Note: commit a8b11bd1f8dc68795b377138b5d94638ef75a50d missed Signed-off-by tag from Nicholas Guriev <nicholas@guriev.su>.
* elf: Rewrite long RESOLVE_MAP macro to an always_inline static functionNicholas Guriev2022-05-231-22/+34
| | | | | | | An __always_inline static function is better to find where exactly a crash happens, so one can step into the function with GDB. Reviewed-by: Fangrui Song <maskray@google.com>
* elf: Optimize _dl_new_hash in dl-new-hash.hNoah Goldstein2022-05-232-12/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unroll slightly and enforce good instruction scheduling. This improves performance on out-of-order machines. The unrolling allows for pipelined multiplies. As well, as an optional sysdep, reorder the operations and prevent reassosiation for better scheduling and higher ILP. This commit only adds the barrier for x86, although it should be either no change or a win for any architecture. Unrolling further started to induce slowdowns for sizes [0, 4] but can help the loop so if larger sizes are the target further unrolling can be beneficial. Results for _dl_new_hash Benchmarked on Tigerlake: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz Time as Geometric Mean of N=30 runs Geometric of all benchmark New / Old: 0.674 type, length, New Time, Old Time, New Time / Old Time fixed, 0, 2.865, 2.72, 1.053 fixed, 1, 3.567, 2.489, 1.433 fixed, 2, 2.577, 3.649, 0.706 fixed, 3, 3.644, 5.983, 0.609 fixed, 4, 4.211, 6.833, 0.616 fixed, 5, 4.741, 9.372, 0.506 fixed, 6, 5.415, 9.561, 0.566 fixed, 7, 6.649, 10.789, 0.616 fixed, 8, 8.081, 11.808, 0.684 fixed, 9, 8.427, 12.935, 0.651 fixed, 10, 8.673, 14.134, 0.614 fixed, 11, 10.69, 15.408, 0.694 fixed, 12, 10.789, 16.982, 0.635 fixed, 13, 12.169, 18.411, 0.661 fixed, 14, 12.659, 19.914, 0.636 fixed, 15, 13.526, 21.541, 0.628 fixed, 16, 14.211, 23.088, 0.616 fixed, 32, 29.412, 52.722, 0.558 fixed, 64, 65.41, 142.351, 0.459 fixed, 128, 138.505, 295.625, 0.469 fixed, 256, 291.707, 601.983, 0.485 random, 2, 12.698, 12.849, 0.988 random, 4, 16.065, 15.857, 1.013 random, 8, 19.564, 21.105, 0.927 random, 16, 23.919, 26.823, 0.892 random, 32, 31.987, 39.591, 0.808 random, 64, 49.282, 71.487, 0.689 random, 128, 82.23, 145.364, 0.566 random, 256, 152.209, 298.434, 0.51 Co-authored-by: Alexander Monakov <amonakov@ispras.ru> Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* 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>