Up to [cvs.NetBSD.org] / src / libexec / ld.elf_so
Request diff between arbitrary revisions
Keyword substitution: kv
Default branch: MAIN
ld.elf_so(1): Nix trailing whitespace. No functional change intended.
KNF
Pull up following revision(s), all via patch, (requested by riastradh in ticket #1699): distrib/sets/lists/tests/shl.mi: revision 1.14 distrib/sets/lists/tests/shl.mi: revision 1.15 distrib/sets/lists/tests/shl.mi: revision 1.16 tests/libexec/ld.elf_so/helper_def_static/h_def_static.c: revision 1.1 tests/libexec/ld.elf_so/helper_def_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_def_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_onlyuse_static/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_onlyuse_static/Makefile: revision 1.2 libexec/ld.elf_so/arch/mips/mips_reloc.c: revision 1.75 distrib/sets/lists/tests/mi: revision 1.1265 libexec/ld.elf_so/arch/sh3/mdreloc.c: revision 1.36 libexec/ld.elf_so/rtld.c: revision 1.214 tests/libexec/ld.elf_so/helper_onlydef_static/Makefile: revision 1.1 distrib/sets/lists/debug/mi: revision 1.400 tests/libexec/ld.elf_so/helper_onlydef_static/Makefile: revision 1.2 distrib/sets/lists/debug/mi: revision 1.401 distrib/sets/lists/debug/mi: revision 1.402 tests/libexec/ld.elf_so/helper_dso2/Makefile: revision 1.2 distrib/sets/lists/debug/mi: revision 1.403 tests/libexec/ld.elf_so/helper_symver_dso0/Makefile: revision 1.2 libexec/ld.elf_so/arch/x86_64/mdreloc.c: revision 1.48 distrib/sets/lists/debug/mi: revision 1.406 tests/libexec/ld.elf_so/helper_use_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_use_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_ifunc_dso/Makefile: revision 1.2 libexec/ld.elf_so/arch/sparc64/mdreloc.c: revision 1.70 libexec/ld.elf_so/arch/aarch64/mdreloc.c: revision 1.18 tests/libexec/ld.elf_so/helper_abuse_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_abuse_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/Makefile: revision 1.13 libexec/ld.elf_so/arch/arm/mdreloc.c: revision 1.46 libexec/ld.elf_so/rtld.h: revision 1.146 tests/libexec/ld.elf_so/Makefile: revision 1.14 distrib/sets/lists/debug/shl.mi: revision 1.306 tests/libexec/ld.elf_so/Makefile: revision 1.15 tests/libexec/ld.elf_so/helper_abuse_static/Makefile: revision 1.1 distrib/sets/lists/debug/shl.mi: revision 1.307 tests/libexec/ld.elf_so/Makefile: revision 1.16 tests/libexec/ld.elf_so/helper_abuse_static/Makefile: revision 1.2 distrib/sets/lists/debug/shl.mi: revision 1.308 tests/libexec/ld.elf_so/Makefile: revision 1.17 distrib/sets/lists/debug/shl.mi: revision 1.309 tests/libexec/ld.elf_so/Makefile: revision 1.18 tests/libexec/ld.elf_so/Makefile: revision 1.19 libexec/ld.elf_so/tls.c: revision 1.16 libexec/ld.elf_so/tls.c: revision 1.17 libexec/ld.elf_so/tls.c: revision 1.18 libexec/ld.elf_so/tls.c: revision 1.19 tests/libexec/ld.elf_so/helper_onlydef_static/h_onlydef_static.c: revision 1.1 tests/libexec/ld.elf_so/helper_use_static/h_use_static.c: revision 1.1 tests/libexec/ld.elf_so/helper_use_static/h_use_static.c: revision 1.2 tests/libexec/ld.elf_so/helper_def_static/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_def_static/Makefile: revision 1.2 libexec/ld.elf_so/arch/hppa/hppa_reloc.c: revision 1.50 distrib/sets/lists/debug/shl.mi: revision 1.310 libexec/ld.elf_so/README.TLS: revision 1.6 distrib/sets/lists/debug/shl.mi: revision 1.311 distrib/sets/lists/debug/shl.mi: revision 1.314 tests/libexec/ld.elf_so/helper_dso3/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_symver_dso1/Makefile: revision 1.4 libexec/ld.elf_so/arch/powerpc/ppc_reloc.c: revision 1.63 tests/libexec/ld.elf_so/helper_def_dynamic/h_def_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_onlydef/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_onlydef/Makefile: revision 1.2 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.10 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.11 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.12 libexec/ld.elf_so/map_object.c: revision 1.66 tests/libexec/ld.elf_so/helper.mk: revision 1.1 libexec/ld.elf_so/arch/sparc/mdreloc.c: revision 1.57 libexec/ld.elf_so/map_object.c: revision 1.67 tests/libexec/ld.elf_so/helper_onlydef/h_onlydef.c: revision 1.1 tests/libexec/ld.elf_so/helper_symver_dso2/Makefile: revision 1.4 tests/libexec/ld.elf_so/helper_use_static/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_use_static/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_use_static/Makefile: revision 1.3 tests/libexec/ld.elf_so/helper_use_dynamic/h_use_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_abuse_static/h_abuse_static.c: revision 1.1 libexec/ld.elf_so/arch/riscv/mdreloc.c: revision 1.9 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.1 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.2 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.3 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.4 tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.5 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.6 libexec/ld.elf_so/arch/m68k/mdreloc.c: revision 1.34 tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.7 libexec/ld.elf_so/arch/i386/mdreloc.c: revision 1.42 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.8 libexec/ld.elf_so/arch/i386/mdreloc.c: revision 1.43 libexec/ld.elf_so/arch/or1k/mdreloc.c: revision 1.4 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.9 tests/libexec/ld.elf_so/helper_onlyuse_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_onlyuse_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_abuse_dynamic/h_abuse_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_onlyuse_static/h_onlyuse_static.c: revision 1.1 tests/libexec/ld.elf_so/helper_onlyuse_dynamic/h_onlyuse_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_dso1/Makefile: revision 1.2 distrib/sets/lists/tests/shl.mi: revision 1.12 distrib/sets/lists/tests/shl.mi: revision 1.13 libexec/ld.elf_so/arch/alpha/alpha_reloc.c: revision 1.44 ld.elf_so: New test for extern initial-exec TLS, PR toolchain/50277. ld.elf_so: Fix extern TLS test to match PR toolchain/50277. Now it's actually testing the problem. ld.elf_so: Nix inadvertently committed private test program. ld.elf_so: Fix set lists for MKDEBUG=yes builds with t_tls_extern. ld.elf_so: Sprinkle tls debug messages. ld.elf_so: Make tls alloc debug messages more detailed and greppable. ld.elf_so: Test variations on PR toolchain/50277. ld.elf_so: Test extern dynamic TLS too. ld.elf_so: Factor out logic in TLS tests to make writing more easier. No functional change intended. ld.elf_so: Test TLS abuse of static def, dynamic use and vice versa. ld.elf_so: Shorter test names. No functional non-cosmetic change intended. ld.elf_so: Separately test eager and lazy resolution of def tls ptr. eager: before loading use library lazy: after loading use library Add recent ld.elf_so test helpers debug info ld.elf_so: Add new files to debug/shl.mi. ld.elf_so: tls_extern dynamic_defabuse_eager must xfail differently. If a symbol has already been resolved as dynamic TLS, any library that tries to use it as static TLS cannot be dlopened. ld.elf_so: Test another edge case of mismatched TLS models. One library defines a symbol and _doesn't_ use it, so it has no indication of whether the symbol is for static TLS or dynamic TLS, and then two other libraries use it in different ways. ld.elf_so: Test dynamic-then-static abuse via ctor. ld.elf_so: Fix missing tab in debug/shl.mi in last change. Fix interactions of initial-exec TLS model and dlopen (1) If an initial-exec relocation was used for a non-local symbol (i.e. the definition of the symbol is in a different DSO), the computation of the static TLS offset used the wrong DSO. This would effectively mean the wrong address was computed (PR toolchain/50277, PR pkg/57445). Fix this by forcing the computation of the correct DSO (the one defining the symbol). This code uses __UNCONST to avoid the vast interface changes for this special case. (2) If symbols from a DSO loaded via dlopen are used with both global-dynamic/local-dynamic and initial-exec relocations AND a initial-exec relocation was resolved first in a thread, a split brain situation could exist where the dynamic relocations would use one memory block (separate allocation) and the initial-exec relocations the static per-thread TLS space. (3) If the initial-exec relocation in (2) is seen after any thread has already used a GD/LD allocation, bail out. Since IE relocations are used only in the GOT, this will prevent the dlopen. This is a bit more aggressive than necessary, but a full blown reference counting doesn't seem to be justified. Avoid using uninitialized variable "symnum" when building with DEBUG enabled by borrowing the rdbg_symname() macro from arch/x86_64. ld.elf_so: Sprinkle more debug messages on dlopen and error. PR pkg/57445 Fix MKDEBUGLIB build by adding these installed files to the debug set list. One could argue that these files are not of any use, so why install them? I don't have a good argument either way, and this is (for now) a simple work-around for PR bin/57455 Please feel free to commit a different fix to avoid installing these files at all. Fix markup of libh_ MKDEBUGLIB=yes only files TLS variant I archs need to fudge the offset by the size of the TCB. tests/libexec/ld.elf_so: Fix helper library makefiles. 1. Consolidate logic into a single helper.mk to reduce duplication. 2. Set NO* variables, not MK* variables which are reserved for user. 3. Avoid eager X!= in favour of lazy ${X:sh}. 4. Mark _g.a set list entries obsolete. Never should've been built! PR misc/57462
Pull up following revision(s) (requested by riastradh in ticket #297): distrib/sets/lists/tests/shl.mi: revision 1.14 distrib/sets/lists/tests/shl.mi: revision 1.15 distrib/sets/lists/tests/shl.mi: revision 1.16 tests/libexec/ld.elf_so/helper_def_static/h_def_static.c: revision 1.1 tests/libexec/ld.elf_so/helper_def_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_def_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_onlyuse_static/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_onlyuse_static/Makefile: revision 1.2 libexec/ld.elf_so/arch/mips/mips_reloc.c: revision 1.75 distrib/sets/lists/tests/mi: revision 1.1265 libexec/ld.elf_so/arch/sh3/mdreloc.c: revision 1.36 libexec/ld.elf_so/rtld.c: revision 1.214 tests/libexec/ld.elf_so/helper_onlydef_static/Makefile: revision 1.1 distrib/sets/lists/debug/mi: revision 1.400 tests/libexec/ld.elf_so/helper_onlydef_static/Makefile: revision 1.2 distrib/sets/lists/debug/mi: revision 1.401 distrib/sets/lists/debug/mi: revision 1.402 tests/libexec/ld.elf_so/helper_dso2/Makefile: revision 1.2 distrib/sets/lists/debug/mi: revision 1.403 tests/libexec/ld.elf_so/helper_symver_dso0/Makefile: revision 1.2 libexec/ld.elf_so/arch/x86_64/mdreloc.c: revision 1.48 distrib/sets/lists/debug/mi: revision 1.406 tests/libexec/ld.elf_so/helper_use_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_use_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_ifunc_dso/Makefile: revision 1.2 libexec/ld.elf_so/arch/sparc64/mdreloc.c: revision 1.70 libexec/ld.elf_so/arch/aarch64/mdreloc.c: revision 1.18 tests/libexec/ld.elf_so/helper_abuse_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_abuse_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/Makefile: revision 1.13 libexec/ld.elf_so/arch/arm/mdreloc.c: revision 1.46 libexec/ld.elf_so/rtld.h: revision 1.146 tests/libexec/ld.elf_so/Makefile: revision 1.14 distrib/sets/lists/debug/shl.mi: revision 1.306 tests/libexec/ld.elf_so/Makefile: revision 1.15 tests/libexec/ld.elf_so/helper_abuse_static/Makefile: revision 1.1 distrib/sets/lists/debug/shl.mi: revision 1.307 tests/libexec/ld.elf_so/Makefile: revision 1.16 tests/libexec/ld.elf_so/helper_abuse_static/Makefile: revision 1.2 distrib/sets/lists/debug/shl.mi: revision 1.308 tests/libexec/ld.elf_so/Makefile: revision 1.17 distrib/sets/lists/debug/shl.mi: revision 1.309 tests/libexec/ld.elf_so/Makefile: revision 1.18 tests/libexec/ld.elf_so/Makefile: revision 1.19 libexec/ld.elf_so/tls.c: revision 1.16 libexec/ld.elf_so/tls.c: revision 1.17 libexec/ld.elf_so/tls.c: revision 1.18 libexec/ld.elf_so/tls.c: revision 1.19 tests/libexec/ld.elf_so/helper_onlydef_static/h_onlydef_static.c: revision 1.1 tests/libexec/ld.elf_so/helper_use_static/h_use_static.c: revision 1.1 tests/libexec/ld.elf_so/helper_use_static/h_use_static.c: revision 1.2 tests/libexec/ld.elf_so/helper_def_static/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_def_static/Makefile: revision 1.2 libexec/ld.elf_so/arch/hppa/hppa_reloc.c: revision 1.50 distrib/sets/lists/debug/shl.mi: revision 1.310 libexec/ld.elf_so/README.TLS: revision 1.6 distrib/sets/lists/debug/shl.mi: revision 1.311 distrib/sets/lists/debug/shl.mi: revision 1.314 tests/libexec/ld.elf_so/helper_dso3/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_symver_dso1/Makefile: revision 1.4 libexec/ld.elf_so/arch/powerpc/ppc_reloc.c: revision 1.63 tests/libexec/ld.elf_so/helper_def_dynamic/h_def_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_onlydef/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_onlydef/Makefile: revision 1.2 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.10 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.11 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.12 libexec/ld.elf_so/map_object.c: revision 1.66 tests/libexec/ld.elf_so/helper.mk: revision 1.1 libexec/ld.elf_so/arch/sparc/mdreloc.c: revision 1.57 libexec/ld.elf_so/map_object.c: revision 1.67 tests/libexec/ld.elf_so/helper_onlydef/h_onlydef.c: revision 1.1 tests/libexec/ld.elf_so/helper_symver_dso2/Makefile: revision 1.4 tests/libexec/ld.elf_so/helper_use_static/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_use_static/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_use_static/Makefile: revision 1.3 tests/libexec/ld.elf_so/helper_use_dynamic/h_use_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_abuse_static/h_abuse_static.c: revision 1.1 libexec/ld.elf_so/arch/riscv/mdreloc.c: revision 1.9 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.1 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.2 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.3 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.4 tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.5 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.6 libexec/ld.elf_so/arch/m68k/mdreloc.c: revision 1.34 tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.7 libexec/ld.elf_so/arch/i386/mdreloc.c: revision 1.42 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.8 libexec/ld.elf_so/arch/i386/mdreloc.c: revision 1.43 libexec/ld.elf_so/arch/or1k/mdreloc.c: revision 1.4 tests/libexec/ld.elf_so/t_tls_extern.c: revision 1.9 tests/libexec/ld.elf_so/helper_onlyuse_dynamic/Makefile: revision 1.1 tests/libexec/ld.elf_so/helper_onlyuse_dynamic/Makefile: revision 1.2 tests/libexec/ld.elf_so/helper_abuse_dynamic/h_abuse_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_onlyuse_static/h_onlyuse_static.c: revision 1.1 tests/libexec/ld.elf_so/helper_onlyuse_dynamic/h_onlyuse_dynamic.c: revision 1.1 tests/libexec/ld.elf_so/helper_dso1/Makefile: revision 1.2 distrib/sets/lists/tests/shl.mi: revision 1.12 distrib/sets/lists/tests/shl.mi: revision 1.13 libexec/ld.elf_so/arch/alpha/alpha_reloc.c: revision 1.44 (all via patch) ld.elf_so: New test for extern initial-exec TLS, PR toolchain/50277. ld.elf_so: Fix extern TLS test to match PR toolchain/50277. Now it's actually testing the problem. ld.elf_so: Nix inadvertently committed private test program. ld.elf_so: Fix set lists for MKDEBUG=yes builds with t_tls_extern. ld.elf_so: Sprinkle tls debug messages. ld.elf_so: Make tls alloc debug messages more detailed and greppable. ld.elf_so: Test variations on PR toolchain/50277. ld.elf_so: Test extern dynamic TLS too. ld.elf_so: Factor out logic in TLS tests to make writing more easier. No functional change intended. ld.elf_so: Test TLS abuse of static def, dynamic use and vice versa. ld.elf_so: Shorter test names. No functional non-cosmetic change intended. ld.elf_so: Separately test eager and lazy resolution of def tls ptr. eager: before loading use library lazy: after loading use library Add recent ld.elf_so test helpers debug info ld.elf_so: Add new files to debug/shl.mi. ld.elf_so: tls_extern dynamic_defabuse_eager must xfail differently. If a symbol has already been resolved as dynamic TLS, any library that tries to use it as static TLS cannot be dlopened. ld.elf_so: Test another edge case of mismatched TLS models. One library defines a symbol and _doesn't_ use it, so it has no indication of whether the symbol is for static TLS or dynamic TLS, and then two other libraries use it in different ways. ld.elf_so: Test dynamic-then-static abuse via ctor. ld.elf_so: Fix missing tab in debug/shl.mi in last change. Fix interactions of initial-exec TLS model and dlopen (1) If an initial-exec relocation was used for a non-local symbol (i.e. the definition of the symbol is in a different DSO), the computation of the static TLS offset used the wrong DSO. This would effectively mean the wrong address was computed (PR toolchain/50277, PR pkg/57445). Fix this by forcing the computation of the correct DSO (the one defining the symbol). This code uses __UNCONST to avoid the vast interface changes for this special case. (2) If symbols from a DSO loaded via dlopen are used with both global-dynamic/local-dynamic and initial-exec relocations AND a initial-exec relocation was resolved first in a thread, a split brain situation could exist where the dynamic relocations would use one memory block (separate allocation) and the initial-exec relocations the static per-thread TLS space. (3) If the initial-exec relocation in (2) is seen after any thread has already used a GD/LD allocation, bail out. Since IE relocations are used only in the GOT, this will prevent the dlopen. This is a bit more aggressive than necessary, but a full blown reference counting doesn't seem to be justified. Avoid using uninitialized variable "symnum" when building with DEBUG enabled by borrowing the rdbg_symname() macro from arch/x86_64. ld.elf_so: Sprinkle more debug messages on dlopen and error. PR pkg/57445 Fix MKDEBUGLIB build by adding these installed files to the debug set list. XXX One could argue that these files are not of any use, so why install them? I don't have a good argument either way, and this is (for now) a simple work-around for PR bin/57455 Please feel free to commit a different fix to avoid installing these files at all. Fix markup of libh_ MKDEBUGLIB=yes only files TLS variant I archs need to fudge the offset by the size of the TCB. tests/libexec/ld.elf_so: Fix helper library makefiles. 1. Consolidate logic into a single helper.mk to reduce duplication. 2. Set NO* variables, not MK* variables which are reserved for user. 3. Avoid eager X!= in favour of lazy ${X:sh}. 4. Mark _g.a set list entries obsolete. Never should've been built! PR misc/57462
Fix interactions of initial-exec TLS model and dlopen (1) If an initial-exec relocation was used for a non-local symbol (i.e. the definition of the symbol is in a different DSO), the computation of the static TLS offset used the wrong DSO. This would effectively mean the wrong address was computed (PR toolchain/50277, PR pkg/57445). Fix this by forcing the computation of the correct DSO (the one defining the symbol). This code uses __UNCONST to avoid the vast interface changes for this special case. (2) If symbols from a DSO loaded via dlopen are used with both global-dynamic/local-dynamic and initial-exec relocations AND a initial-exec relocation was resolved first in a thread, a split brain situation could exist where the dynamic relocations would use one memory block (separate allocation) and the initial-exec relocations the static per-thread TLS space. (3) If the initial-exec relocation in (2) is seen after any thread has already used a GD/LD allocation, bail out. Since IE relocations are used only in the GOT, this will prevent the dlopen. This is a bit more aggressive than necessary, but a full blown reference counting doesn't seem to be justified.
ld.elf_so: Sprinkle tls debug messages. XXX pullup-10
fix the ldd build
Handle program headers properly; fixes c++ exceptions on arm32.
Remove the limitation of only being able to load binaries with 2 PT_LOAD sections, like the kernel can. From FreeBSD.
_rtld_map_object(): no need to mmap an empty bss segment.
Merge changes from current as of 20200406
Pull up following revision(s) (requested by thorpej in ticket #758): libexec/ld.elf_so/map_object.c: revision 1.61 libexec/ld.elf_so/headers.c: revision 1.68 libexec/ld.elf_so/rtld.c: revision 1.203 PT_GNU_RELRO segments are arranged such that their vaddr + memsz ends on a linker common page size boundary. However, if the common page size used by the linker is less than the VM page size being used by the kernel, this can end up in the middle of a VM page and when the region is write- protected, this can cause objects in neighboring .data to get incorrectly write-protected, resulting in a crash. Avoid this situation by calculating the end of the RELRO region not by rounding memsz up to the VM page size, but rather by adding vaddr + memsz and then truncating to the VM page size. Fixes PR toolchain/55043. XXX pullup-9
PT_GNU_RELRO segments are arranged such that their vaddr + memsz ends on a linker common page size boundary. However, if the common page size used by the linker is less than the VM page size being used by the kernel, this can end up in the middle of a VM page and when the region is write- protected, this can cause objects in neighboring .data to get incorrectly write-protected, resulting in a crash. Avoid this situation by calculating the end of the RELRO region not by rounding memsz up to the VM page size, but rather by adding vaddr + memsz and then truncating to the VM page size. Fixes PR toolchain/55043. XXX pullup-9
Sync with HEAD
Synch with HEAD
When loading a non-PIE main binary, the virtual address must match. Use MAP_TRYFIXED and verify that the result matches the expectation.
MAP_ALIGNED has existed for years, just assume it exists.
Pull up following revision(s) (requested by joerg in ticket #64): libexec/ld.elf_so/arch/arm/mdreloc.c: revision 1.40 libexec/ld.elf_so/arch/arm/mdreloc.c: revision 1.41 libexec/ld.elf_so/arch/hppa/hppa_reloc.c: revision 1.44 libexec/ld.elf_so/arch/riscv/mdreloc.c: revision 1.3 libexec/ld.elf_so/arch/aarch64/mdreloc.c: revision 1.3 libexec/ld.elf_so/arch/sparc64/mdreloc.c: revision 1.60 libexec/ld.elf_so/arch/m68k/mdreloc.c: revision 1.32 libexec/ld.elf_so/arch/sparc64/mdreloc.c: revision 1.61 libexec/ld.elf_so/arch/or1k/mdreloc.c: revision 1.2 libexec/ld.elf_so/arch/sparc/mdreloc.c: revision 1.50 libexec/ld.elf_so/arch/sh3/mdreloc.c: revision 1.33 libexec/ld.elf_so/arch/sh3/mdreloc.c: revision 1.34 libexec/ld.elf_so/arch/arm/mdreloc.c: revision 1.39 libexec/ld.elf_so/symbol.c: revision 1.68 libexec/ld.elf_so/arch/mips/mips_reloc.c: revision 1.66 libexec/ld.elf_so/arch/mips/mips_reloc.c: revision 1.67 libexec/ld.elf_so/arch/mips/mips_reloc.c: revision 1.68 libexec/ld.elf_so/arch/x86_64/mdreloc.c: revision 1.42 libexec/ld.elf_so/arch/powerpc/ppc_reloc.c: revision 1.54 libexec/ld.elf_so/Makefile: revision 1.137 libexec/ld.elf_so/arch/vax/mdreloc.c: revision 1.32 libexec/ld.elf_so/rtld.h: revision 1.127 libexec/ld.elf_so/arch/vax/mdreloc.c: revision 1.33 libexec/ld.elf_so/arch/i386/mdreloc.c: revision 1.38 libexec/ld.elf_so/arch/alpha/alpha_reloc.c: revision 1.42 libexec/ld.elf_so/map_object.c: revision 1.58 libexec/ld.elf_so/arch/sparc/mdreloc.c: revision 1.49 Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects. The COMBREL logic predates thread-safety of the dynamic linker and breaks the use of shared locks for the common symbol lookup case. It is unlikely to provide any benefit for lazy binding or PLT lookups, so provide equivalent functionality in the non-PLT relocation handling loop by checking if the symbol used by the current relocation is the same as the one used during the last lookup. No inter-object cachine is done as it is also unlikely to be benefical. Testing with Firefox startup on AMD64 shows a small performance gain by the new method. Drop symbol number from default branch diagnostic, it isn't set at this point and most likely not valid either. Expand symnum, GCC's uninitialized used tracking is too imprecise. Fix C&P bug. Deal with more MIPS hacks overriding def. Add last_symnum, move up def and defobj. Add back symnum, fix debug print. Replace last use of r_type. Fix indentation. Fix indentation.
Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects. The COMBREL logic predates thread-safety of the dynamic linker and breaks the use of shared locks for the common symbol lookup case. It is unlikely to provide any benefit for lazy binding or PLT lookups, so provide equivalent functionality in the non-PLT relocation handling loop by checking if the symbol used by the current relocation is the same as the one used during the last lookup. No inter-object cachine is done as it is also unlikely to be benefical. Testing with Firefox startup on AMD64 shows a small performance gain by the new method.
Sync with HEAD
Sync with HEAD
Revert to version 1.55 of map_object.c. This reverts: "really unmap the gap between the text and data rather than just removing all access with mprotect(). the latter results in the kernel having to keep track of that range separately since the permissions are different. avoid calling mmap() with a size of zero." As per toolchain/52054: src/libexec/ld.elf_so update breaks everything, this commit is very broken for some people (but not others). chs mentioned he has a fix, but best not to leave -current broken in the meantime.
really unmap the gap between the text and data rather than just removing all access with mprotect(). the latter results in the kernel having to keep track of that range separately since the permissions are different. avoid calling mmap() with a size of zero.
Move relro after we've computed out relocbase and re-enable it. (Matthias Weckbecker)
Add support for GNU RELRO headers from Matthias Weckbecker.
Catch up to -current, via patch, requested by christos in ticket #1126:
Avoid use after free, reported by the coverity scanner.
Rebase to HEAD as of a few days ago.
sync with head. for a reference, the tree before this commit was tagged as yamt-pagecache-tag8. this commit was splitted into small chunks to avoid a limitation of cvs. ("Protocol error: too many arguments")
Fix DEBUG build.
resync from head
convert to SIMPLEQ like the rest of the queues.
need xfree() instead of free(). Using free() ends us up in an infinite loop.
Fixed handling of DT_SONAME: - add function to add name aliases for shared libraries loaded XXX[1]: we don't add a name during load time, only when DT_SONAME is present. - search already loaded objects in load_by_name for an already loaded object that matches our name and return it. - add missing initialization and cleanup for obj->names XXX[2]: should we make them SIMPLEQ? - Add XXX in rtld.c about getting the name of an object. NB: This makes the jdk work again without resorting to a hack of putting the build path of libjvm.so into the run path (which is a security problem). XXX: Pullup-6?
Trailing whitespace
Adjust exidx_start by relocbase
Handle PT_ARM_EXIDX when mapping objects.
Resync to 2012-11-19 00:00:00 UTC
sync with head
Improve the diagnostic messages for invalid/non-ELF files. Proposed a while back; I forget the context. Has been sitting in one of my trees awaiting a test run since, apparently, August 2011.
Try to make dbg() printfs realy ELFSIZE independent
Pull up following revision(s) via patch (requested by skrll in ticket #1724): rescue/list.ldd: revision 1.4 lib/libc/dlfcn/dlfcn_elf.c: revision 1.7 libexec/ld.elf_so/arch/mips/mips_reloc.c: revision 1.57 distrib/sets/lists/comp/mi: revision 1.1512 share/man/man3/Makefile: revision 1.56 libexec/ld.elf_so/arch/mips/mips_reloc.c: revision 1.58 usr.bin/ldd/ldd.c: revision 1.15 libexec/ld.elf_so/rtld.h: revision 1.84 share/man/man3/dl_iterate_phdr.3: revision 1.1 libexec/ld.elf_so/rtld.c: revision 1.129 libexec/ld.elf_so/arch/powerpc/ppc_reloc.c: revision 1.44 libexec/ld.elf_so/rtld.h: revision 1.89 libexec/ld.elf_so/arch/x86_64/mdreloc.c: revision 1.36 libexec/ld.elf_so/map_object.c: revision 1.41 libexec/ld.elf_so/arch/x86_64/mdreloc.c: revision 1.37 libexec/ld.elf_so/arch/sparc64/mdreloc.c: revision 1.46 include/link_elf.h: revision 1.10 libexec/ld.elf_so/arch/i386/mdreloc.c: revision 1.29 libexec/ld.elf_so/arch/vax/mdreloc.c: revision 1.26 libexec/ld.elf_so/arch/alpha/alpha_reloc.c: revision 1.34 libexec/ld.elf_so/arch/hppa/hppa_reloc.c: revision 1.31 libexec/ld.elf_so/arch/alpha/alpha_reloc.c: revision 1.35 libexec/ld.elf_so/Makefile: revision 1.94 libexec/ld.elf_so/arch/hppa/hppa_reloc.c: revision 1.32 libexec/ld.elf_so/Makefile: revision 1.95 libexec/ld.elf_so/arch/arm/mdreloc.c: revision 1.31 libexec/ld.elf_so/Makefile: revision 1.96 libexec/ld.elf_so/arch/arm/mdreloc.c: revision 1.32 libexec/ld.elf_so/reloc.c: revision 1.98 libexec/ld.elf_so/arch/arm/mdreloc.c: revision 1.33 sys/sys/exec_elf.h: revision 1.106 libexec/ld.elf_so/rtld.c: revision 1.130 libexec/ld.elf_so/load.c: revision 1.37 libexec/ld.elf_so/rtld.c: revision 1.131 libexec/ld.elf_so/load.c: revision 1.38 libexec/ld.elf_so/rtld.h: revision 1.90 libexec/ld.elf_so/headers.c: revision 1.36 libexec/ld.elf_so/rtld.h: revision 1.95 libexec/ld.elf_so/arch/i386/mdreloc.c: revision 1.30 libexec/ld.elf_so/arch/m68k/mdreloc.c: revision 1.25 libexec/ld.elf_so/symbol.c: revision 1.50 libexec/ld.elf_so/symbol.c: revision 1.51 libexec/ld.elf_so/arch/sparc/mdreloc.c: revision 1.43 libexec/ld.elf_so/symbol.c: revision 1.52 libexec/ld.elf_so/arch/sh3/mdreloc.c: revision 1.27 libexec/ld.elf_so/symbol.c: revision 1.54 PR/39240: Satoshi Suetake: Don't fail when attempting to resolve weak symbols when we are doing immediate binding, leave them alone and they will be dealt with later during lazy binding. From skrll@ Implement negative cache checks for symbol lookups. Uses the Donelist idea from FreeBSD. Use alloca(3) instead of local xmalloc for creating our DoneLists. This allows threaded programs to use us a little better, PR lib/43005. Implement dl_iterate_phdr. Somewhat taken from FreeBSD. Manual page from OpenBSD.
consistent debugging info for program headers
Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports _rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to setup the thread private area of all new threads. ld.elf_so is responsible for setting up the private area for the initial thread. Similar functions are called from _libc_init for static binaries, using dl_iterate_phdr to access the ELF Program Header. Add test cases to exercise the different TLS storage models. Test cases are compiled and installed on all platforms, but are skipped on platforms not marked for TLS support. This material is based upon work partially supported by The NetBSD Foundation under a contract with Joerg Sonnenberger. It is inspired by the TLS support in FreeBSD by Doug Rabson and the clean ups of the DragonFly port of the original FreeBSD modifications.
Implement dl_iterate_phdr. Somewhat taken from FreeBSD. Manual page from OpenBSD.
Wrap long line.
sync to netbsd-5
Pull up following revision(s) (requested by skrll in ticket #1266): libexec/ld.elf_so/map_object.c: revision 1.39 libexec/ld.elf_so/rtld.h: revision 1.83 libexec/ld.elf_so/symbol.c: revision 1.49 Reset the COMBRELOC cache Obj_Entry if it was freed. Fixes PR 41482. Done slightly differently to the patch in the PR.
Reset the COMBRELOC cache Obj_Entry if it was freed. Fixes PR 41482. Done slightly differently to the patch in the PR.
warns=4
Pull up following revision(s) (requested by mrg in ticket #265): libexec/ld.elf_so/headers.c: revision 1.27 rescue/list: revision 1.35 libexec/ld.elf_so/arch/sparc/Makefile.ld32: revision 1.1 usr.bin/ldd/Makefile.elf: revision 1.1 usr.bin/ldd/Makefile.elf: revision 1.2 usr.bin/ldd/ldd_aout/ldd.c: file removal usr.bin/ldd/Makefile.elf: revision 1.3 libexec/ld.elf_so/arch/sparc/Makefile.inc: revision 1.12 usr.bin/ldd/dummy.c: revision 1.1 gnu/usr.bin/binutils/ld/Makefile: revision 1.28 usr.bin/ldd/elf32/Makefile: revision 1.1 usr.bin/ldd/elf32/Makefile: revision 1.2 usr.bin/ldd/ldd.c: revision 1.3 usr.bin/ldd/elf32/Makefile: revision 1.3 usr.bin/ldd/ldd_elf/Makefile: file removal usr.bin/ldd/ldd.h: revision 1.1 usr.bin/ldd/ldd.c: revision 1.4 usr.bin/ldd/ldd_aout.c: revision 1.1 usr.bin/ldd/Makefile: revision 1.8 usr.bin/ldd/Makefile: revision 1.9 usr.bin/ldd/ldd_elfxx.c: revision 1.1 libexec/ld.elf_so/map_object.c: revision 1.37 usr.bin/ldd/ldd_aout/Makefile: file removal usr.bin/ldd/elf64/Makefile: revision 1.1 rescue/Makefile: revision 1.22 libexec/ld.elf_so/arch/i386/Makefile.ld32: revision 1.1 usr.bin/ldd/ldd_elf/ldd.c: file removal usr.bin/ldd/elf64/Makefile: revision 1.2 usr.bin/ldd/elf64/Makefile: revision 1.3 usr.bin/ldd/aout/Makefile: revision 1.1 libexec/ld.elf_so/arch/i386/Makefile.inc: revision 1.12 rescue/list.ldd: revision 1.1 usr.bin/ldd/ldd_elf/README: file removal usr.bin/ldd/Makefile.common: revision 1.1 move the defines for RTLD_ARCH_SUBDIR into a sub-sub-makefile so we can grab these values via reach-over more easily. some fixes for PR#40170: - set NATIVE=yes in the environment for genscripts.sh - set LIB_PATH to /usr/lib/{sparc,i386} for those scripts - set use_sysroot to "yes", to enable LIB_PATH to work in genscripts.sh - get rid of building an a.out-happy ldd (but keep supporting a.out binaries for the ELF version.) - convert a.out, elf32 and elf64 support into convience libraries and link them right ones in. if elf_ldd() fails on 64 bit platforms, try elf32_ldd() before aout_ldd(). now ldd on 64 bit platforms works for 32 bit binaries, aka PR#40199, and it seems that all the issues from README are gone too. add some (uintptr_t) to some casts, so these compile with ELFSIZE=32 *and _LP64. necessary for 32/64 bit combo ldd support. - rework this a bunch to make it work inside /rescue/ldd. - fix alpha build. make sure we set LIBISPRIVATE. fixes build issues reported by moof. make sure we set LIBISPRIVATE. fixes build issues reported by moof.
add some (uintptr_t) to some casts, so these compile with ELFSIZE=32 *and _LP64. necessary for 32/64 bit combo ldd support.
Sync w/ -current. 34 merge conflicts to follow.
sync with head.
Don't bother unmapping the ELF header unless it overlaps the first load section.
sync with HEAD
- Don't use the names malloc/free/etc, since we can end up pulling in libc's malloc which is not what we want. - Remove ancient memory compaction hack. Realloc on free memory is now an error again (from joerg@). Ok christos@.
Coverity CID 2749: Fix another double free. Instead of removing that last free() call, change the allocation policy to leave the responsibility for allocation/freeing the pathname to _rtld_map_object(), instead of having the caller allocate it and _rtld_map_object() free it. This simplifies the code a lot and it is more efficient.
Fix some double frees / missing frees / use after freed all relating to _rtld_load_object. Fix Coverity CID 2601, 2600.
appease gcc -Wuninitialized
Add __RCSIDs. OK'd by mycroft.
Apply patch (request by skrll in ticket #1702): Bring "ld.elf_so" (mostly) in sync with NetBSD-current: - MI and MD (e.g. under NetBSD-alpha) performance improvements - RTLD_SELF, RTLD_NEXT, RTLD_DEFAULT support - much better structured code - closes PR bin/25464
ANSIfy and de-__P().
KNF- blank lines before code at start of functions.
make it compile in /usr/src/rescue directory.
Align psections to their specified alignment (if possible). Use mmap(2) MAP_ALIGNED.
If fstat info was passed, and from it it can be seen that the file size is smaller than an ELF header, don't even bother to try to look at it. Avoids coredumps with zero-sized files.
A bit speedup: in _rtld_load_object(), save the number of calls to strcmp() by performing path name length comparison first. In the test with Mozilla, the number was reduced to 1068 from 7182 (yes, we saved 6114 strcmp()!).
Minor cleanup.
Make this work for ldd again.
Rearrange _rtld_map_object() a little, so that we don't have to have the first page of the object double-mapped. Not that it matters much, but someone was whinging about it. While I'm at it, nuke obj->phdr and obj->phsize; they're unused.
Change the munmap() of the text-data gap to mprotect(PROT_NONE). This avoids having scattered little mappings, although it's probably not the best way...
Woops, unmap the first page in the `win' case, too. Tidy up a bit.
Use _rtld_pagesz instead of PAGESIZE.
space -> tab.
Don't need to use union any longer.
Several small changes that shave 7-8% off the simple-exec-loop test: * Rename _rtld_find_library() to _rtld_load_library(). It now calls _rtld_load_object() if necessary to actually load the object, rather than having the caller do it. To do this, it also takes the `mode' argument that gets passed to _rtld_load_object(). * On a related note, remove _rtld_check_library(), and instead call _rtld_load_object() to instead try actually loading the object. We save two extra namei's and a bunch of redundant work (almost literally the same code) this way. * In _rtld_map_object(), mmap(2) the first page read-only, rather than read(2)ing it. * In _rtld_symlook_obj(), compare the *second* character of the symbol name before calling strcmp(). (This first character is too frequently `_', and turns out to not be helpful, in libc.) * Also in _rtld_symlook_obj(), remove the bogus STT_FUNC special case -- this also allows removing the `in_plt' argument to _rtld_symlook_list() and _rtld_symlook_obj(). Also: * In _rtld_obj_from_addr(), rather than trying to look up `_end' in the each object, instead use obj->mapsize as the upper bound.
Nuke two frivolous assert()s.
Introduce a new flag, `isdynamic', which is used to remember whether the executable was of type ET_DYN. Use this instead of `mainprog' to determine whether we need to do base-relative fixups of the PLT. (This allows loading non-relocatable objects, should we desire to do that at some point...)
SIMPLEQ rototill: - implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n), this mirrors the functionality of SLIST_REMOVE() (the other singly-linked list type) and FreeBSD's STAILQ_REMOVE() - remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD(). this mirrors the functionality of SLIST_REMOVE_HEAD() (the other singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD() - remove notes about SIMPLEQ not supporting arbitrary element removal - use SIMPLEQ_FOREACH() instead of home-grown for loops - use SIMPLEQ_EMPTY() appropriately - use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly - reorder manual page; be consistent about how the types are listed - other minor cleanups
Pull up revision 1.12 (requested by skrll): Add init/fini section support in crtbegin and crtend, and introduce support for DWARF2 exception handling. Fixes PR#12865, PR#13488, PR#13489, and PR#13491. Also fix ld.elf_so to deal appropriately.
Return an error when there are too many segments rather than abort()ing. This way `ldd /usr/libexec/ld.elf_so' doesn't core dump.
switch back to using a file mapping for the initial mapping of a new object. this allows the kernel to use PMAP_PREFER() to give us better alignment on platforms that care.
Pull up to last week's -current.
Changes from msaitoh to fix local/global symbol confusion, and to fix weak symbol support -- updated by me for elf.h changes.
Remove ELFNAME defines since they are defined in sys/exec_elf.h
Update to match new SVR4-style definition names in <sys/exec_elf.h>.
Undo last change. While these macros are defined in exec_elf.h, they are enclosed by `#ifdef _KERNEL'.
Remove ELFNAME macros which are already defines in exec_elf.h
When allocating the entire address space of an object, map an anonymous region first (using the data/bss protection) covering it, then overlay the text and data regions at the appropriate offsets within the region, and then unmap any gap between the text and data. The previous method of maping the entire address space with the actual file object itself is incorrect, as it may extend past the end of the file if the section alignment is large enough. This bug was the source of the libposix failure on the SPARC and another similar failure (with libc!) on the Alpha (failure was accompanied by a "uvn_io: size check fired" message on the console).
KNF
Fill in missing (default) mmap(2) flags.
Mipsel changes to ELF ldd/ld.so: * don't abort() on NetBSD/pmax 1.1 elf binaries; * Assume 32-bit elf unless compiling for Alpha; * note bugs in ldd's README.
First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to make it work with new versions of the toolchain, etc.). This runs, but it's in serious need of cleaning and/or a fair bit of reworking. See the README file for more information, and a list of things to do.