about summary refs log tree commit diff
path: root/elf
Commit message (Collapse)AuthorAgeFilesLines
...
* powerpc64le: Add glibc-hwcaps supportFlorian Weimer2020-12-042-1/+7
| | | | | The "power10" and "power9" subdirectories are selected in a way that matches the -mcpu=power10 and -mcpu=power9 options of GCC.
* elf: Add missing <stddef.h> header to elf/dl-hwcaps.hMatheus Castanho2020-12-041-0/+1
| | | | | The lack of this header makes size_t unavailable on builds configured with --disable-tunables, causing compilation errors.
* x86_64: Add glibc-hwcaps supportFlorian Weimer2020-12-042-1/+11
| | | | | | | | The subdirectories match those in the x86-64 psABI: https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/77566eb03bc6a326811cb7e9a6b9396884b67c7c Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Add glibc-hwcaps subdirectory support to ld.so cache processingFlorian Weimer2020-12-0410-3/+508
| | | | | | | | | | | | | | This recognizes the DL_CACHE_HWCAP_EXTENSION flag in cache entries, and picks the supported cache entry with the highest priority. The elf/tst-glibc-hwcaps-prepend-cache test documents a non-desired aspect of the current cache implementation: If the cache selects a DSO that does not exist on disk, _dl_map_object falls back to open_path, which may or may not find an alternative implementation. This is an existing limitation that also applies to the legacy hwcaps processing for ld.so.cache. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Process glibc-hwcaps subdirectories in ldconfigFlorian Weimer2020-12-042-51/+361
| | | | | | | | Libraries from these subdirectories are added to the cache with a special hwcap bit DL_CACHE_HWCAP_EXTENSION, so that they are ignored by older dynamic loaders. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Implement tail merging of strings in ldconfigFlorian Weimer2020-12-042-39/+40
| | | | | | | | | | | | | This simplifies the string table construction in elf/cache.c because there is no more need to keep track of offsets explicitly; the string table implementation does this internally. This change slightly reduces the size of the cache on disk. The file format does not change as a result. The strings are null-terminated, without explicit length, so tail merging is transparent to readers. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Implement a string table for ldconfig, with tail mergingFlorian Weimer2020-12-045-1/+488
| | | | | | | | | | | | | | | | This will be used in ldconfig to reduce the ld.so.cache size slightly. Tail merging is an optimization where a pointer points into another string if the first string is a suffix of the second string. The hash function FNV-1a was chosen because it is simple and achieves good dispersion even for short strings (so that the hash table bucket count can be a power of two). It is clearly superior to the hsearch hash and the ELF hash in this regard. The hash table uses chaining for collision resolution. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Add extension mechanism to ld.so.cacheFlorian Weimer2020-12-041-0/+89
| | | | | | | | | | A previously unused new-format header field is used to record the address of an extension directory. This change adds a demo extension which records the version of ldconfig which builds a file. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Add endianness markup to ld.so.cache (bug 27008)Florian Weimer2020-12-042-1/+30
| | | | | | | | | Use a reserved byte in the new format cache header to indicate whether the file is in little endian or big endian format. Eventually, this information could be used to provide a unified cache for qemu-user and similiar scenarios. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Add glibc-hwcaps support for LD_LIBRARY_PATHFlorian Weimer2020-12-0415-28/+769
| | | | | | | | | | | | | | | | | | | | This hacks non-power-set processing into _dl_important_hwcaps. Once the legacy hwcaps handling goes away, the subdirectory handling needs to be reworked, but it is premature to do this while both approaches are still supported. ld.so supports two new arguments, --glibc-hwcaps-prepend and --glibc-hwcaps-mask. Each accepts a colon-separated list of glibc-hwcaps subdirectory names. The prepend option adds additional subdirectories that are searched first, in the specified order. The mask option restricts the automatically selected subdirectories to those listed in the option argument. For example, on systems where /usr/lib64 is on the library search path, --glibc-hwcaps-prepend=valgrind:debug causes the dynamic loader to search the directories /usr/lib64/glibc-hwcaps/valgrind and /usr/lib64/glibc-hwcaps/debug just before /usr/lib64 is searched. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Synchronize <elf.h> section header flags with binutilsFlorian Weimer2020-12-031-0/+2
| | | | | binutils 2.36 will add SHF_GNU_RETAIN support. SHF_GNU_BUILD_NOTE was also missing from the glibc header.
* elf.h: Fix spelling of EM_TILE64 commentFlorian Weimer2020-12-021-1/+1
| | | | Reported-By: Jakub Jelinek <jakub@redhat.com>
* elf: Introduce enum opt_format in the ldconfig implementationFlorian Weimer2020-11-262-17/+16
| | | | Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Fix uninitialized variable for _dl_writeShuo Wang2020-11-241-1/+1
| | | | | Variable ret in elf/dl-write.c is uninitialized, which should get return value from __writev.
* Add {,sysdep-}ld-library-path make variableSamuel Thibault2020-11-161-2/+2
| | | | | | | | On GNU/Hurd we not only need $(common-objpfx) in LD_LIBRARY_PATH when loading dynamic objects, but also $(common-objpfx)/mach and $(common-objpfx)/hurd. This adds an ld-library-path variable to be used as LD_LIBRARY_PATH basis in Makefiles, and a sysdep-ld-library-path variable for sysdeps to add some more paths, here mach/ and hurd/.
* nptl: Move stack list variables into _rtld_globalFlorian Weimer2020-11-164-6/+23
| | | | | | | | | Now __thread_gscope_wait (the function behind THREAD_GSCOPE_WAIT, formerly __wait_lookup_done) can be implemented directly in ld.so, eliminating the unprotected GL (dl_wait_lookup_done) function pointer. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* hurd: keep only required PLTs in ld.soSamuel Thibault2020-11-111-0/+4
| | | | | | | | | | | | | | | | | | | | | We need NO_RTLD_HIDDEN because of the need for PLT calls in ld.so. See Roland's comment in https://sourceware.org/bugzilla/show_bug.cgi?id=15605 "in the Hurd it's crucial that calls like __mmap be the libc ones instead of the rtld-local ones after the bootstrap phase, when the dynamic linker is being used for dlopen and the like." We used to just avoid all hidden use in the rtld ; this commit switches to keeping only those that should use PLT calls, i.e. essentially those defined in sysdeps/mach/hurd/dl-sysdep.c: __assert_fail __assert_perror_fail __*stat64 _exit This fixes a few startup issues, notably the call to __tunable_get_val that is made before PLTs are set up.
* elf: In ldconfig, extract the new_sub_entry function from search_dirFlorian Weimer2020-10-301-13/+21
| | | | Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Unify old and new format cache handling code in ld.soFlorian Weimer2020-10-301-142/+145
| | | | | | | struct file_entry_new starts with the fields of struct file_entry, so the code can be shared if the size computation is made dynamic. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Make elf.h header self contained.Érico Rolim2020-10-281-6/+0
| | | | | | | | | | | | The elf/elf.h header is shared, verbatim, by the elfutils project. However, elfutils can be used on systems with libcs other than glibc, making the presence of __BEGIN_DECLS, __END_DECLS and <features.h> in the file something that downstream distros may have to add patches for. Furthermore, this file doesn't declare anything with language linkage, so `extern "C" {}` blocks aren't necessary; it also doesn't have any conditional definitions based on feature test macros, making inclusion of features.h unnecessary.
* Reword description of SXID_* tunable propertiesSiddhesh Poyarekar2020-10-221-5/+6
| | | | | | | | | | | | | The SXID_* tunable properties only influence processes that are AT_SECURE, so make that a bit more explicit in the documentation and comment. Revisiting the code after a few years I managed to confuse myself, so I imagine there could be others who may have incorrectly assumed like I did that the SXID_ERASE tunables are not inherited by children of non-AT_SECURE processes. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* rtld: fix typo in commentRolf Eike Beer2020-10-131-1/+1
|
* elf: Add missing <dl-procinfo.h> header to elf/dl-usage.cMatheus Castanho2020-10-121-0/+1
|
* elf: Do not pass GLRO(dl_platform), GLRO(dl_platformlen) to _dl_important_hwcapsFlorian Weimer2020-10-092-8/+6
| | | | | | | In the current code, the function can easily obtain the information on its own. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Enhance ld.so --help to print HWCAP subdirectoriesFlorian Weimer2020-10-091-0/+62
| | | | Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Add library search path information to ld.so --helpFlorian Weimer2020-10-091-0/+56
| | | | Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Make __rtld_env_path_list and __rtld_search_dirs global variablesFlorian Weimer2020-10-081-26/+27
| | | | | | | | | They have been renamed from env_path_list and rtld_search_dirs to avoid linknamespace issues. This change will allow future use these variables in diagnostics. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Print the full name of the dynamic loader in the ld.so help messageFlorian Weimer2020-10-082-1/+4
| | | | | | | | This requires defining a macro for the full path, matching the -Wl,--dynamic-link= arguments used for linking glibc programs, and ldd script. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Use the term "program interpreter" in the ld.so help messageFlorian Weimer2020-10-081-11/+11
| | | | | | This is the term that the ELF standard itself uses. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Implement ld.so --versionFlorian Weimer2020-10-083-0/+20
| | | | | | | | This prints out version information for the dynamic loader and exits immediately, without further command line processing (which seems to match what some GNU tools do). Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Implement ld.so --helpFlorian Weimer2020-10-083-13/+75
| | | | | | | | | | | | | | | --help processing is deferred to the point where the executable has been loaded, so that it is possible to eventually include information from the main executable in the help output. As suggested in the GNU command-line interface guidelines, the help message is printed to standard output, and the exit status is successful. Handle usage errors closer to the GNU command-line interface guidelines. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Record whether paths come from LD_LIBRARY_PATH or --library-pathFlorian Weimer2020-10-084-4/+10
| | | | | | This allows more precise LD_DEBUG diagnostics. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Move ld.so error/help output to _dl_usageFlorian Weimer2020-10-084-26/+65
| | | | | | | Also add a comment to elf/Makefile, explaining why we cannot use config.status for autoconf template processing. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Extract command-line/environment variables state from rtld.cFlorian Weimer2020-10-082-96/+157
| | | | | | | | | Introduce struct dl_main_state and move it to <dl-main.h>. Rename enum mode to enum rtld_mode and add the rtld_mode_ prefix to the enum constants. This avoids the need for putting state that is only needed during startup into the ld.so data segment.
* elf: Implement __rtld_malloc_is_completeFlorian Weimer2020-10-081-0/+8
| | | | | | | | In some cases, it is difficult to determine the kind of malloc based on the execution context, so a function to determine that is helpful. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Revert "Fix missing redirects in testsuite targets"Andreas Schwab2020-10-081-1/+1
| | | | | This reverts commit d5afb38503. The log files are actually created by the various shell scripts that drive the tests.
* elf: Implement _dl_writeFlorian Weimer2020-10-072-1/+57
| | | | | | | | The generic version is parallel to _dl_writev. It cannot use _dl_writev directly because the errno value needs to be obtained under a lock. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Do not search HWCAP subdirectories in statically linked binariesFlorian Weimer2020-10-072-2/+16
| | | | | | | | | This functionality does not seem to be useful since static dlopen is mostly used for iconv/character set conversion and NSS support. gconv modules are loaded with full paths anyway, so that the HWCAP subdirectory logic does not apply. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Set tunable value as well as min/max valuesH.J. Lu2020-09-292-6/+60
| | | | | | | | Some tunable values and their minimum/maximum values must be determinted at run-time. Add TUNABLE_SET_WITH_BOUNDS and TUNABLE_SET_WITH_BOUNDS_FULL to update tunable value together with minimum and maximum values. __tunable_set_val is updated to set tunable value as well as min/max values.
* ld.so: add an --argv0 option [BZ #16124]Vincent Mihalkovic2020-09-294-3/+94
|
* Remove internal usage of extensible stat functionsAdhemerval Zanella2020-09-114-6/+6
| | | | | | | | | | | | It replaces the internal usage of __{f,l}xstat{at}{64} with the __{f,l}stat{at}{64}. It should not change the generate code since sys/stat.h explicit defines redirections to internal calls back to xstat* symbols. Checked with a build for all affected ABIs. I also check on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* elf.h: Add aarch64 bti/pac dynamic tag constantsMark Wielaard2020-09-071-0/+2
| | | | | | | | Constants double checked against binutils and the ELF for the Arm 64-bit Architecture (AArch64) Release 2020Q2 document. Only BTI PLT is used in glibc, there's no PAC PLT with glibc, and people are expected to use BIND_NOW.
* elf/tst-libc_dlvsym: Add a TEST_COMPAT around some symbol testsAlistair Francis2020-08-271-0/+5
| | | | | | | | | The _sys_errlist and _sys_siglist symbols are deprecated since 2.32. This patch adds a TEST_COMPAT check around the tests. This fixes test failures on new architectures (such as RV32) that don't have this symbol defined. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Change TLS static surplus default back to 1664Florian Weimer2020-07-203-8/+75
| | | | | | | Make the computation in elf/dl-tls.c more transparent, and add an explicit test for the historic value. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Linux: Remove rseq supportFlorian Weimer2020-07-162-12/+1
| | | | | | | | | | | | | | | | | | The kernel ABI is not finalized, and there are now various proposals to change the size of struct rseq, which would make the glibc ABI dependent on the version of the kernels used for building glibc. This is of course not acceptable. This reverts commit 48699da1c468543ade14777819bd1b4d652709de ("elf: Support at least 32-byte alignment in static dlopen"), commit 8f4632deb3545b2949cec5454afc3cb21a0024ea ("Linux: rseq registration tests"), commit 6e29cb3f61ff5432c78a1c84b0d9b123a350ab36 ("Linux: Use rseq in sched_getcpu if available"), and commit 0c76fc3c2b346dc5401dc055d97d4279632b0fb3 ("Linux: Perform rseq registration at C startup and thread creation"), resolving the conflicts introduced by the ARC port and the TLS static surplus changes. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* rtld: Avoid using up static TLS surplus for optimizations [BZ #25051]Szabolcs Nagy2020-07-0815-17/+359
| | | | | | | | | | | | | | | | | | | | | | | | | | | | On some targets static TLS surplus area can be used opportunistically for dynamically loaded modules such that the TLS access then becomes faster (TLSDESC and powerpc TLS optimization). However we don't want all surplus TLS to be used for this optimization because dynamically loaded modules with initial-exec model TLS can only use surplus TLS. The new contract for surplus static TLS use is: - libc.so can have up to 192 bytes of IE TLS, - other system libraries together can have up to 144 bytes of IE TLS. - Some "optional" static TLS is available for opportunistic use. The optional TLS is now tunable: rtld.optional_static_tls, so users can directly affect the allocated static TLS size. (Note that module unloading with dlclose does not reclaim static TLS. After the optional TLS runs out, TLS access is no longer optimized to use static TLS.) The default setting of rtld.optional_static_tls is 512 so the surplus TLS is 3*192 + 4*144 + 512 = 1664 by default, the same as before. Fixes BZ #25051. Tested on aarch64-linux-gnu and x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* rtld: Account static TLS surplus for audit modulesSzabolcs Nagy2020-07-082-6/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | The new static TLS surplus size computation is surplus_tls = 192 * (nns-1) + 144 * nns + 512 where nns is controlled via the rtld.nns tunable. This commit accounts audit modules too so nns = rtld.nns + audit modules. rtld.nns should only include the namespaces required by the application, namespaces for audit modules are accounted on top of that so audit modules don't use up the static TLS that is reserved for the application. This allows loading many audit modules without tuning rtld.nns or using up static TLS, and it fixes FAIL: elf/tst-auditmany Note that DL_NNS is currently a hard upper limit for nns, and if rtld.nns + audit modules go over the limit that's a fatal error. By default rtld.nns is 4 which allows 12 audit modules. Counting the audit modules is based on existing audit string parsing code, we cannot use GLRO(dl_naudit) before the modules are actually loaded.
* rtld: Add rtld.nns tunable for the number of supported namespacesSzabolcs Nagy2020-07-083-5/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TLS_STATIC_SURPLUS is 1664 bytes currently which is not enough to support DL_NNS (== 16) number of dynamic link namespaces, if we assume 192 bytes of TLS are reserved for libc use and 144 bytes are reserved for other system libraries that use IE TLS. A new tunable is introduced to control the number of supported namespaces and to adjust the surplus static TLS size as follows: surplus_tls = 192 * (rtld.nns-1) + 144 * rtld.nns + 512 The default is rtld.nns == 4 and then the surplus TLS size is the same as before, so the behaviour is unchanged by default. If an application creates more namespaces than the rtld.nns setting allows, then it is not guaranteed to work, but the limit is not checked. So existing usage will continue to work, but in the future if an application creates more than 4 dynamic link namespaces then the tunable will need to be set. In this patch DL_NNS is a fixed value and provides a maximum to the rtld.nns setting. Static linking used fixed 2048 bytes surplus TLS, this is changed so the same contract is used as for dynamic linking. With static linking DL_NNS == 1 so rtld.nns tunable is forced to 1, so by default the surplus TLS is reduced to 144 + 512 = 656 bytes. This change is not expected to cause problems. Tested on aarch64-linux-gnu and x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* rtld: Clean up PT_NOTE and add PT_GNU_PROPERTY handlingSzabolcs Nagy2020-07-082-12/+96
| | | | | | | | | | | | | | | | | | | | | | Add generic code to handle PT_GNU_PROPERTY notes. Invalid content is ignored, _dl_process_pt_gnu_property is always called after PT_LOAD segments are mapped and it has no failure modes. Currently only one NT_GNU_PROPERTY_TYPE_0 note is handled, which contains target specific properties: the _dl_process_gnu_property hook is called for each property. The old _dl_process_pt_note and _rtld_process_pt_note differ in how the program header is read. The old _dl_process_pt_note is called before PT_LOAD segments are mapped and _rtld_process_pt_note is called after PT_LOAD segments are mapped. The old _rtld_process_pt_note is removed and _dl_process_pt_note is always called after PT_LOAD segments are mapped and now it has no failure modes. The program headers are scanned backwards so that PT_NOTE can be skipped if PT_GNU_PROPERTY exists. Co-Authored-By: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Do not signal LA_ACT_CONSISTENT for an empty namespace [BZ #26076]Florian Weimer2020-07-071-2/+8
| | | | | | | | | The auditing interface identifies namespaces by their first loaded module. Once the namespace is empty, it is no longer possible to signal LA_ACT_CONSISTENT for it because the first loaded module is already gone at that point. Reviewed-by: Carlos O'Donell <carlos@redhat.com>