about summary refs log tree commit diff
path: root/elf
Commit message (Collapse)AuthorAgeFilesLines
* elf: Introduce to _dl_call_finiFlorian Weimer2022-10-274-78/+53
| | | | | | | | | | This consolidates the destructor invocations from _dl_fini and dlclose. Remove the micro-optimization that avoids calling _dl_call_fini if they are no destructors (as dlclose is quite expensive anyway). The debug log message is now printed unconditionally. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_calledFlorian Weimer2022-10-271-5/+5
| | | | | | | This allows the rest of dynamic loader to check whether the TCB has been set up (and THREAD_GETMEM and THREAD_SETMEM will work). Reviewed-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
* elf: Reinstate on DL_DEBUG_BINDINGS _dl_lookup_symbol_xAdhemerval Zanella2022-10-261-0/+17
| | | | | | | The prelink removal done by 6628c742b2c16e wrongly removed the debug support. Checked on x86_64-linux-gnu.
* elf: Do not completely clear reused namespace in dlmopen (bug 29600)Florian Weimer2022-10-142-12/+30
| | | | | | | | | | | | | The data in the _ns_debug member must be preserved, otherwise _dl_debug_initialize enters an infinite loop. To be conservative, only clear the libc_map member for now, to fix bug 29528. Fixes commit d0e357ff45a75553dee3b17ed7d303bfa544f6fe ("elf: Call __libc_early_init for reused namespaces (bug 29528)"), by reverting most of it. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
* Add NT_S390_PV_CPU_DATA from Linux 6.0 to elf.hJoseph Myers2022-10-121-0/+1
| | | | | | | Add the new NT_S390_PV_CPU_DATA constant from Linux 6.0 to glibc's elf.h. Tested for x86_64.
* elf: Remove -fno-tree-loop-distribute-patterns usage on dl-supportAdhemerval Zanella2022-10-102-5/+1
| | | | | | | | | | | | | | Besides the option being gcc specific, this approach is still fragile and not future proof since we do not know if this will be the only optimization option gcc will add that transforms loops to memset (or any libcall). This patch adds a new header, dl-symbol-redir-ifunc.h, that can b used to redirect the compiler generated libcalls to port the generic memset implementation if required. Checked on x86_64-linux-gnu and aarch64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* elf: Simplify output of hwcap subdirectories in ld.so helpJavier Pello2022-10-061-36/+7
| | | | | | | | | The print_hwcap_1 machinery was useful for the legacy hwcaps subdirectories, but it is not worth the trouble now that they are gone. Signed-off-by: Javier Pello <devel@otheo.eu> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Remove hwcap and bits_hwcap fields from struct cache_entryJavier Pello2022-10-061-22/+6
| | | | | | | | They were set to 0 on initialisation and never changed later after last commit. Signed-off-by: Javier Pello <devel@otheo.eu> Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Remove hwcap parameter from add_to_cache signatureJavier Pello2022-10-062-15/+4
| | | | | | | | Last commit made it so that the value passed for that parameter was always 0 at its only call site. Signed-off-by: Javier Pello <devel@otheo.eu> Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Remove legacy hwcaps support from ldconfigJavier Pello2022-10-061-145/+10
| | | | | | | Remove support for the legacy hwcaps subdirectories from ldconfig. Signed-off-by: Javier Pello <devel@otheo.eu> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Remove legacy hwcaps support from the dynamic loaderJavier Pello2022-10-063-212/+10
| | | | | | | | Remove support for the legacy hwcaps subdirectories from the dynamic loader. Signed-off-by: Javier Pello <devel@otheo.eu> Reviewed-by: Florian Weimer <fweimer@redhat.com>
* Use '%z' instead of '%Z' on printf functionsAdhemerval Zanella Netto2022-09-227-14/+14
| | | | | | | | The Z modifier is a nonstandard synonymn for z (that predates z itself) and compiler might issue an warning for in invalid conversion specifier. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Extract glibcelf constants from <elf.h>Florian Weimer2022-09-221-16/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The need to maintain elf/elf.h and scripts/glibcelf.py in parallel results in a backporting hazard: they need to be kept in sync to avoid elf/tst-glibcelf consistency check failures. glibcelf (unlike tst-glibcelf) does not use the C implementation to extract constants. This applies the additional glibcpp syntax checks to <elf.h>. This changereplaces the types derived from Python enum types with custom types _TypedConstant, _IntConstant, and _FlagConstant. These types have fewer safeguards, but this also allows incremental construction and greater flexibility for grouping constants among the types. Architectures-specific named constants are now added as members into their superclasses (but value-based lookup is still restricted to generic constants only). Consequently, check_duplicates in elf/tst-glibcelf has been adjusted to accept differently-named constants of the same value if their subtypes are distinct. The ordering check for named constants has been dropped because they are no longer strictly ordered. Further test adjustments: Some of the type names are different. The new types do not support iteration (because it is unclear whether iteration should cover the all named values (including architecture-specific constants), or only the generic named values), so elf/tst-glibcelf now uses by_name explicit (to get all constants). PF_HP_SBP and PF_PARISC_SBP are now of distinct types (PfHP and PfPARISC), so they are how both present on the Python side. EM_NUM and PT_NUM are filtered (which was an oversight in the old conversion). The new version of glibcelf should also be compatible with earlier Python versions because it no longer depends on the enum module and its advanced features. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* elf: Use C11 atomics on _dl_mcountAdhemerval Zanella2022-09-211-5/+5
| | | | | | | All atomic operation are counters, so relaxed MO should be suffice. Checked on x86_64-linux-gnu. Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
* elf: Implement force_first handling in _dl_sort_maps_dfs (bug 28937)Florian Weimer2022-09-202-9/+30
| | | | | | | | | | | | | The implementation in _dl_close_worker requires that the first element of l_initfini is always this very map (“We are always the zeroth entry, and since we don't include ourselves in the dependency analysis start at 1.”). Rather than fixing that assumption, this commit adds an implementation of the force_first argument to the new dependency sorting algorithm. This also means that the directly dlopen'ed shared object is always initialized last, which is the least surprising behavior in the presence of cycles. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Makerules: fix MAKEFLAGS assignment for upcoming make-4.4 [BZ# 29564]Sergei Trofimovich2022-09-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | make-4.4 will add long flags to MAKEFLAGS variable: * WARNING: Backward-incompatibility! Previously only simple (one-letter) options were added to the MAKEFLAGS variable that was visible while parsing makefiles. Now, all options are available in MAKEFLAGS. This causes locale builds to fail when long options are used: $ make --shuffle ... make -C localedata install-locales make: invalid shuffle mode: '1662724426r' The change fixes it by passing eash option via whitespace and dashes. That way option is appended to both single-word form and whitespace separated form. While at it fixed --silent mode detection in $(MAKEFLAGS) by filtering out --long-options. Otherwise options like --shuffle flag enable silent mode unintentionally. $(silent-make) variable consolidates the checks. Resolves: BZ# 29564 CC: Paul Smith <psmith@gnu.org> CC: Siddhesh Poyarekar <siddhesh@gotplt.org> Signed-off-by: Sergei Trofimovich <slyich@gmail.com> Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* elf: Fix hwcaps string size overestimationJavier Pello2022-09-081-3/+5
| | | | | | | | | | | | | | Commit dad90d528259b669342757c37dedefa8577e2636 added glibc-hwcaps support for LD_LIBRARY_PATH and, for this, it adjusted the total string size required in _dl_important_hwcaps. However, in doing so it inadvertently altered the calculation of the size required for the power set strings, as the computation of the power set string size depended on the first value assigned to the total variable, which is later shifted, resulting in overallocation of string space. Fix this now by using a different variable to hold the string size required for glibc-hwcaps. Signed-off-by: Javier Pello <devel@otheo.eu>
* elf: Rename _dl_sort_maps parameter from skip to force_firstFlorian Weimer2022-09-061-7/+7
| | | | | | | The new implementation will not be able to skip an arbitrary number of objects. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf.h: Remove duplicate definition of VER_FLG_WEAKFlorian Weimer2022-09-051-5/+2
| | | | | | | This did not cause a warning before because the token sequence for the two definitions was identical. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Restore how vDSO dependency is printed with LD_TRACE_LOADED_OBJECTS (BZ ↵Adhemerval Zanella2022-08-311-0/+6
| | | | | | | | | | | | | | | | | | | | | | | #29539) The d7703d3176d225d5743b21811d888619eba39e82 changed how vDSO like dependencies are printed, instead of just the name and address it follows other libraries mode and prints 'name => path'. Unfortunately, this broke some ldd consumer that uses the output to filter out the program's dependencies. For instance CMake bundleutilities module [1], where GetPrequirite uses the regex to filter out 'name => path' [2]. This patch restore the previous way to print just the name and the mapping address. Checked on x86_64-linux-gnu. [1] https://github.com/Kitware/CMake/tree/master/Tests/BundleUtilities [2] https://github.com/Kitware/CMake/blob/master/Modules/GetPrerequisites.cmake#L733 Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Call __libc_early_init for reused namespaces (bug 29528)Florian Weimer2022-08-265-5/+136
| | | | | | | | | | libc_map is never reset to NULL, neither during dlclose nor on a dlopen call which reuses the namespace structure. As a result, if a namespace is reused, its libc is not initialized properly. The most visible result is a crash in the <ctype.h> functions. To prevent similar bugs on namespace reuse from surfacing, unconditionally initialize the chosen namespace to zero using memset.
* Revert "Detect ld.so and libc.so version inconsistency during startup"Florian Weimer2022-08-258-49/+44
| | | | | | | | | | | | | | | | This reverts commit 6f85dbf102ad7982409ba0fe96886caeb6389fef. Once this change hits the release branches, it will require relinking of all statically linked applications before static dlopen works again, for the majority of updates on release branches: The NEWS file is regularly updated with bug references, so the __libc_early_init suffix changes, and static dlopen cannot find the function anymore. While this ABI check is still technically correct (we do require rebuilding & relinking after glibc updates to keep static dlopen working), it is too drastic for stable release branches. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Add NT_LOONGARCH_* from Linux 5.19 to elf.hJoseph Myers2022-08-241-0/+9
| | | | | | Add the new NT_LOONGARCH_* constants from Linux 5.19 to glibc's elf.h. Tested for x86_64.
* Detect ld.so and libc.so version inconsistency during startupFlorian Weimer2022-08-248-44/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The files NEWS, include/link.h, and sysdeps/generic/ldsodefs.h contribute to the version fingerprint used for detection. The fingerprint can be further refined using the --with-extra-version-id configure argument. _dl_call_libc_early_init is replaced with _dl_lookup_libc_early_init. The new function is used store a pointer to libc.so's __libc_early_init function in the libc_map_early_init member of the ld.so namespace structure. This function pointer can then be called directly, so the separate invocation function is no longer needed. The versioned symbol lookup needs the symbol versioning data structures, so the initialization of libc_map and libc_map_early_init is now done from _dl_check_map_versions, after this information becomes available. (_dl_map_object_from_fd does not set this up in time, so the initialization code had to be moved from there.) This means that the separate initialization code can be removed from dl_main because _dl_check_map_versions covers all maps, including the initial executable loaded by the kernel. The lookup still happens before relocation and the invocation of IFUNC resolvers, so IFUNC resolvers are protected from ABI mismatch. The __libc_early_init function pointer is not protected because so little code runs between the pointer write and the invocation (only dynamic linker code and IFUNC resolvers). Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* scripts/glibcelf.py: Add hashing supportFlorian Weimer2022-08-231-0/+19
| | | | | | | | ELF and GNU hashes can now be computed using the elf_hash and gnu_hash functions. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
* elf: Run tst-audit-tlsdesc, tst-audit-tlsdesc-dlopen everywhereFlorian Weimer2022-08-161-16/+24
| | | | | | | | | The test is valid for all TLS models, but we want to make a reasonable effort to test the GNU2 model specifically. For example, aarch64 defaults to GNU2, but does not have -mtls-dialect=gnu2, and the test was not run there. Suggested-by: Martin Coufal <mcoufal@redhat.com>
* 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>