about summary refs log tree commit diff
path: root/elf
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix elf/loadfail test build dependenciesSzabolcs Nagy2022-01-281-1/+3
| | | | | | | | | | There was no direct or indirect make dependency on testobj3.so so the test could fail with /B/elf/loadfail: failed to load shared object: testobj3.so: cannot open shared object file: No such file or directory Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Fix glibc 2.34 ABI omission (missing GLIBC_2.34 in dynamic loader)Florian Weimer2022-01-273-0/+39
| | | | | | | | | | | | | The glibc 2.34 release really should have added a GLIBC_2.34 symbol to the dynamic loader. With it, we could move functions such as dlopen or pthread_key_create that work on process-global state into the dynamic loader (once we have fixed a longstanding issue with static linking). Without the GLIBC_2.34 symbol, yet another new symbol version would be needed because old glibc will fail to load binaries due to the missing symbol version in ld.so that newly linked programs will require. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* Guard tst-valgrind-smoke.out with run-built-testsMark Wielaard2022-01-261-0/+2
| | | | | | Prevent tst-valgrind-smoke from running when run-built-tests is not yes. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Replace tst-p_alignmod1-editX with a python scriptAdhemerval Zanella2022-01-264-190/+4
| | | | | | | | This avoid the cross-compiling breakage when the test should not run ($(run-built-tests) equal to no). Checked on x86_64-linux-gnu and i686-linux-gnu as well with a cross compile to aarch64-linux-gnu and powerpc64-linux-gnu.
* elf: Fix use-after-free in ldconfig [BZ #26779]Martin Sebor2022-01-251-1/+1
| | | | Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* elf: Add a test for PT_LOAD segments with invalid p_align [BZ #28688]H.J. Lu2022-01-244-0/+88
| | | | | | | Build tst-p_alignmod3.so with 256 byte page size and verify that it is rejected with a proper error message. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Add a test for PT_LOAD segments with p_align == 1 [BZ #28688]H.J. Lu2022-01-243-0/+67
| | | | | | | | Add tst-p_alignmod2-edit to edit the copy of tst-p_alignmod-base.so to set p_align of the first PT_LOAD segment to 1 and verify that the shared library can be loaded normally. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Add a test for PT_LOAD segments with mixed p_align [BZ #28676]H.J. Lu2022-01-246-0/+258
| | | | | | | | Add tst-p_alignmod1-edit to edit the copy of tst-p_alignmod-base.so to reduce p_align of the first PT_LOAD segment by half and verify that the shared library is mapped with the maximum p_align of all PT_LOAD segments. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Add and use link-test-modules-rpath-link [BZ #28455]H.J. Lu2022-01-243-0/+80
| | | | | | | | | | | | | DT_RUNPATH is only used to find the immediate dependencies of the executable or shared object containing the DT_RUNPATH entry: 1. Define link-test-modules-rpath-link if $(build-hardcoded-path-in-tests) is yes. 2. Use $(link-test-modules-rpath-link) in build-module-helper so that test modules can dlopen modules with DT_RUNPATH. 3. Add a test to show why link-test-modules-rpath-link is needed. This partially fixes BZ #28455.
* Add valgrind smoke testAlexandra Hájková2022-01-223-0/+102
| | | | | | | | | | Check if whether valgrind is available in the test environment. If not, skip the test. Run smoke tests with valgrind to verify dynamic loader. First, check if algrind works with the system ld.so in the test environment. Then run the actual test inside the test environment, using the just build ld.so and new libraries. Co-authored-by: Mark Wielaard <mark@klomp.org>
* elf: Properly align all PT_LOAD segments [BZ #28676]H.J. Lu2022-01-211-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Linker may set p_align of a PT_LOAD segment larger than p_align of the first PT_LOAD segment to satisfy a section alignment: Elf file type is DYN (Shared object file) Entry point 0x0 There are 10 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000834 0x0000000000000834 R E 0x1000 LOAD 0x0000000000000e00 0x0000000000001e00 0x0000000000001e00 0x0000000000000230 0x0000000000000230 RW 0x1000 LOAD 0x0000000000400000 0x0000000000400000 0x0000000000400000 0x0000000000000004 0x0000000000000008 RW 0x400000 ... Section to Segment mapping: Segment Sections... 00 .note.gnu.property .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .plt.got .text .fini .rodata .eh_frame_hdr .eh_frame 01 .init_array .fini_array .data.rel.ro .dynamic .got .got.plt 02 .data .bss We should align the first PT_LOAD segment to the maximum p_align of all PT_LOAD segments, similar to the kernel commit: commit ce81bb256a224259ab686742a6284930cbe4f1fa Author: Chris Kennelly <ckennelly@google.com> Date: Thu Oct 15 20:12:32 2020 -0700 fs/binfmt_elf: use PT_LOAD p_align values for suitable start address This fixes BZ #28676. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Fix tst-align3Adhemerval Zanella2022-01-181-2/+3
| | | | | | The elf/tst-align3.c declares the function using a wrong prototype. Checked on aarch64-linux-gnu.
* elf: Move _dl_setup_hash to its own fileFlorian Weimer2022-01-183-45/+65
| | | | | | | | | And compile it with the early CFLAGS. _dl_setup_hash is called very early for the ld.so link map, so it should be compiled differently. Reviewed-by: Stefan Liebler <stli@linux.ibm.com> Tested-by: Stefan Liebler <stli@linux.ibm.com>
* elf: Reinstate tst-audit17Adhemerval Zanella2022-01-171-0/+1
| | | | | 9926f6e2eeb3 ("elf: Skip tst-auditlogmod-* if the linker doesn't support --depaudit [BZ #28 151]") dropped the test by mistake.
* elf: Fix 64 time_t support for installed statically binariesAdhemerval Zanella2022-01-175-36/+36
| | | | | | | | | | | | | | The usage of internal static symbol for statically linked binaries does not work correctly for objects built with -D_TIME_BITS=64, since the internal definition does not provide the expected aliases. This patch makes it to use the default stat functions instead (which uses the default 64 time_t alias and types). Checked on i686-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
* Revert "elf: Fix 64 time_t support for installed statically binaries"Adhemerval Zanella2022-01-175-36/+36
| | | | This reverts commit 0b8e83eb1455f3c0332eeb1f96fbc262fbd054e0.
* elf/tst-dl_find_object: Disable subtests for non-contiguous maps (bug 28732)Florian Weimer2022-01-171-12/+17
| | | | Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* elf: Set l_contiguous to 1 for the main map in more casesFlorian Weimer2022-01-171-0/+25
| | | | | | | | | | | | | | | | | l_contiguous was not initialized at all for the main map and always 0. This commit adds code to check if the LOAD segments are adjacent to each other, and sets l_contiguous accordingly. This helps _dl_find_object because it is more efficient if the main mapping is contiguous. Note that not all (PIE or non-PIE) binaries are contiguous in this way because BFD ld creates executables with LOAD holes: ELF LOAD segments creating holes in the process image on GNU/Linux https://sourceware.org/pipermail/binutils/2022-January/119082.html https://sourceware.org/bugzilla/show_bug.cgi?id=28743 Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* elf: Introduce rtld_setup_main_mapFlorian Weimer2022-01-171-144/+159
| | | | | | | This function collects most of the processing needed to initialize the link map for the main executable. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* elf tst-dl_find_object: Fix typoSamuel Thibault2022-01-151-1/+1
| | | | mod1 was xdlclose()d a few lines above.
* Add --with-rtld-early-cflags configure optionFlorian Weimer2022-01-141-0/+8
| | | | | Reviewed-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* elf: Split dl-printf.c from dl-misc.cFlorian Weimer2022-01-143-277/+297
| | | | | | | This allows to use different compiler flags for the diagnostics code. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* elf/Makefile: Reflow and sort most variable assignmentsFlorian Weimer2022-01-141-102/+318
| | | | Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
* elf: Fix 64 time_t support for installed statically binariesAdhemerval Zanella2022-01-125-36/+36
| | | | | | | | | | | The usage of internal static symbol for statically linked binaries does not work correctly for objects built with -D_TIME_BITS=64, since the internal definition does not provide the expected aliases. This patch makes it to use the default stat functions instead (which uses the default 64 time_t alias and types). Checked on i686-linux-gnu.
* elf: Simplify software TM implementation in _dl_find_objectFlorian Weimer2022-01-101-36/+20
| | | | | | | | | | | | | With the current set of fences, the version update at the start of the TM write operation is redundant, and the version update at the end does not need to use an atomic read-modify-write operation. Also use relaxed MO stores during the dlclose update, and skip any version changes there. Suggested-by: Szabolcs Nagy <szabolcs.nagy@arm.com> Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
* elf: Fix fences in _dl_find_object_update (bug 28745)Florian Weimer2022-01-073-77/+133
| | | | | | | | | | | | | | | | | | | | | | As explained in Hans Boehm, Can Seqlocks Get Along with Programming Language Memory Models?, an acquire fence is needed in _dlfo_read_success. The lack of a fence resulted in an observable bug on powerpc64le compile-time load reordering. The fence in _dlfo_mappings_begin_update has been reordered, turning the fence/store sequence into a release MO store equivalent. Relaxed MO loads are used on the reader side, and relaxed MO stores on the writer side for the shared data, to avoid formal data races. This is just to be conservative; it should not actually be necessary given how the data is used. This commit also fixes the test run time. The intent was to run it for 3 seconds, but 0.3 seconds was enough to uncover the bug very occasionally (while 3 seconds did not reliably show the bug on every test run). Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
* elf: Add reloc for OpenRISCStafford Horne2022-01-051-0/+37
| | | | Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Add a comment after trailing backslashesH.J. Lu2022-01-041-0/+4
|
* elf: Also try DT_RUNPATH for LD_AUDIT dlopen [BZ #28455]H.J. Lu2022-01-043-3/+24
| | | | | | | | | | | DT_RUNPATH is only used to find the immediate dependencies of the executable or shared object containing the DT_RUNPATH entry. Update LD_AUDIT dlopen call to try the DT_RUNPATH entry of the executable. Add tst-audit14a, which is copied from tst-audit14, to DT_RUNPATH and build tst-audit14 with -Wl,--disable-new-dtags to test DT_RPATH. This partially fixes BZ #28455.
* elf: Fix tst-linkall-static link when pthread is not in libcSamuel Thibault2022-01-041-0/+4
| | | | In that case we want to link in libanl.a, thus providing getaddrinfo_a.
* elf: Sort tests and modules-namesH.J. Lu2022-01-031-147/+405
| | | | Sort tests and modules-names to reduce future conflicts.
* Remove stale reference to libanl.aAdhemerval Zanella2022-01-031-1/+0
| | | | | Since dbb949f53d4 ("resolv: Move libanl into libc (if libpthread is in libc)") libanl.a is empty, so linking against it no longer necessary.
* elf: Add <dl-debug.h>H.J. Lu2022-01-032-18/+6
| | | | | | | Add <dl-debug.h> to setup debugging entry in PT_DYNAMIC segment to support DT_DEBUG, DT_MIPS_RLD_MAP_REL and DT_MIPS_RLD_MAP. Tested on x86-64, x32 and i686 as well as with build-many-glibcs.py.
* Update copyright dates not handled by scripts/update-copyrights.Paul Eggert2022-01-015-5/+5
| | | | | | | | | | | | | | I've updated copyright dates in glibc for 2022. This is the patch for the changes not generated by scripts/update-copyrights and subsequent build / regeneration of generated files. As well as the usual annual updates, mainly dates in --version output (minus csu/version.c which previously had to be handled manually but is now successfully updated by update-copyrights), there is a small change to the copyright notice in NEWS which should let NEWS get updated automatically next year. Please remember to include 2022 in the dates for any new files added in future (which means updating any existing uncommitted patches you have that add new files to use the new copyright dates in them).
* Update copyright dates with scripts/update-copyrightsPaul Eggert2022-01-01319-320/+320
| | | | | | | | | | | | | | | | | | | | | | | I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 7061 files FOO. I then removed trailing white space from math/tgmath.h, support/tst-support-open-dev-null-range.c, and sysdeps/x86_64/multiarch/strlen-vec.S, to work around the following obscure pre-commit check failure diagnostics from Savannah. I don't know why I run into these diagnostics whereas others evidently do not. remote: *** 912-#endif remote: *** 913: remote: *** 914- remote: *** error: lines with trailing whitespace found ... remote: *** error: sysdeps/unix/sysv/linux/statx_cp.c: trailing lines
* elf: Add _dl_find_object functionFlorian Weimer2021-12-2823-4/+1697
| | | | | | | | | | | | | | | | | | | | | | | | | It can be used to speed up the libgcc unwinder, and the internal _dl_find_dso_for_object function (which is used for caller identification in dlopen and related functions, and in dladdr). _dl_find_object is in the internal namespace due to bug 28503. If libgcc switches to _dl_find_object, this namespace issue will be fixed. It is located in libc for two reasons: it is necessary to forward the call to the static libc after static dlopen, and there is a link ordering issue with -static-libgcc and libgcc_eh.a because libc.so is not a linker script that includes ld.so in the glibc build tree (so that GCC's internal -lc after libgcc_eh.a does not pick up ld.so). It is necessary to do the i386 customization in the sysdeps/x86/bits/dl_find_object.h header shared with x86-64 because otherwise, multilib installations are broken. The implementation uses software transactional memory, as suggested by Torvald Riegel. Two copies of the supporting data structures are used, also achieving full async-signal-safety. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Do not fail for failed dlmopen on audit modules (BZ #28061)Adhemerval Zanella2021-12-284-2/+87
| | | | | | | | | | | | | | | | | | | | | The dl_main sets the LM_ID_BASE to RT_ADD just before starting to add load new shared objects. The state is set to RT_CONSISTENT just after all objects are loaded. However if a audit modules tries to dlmopen an inexistent module, the _dl_open will assert that the namespace is in an inconsistent state. This is different than dlopen, since first it will not use LM_ID_BASE and second _dl_map_object_from_fd is the sole responsible to set and reset the r_state value. So the assert on _dl_open can not really be seen if the state is consistent, since _dt_main resets it. This patch removes the assert. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Issue audit la_objopen for vDSOAdhemerval Zanella2021-12-286-8/+197
| | | | | | | | | | | | | | | The vDSO is is listed in the link_map chain, but is never the subject of an la_objopen call. A new internal flag __RTLD_VDSO is added that acts as __RTLD_OPENEXEC to allocate the required 'struct auditstate' extra space for the 'struct link_map'. The return value from the callback is currently ignored, since there is no PLT call involved by glibc when using the vDSO, neither the vDSO are exported directly. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Add audit tests for modules with TLSDESCAdhemerval Zanella2021-12-286-0/+242
| | | | | | Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Avoid unnecessary slowdown from profiling with audit (BZ#15533)Adhemerval Zanella2021-12-289-10/+289
| | | | | | | | | | | | | | | | | | | The rtld-audit interfaces introduces a slowdown due to enabling profiling instrumentation (as if LD_AUDIT implied LD_PROFILE). However, instrumenting is only necessary if one of audit libraries provides PLT callbacks (la_pltenter or la_pltexit symbols). Otherwise, the slowdown can be avoided. The following patch adjusts the logic that enables profiling to iterate over all audit modules and check if any of those provides a PLT hook. To keep la_symbind to work even without PLT callbacks, _dl_fixup now calls the audit callback if the modules implements it. Co-authored-by: Alexander Monakov <amonakov@ispras.ru> Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Add _dl_audit_pltexitAdhemerval Zanella2021-12-283-66/+58
| | | | | | | | | It consolidates the code required to call la_pltexit audit callback. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Add _dl_audit_pltenterAdhemerval Zanella2021-12-282-72/+78
| | | | | | | | | It consolidates the code required to call la_pltenter audit callback. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Add _dl_audit_preinitAdhemerval Zanella2021-12-282-1/+16
| | | | | | | | | It consolidates the code required to call la_preinit audit callback. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Add _dl_audit_symbind_alt and _dl_audit_symbindAdhemerval Zanella2021-12-284-124/+125
| | | | | | | | | It consolidates the code required to call la_symbind{32,64} audit callback. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Add _dl_audit_objcloseAdhemerval Zanella2021-12-283-34/+23
| | | | | | | | | It consolidates the code required to call la_objclose audit callback. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Add _dl_audit_objsearchAdhemerval Zanella2021-12-282-49/+40
| | | | | | | | | It consolidates the code required to call la_objsearch audit callback. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Add _dl_audit_activity_map and _dl_audit_activity_nsidAdhemerval Zanella2021-12-285-111/+35
| | | | | | | | | | | | | It consolidates the code required to call la_activity audit callback. Also for a new Lmid_t the namespace link_map list are empty, so it requires to check if before using it. This can happen for when audit module is used along with dlmopen. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Add _dl_audit_objopenAdhemerval Zanella2021-12-284-38/+44
| | | | | | | | It consolidates the code required to call la_objopen audit callback. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer <fweimer@redhat.com>
* elf: Remove AArch64 from comment for AT_MINSIGSTKSZH.J. Lu2021-12-231-2/+1
| | | | | | | | | | | | | | | | | Remove AArch64 from comment for AT_MINSIGSTKSZ to match commit 7cd60e43a6def40ecb75deb8decc677995970d0b Author: Chang S. Bae <chang.seok.bae@intel.com> Date: Tue May 18 13:03:15 2021 -0700 uapi/auxvec: Define the aux vector AT_MINSIGSTKSZ Define AT_MINSIGSTKSZ in the generic uapi header. It is already used as generic ABI in glibc's generic elf.h, and this define will prevent future namespace conflicts. In particular, x86 is also using this generic definition. in Linux kernel 5.14.
* elf: Remove unused NEED_DL_BASE_ADDR and _dl_base_addrFlorian Weimer2021-12-231-8/+0
| | | | Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>