summaryrefslogtreecommitdiff
path: root/ldso
AgeCommit message (Collapse)Author
2022-03-10dl-elf: Supress adding double '/' in library pathnameDaniel Dorau
When searching for shared libraries, it could happen that redudant '/' were added to the pathname with would later be reported via dladdr() in the dli_fname member. Signed-off-by: Daniel Dorau <d.dorau@avm.de>
2021-12-24Fix -Wundef related warningsYann Sionneau
Signed-off-by: Yann Sionneau <ysionneau@kalray.eu>
2021-06-04powerpc: fix PIE/PIC builds with newer gcc/binutils which use secureplt by ↵Yann Sionneau
default This patch fixes segfault of all user space processes (including init, which caused a panic) on recent buildroot powerpc32 builds. The issue has been reported by Romain Naour in this thread: https://mailman.uclibc-ng.org/pipermail/devel/2021-May/002068.html Recent buildroot toolchain enables secure PLT in powerpc gcc. The latter will then supply -msecure-plt to gas invocations by default. Recent buildroot also enables PIE by defaults. For the secure PLT to work in PIC, the r30 register needs to point to the GOT. Old "bss plt" was just a one-instruction-wide PLT slot, pointed-to by a R_PPC_JMP_SLOT relocation, which was written on-the-fly to contain a branch instruction to the correct address. It therefore had to stay writable. New secure PLT only contains read-only code which loads the branch address from the writable GOT. Note: secure PLT without PIC does not need r30 to be set. Because offset between plt stub code and got is known at link-time. In this case the PLT entry looks like: 1009b3e0 <__uClibc_main@plt>: 1009b3e0: 3d 60 10 0e lis r11,4110 1009b3e4: 81 6b 03 74 lwz r11,884(r11) 1009b3e8: 7d 69 03 a6 mtctr r11 1009b3ec: 4e 80 04 20 bctr Whereas secure PLT with PIC - offset between plt and got is unknown at link-time - looks like this: 000af800 <00000000.plt_pic32.__uClibc_main>: af800: 81 7e 03 80 lwz r11,896(r30) af804: 7d 69 03 a6 mtctr r11 af808: 4e 80 04 20 bctr af80c: 60 00 00 00 nop Signed-off-by: Yann Sionneau <yann@sionneau.net>
2021-02-08riscv64: sync ldso relocations with or1k, fixes 5 testsuite errorsWaldemar Brodkorb
2020-10-02kvx: add support for kvx arch to uClibc-ngYann Sionneau
This commit adds support for Kalray VLIW family (kvx) Kalray kv3 core is embedded in Kalray Coolidge SoC. This core which is the third of the KV family has the following features: 32/64 bits execution mode 6-issue VLIW architecture 64 x 64bits general purpose registers SIMD instructions little-endian In order to build a usable toolchain, build scripts are provided at the following address: https://github.com/kalray/build-scripts. Kalray uses FOSS which is available at https://github.com/kalray This includes Linux kernel, uClibc-ng, gcc, binutils, etc. Signed-off-by: Clément Léger <cleger@kalray.eu> Signed-off-by: Guillaume Thouvenin <gthouvenin@kalray.eu> Signed-off-by: Laurent Thevenoux <lthevenoux@kalray.eu> Signed-off-by: Marc Poulhies <mpoulhies@kalray.eu> Signed-off-by: Marius Gligor <mgligor@kalray.eu> Signed-off-by: Yann Sionneau <ysionneau@kalray.eu>
2020-09-22Fix unused variable warning in dl-startup.cYann Sionneau
SEND_STDERR_DEBUG does nothing if __SUPPORT_LD_DEBUG_EARLY__ is not defined thus causing a warning. Fixes this: In file included from ldso/ldso/ldso.c:86:0: ldso/ldso/dl-startup.c: In function '_dl_start': ldso/ldso/dl-startup.c:313:13: warning: variable 'strtab' set but not used [-Wunused-but-set-variable] char *strtab; ^~~~~~ Signed-off-by: Yann Sionneau <ysionneau@kalray.eu>
2020-08-25ldso: Fix pointer cast warningYann Sionneau
Fixes the following compilation warning for 64-bit arch with TLS support: CC ldso/libdl/libdl.oS ldso/libdl/libdl.c: In function 'do_dlsym': ldso/libdl/libdl.c:739:59: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] ret = _dl_tls_symaddr ((struct link_map *)sym_ref.tpnt, (Elf32_Addr)ret); ^
2020-04-01statx: make include conditional, fixes non-csky arch buildroot buildsWaldemar Brodkorb
2020-04-01or1k: fix some TLS issuesYann Sionneau
Before this commit tst-tls-at-ctor test would segfault. After it passes. testsuite run before: https://pastebin.com/504JgQXa testsuite run after: https://pastebin.com/d2aNciVt Stafford Horne already fixed it in glibc: * https://github.com/openrisc/or1k-glibc/blob/bcd87396ebe78228645c0731b06c934dfd88855a/sysdeps/or1k/dl-machine.h#L298 * https://github.com/openrisc/or1k-glibc/blob/bcd87396ebe78228645c0731b06c934dfd88855a/sysdeps/or1k/dl-machine.h#L99
2020-02-03csky: add statx conditionalsWaldemar Brodkorb
Similar to glibc commit https://sourceware.org/git/?p=glibc.git;a=commit;h=6bbfc5c09fc5b5e3d4a0cddbbd4e2e457767dae7 we need to handle Linux kernel change, which removed stat64 family from default syscall set. Signed-off-by: Waldemar Brodkorb <wbx@openadk.org> Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
2019-11-08riscv64: implement NPTL/TLSWaldemar Brodkorb
basically from or1k port of uClibc-ng, with fixes for structures in pthreadtypes.h from 64 bit architectures. 18 testsuite failures counted.
2019-11-06riscv64: lazy relocations do not work like sparc/m68kWaldemar Brodkorb
2019-11-01riscv64: add shared library supportWaldemar Brodkorb
2019-04-14Fix build with SUPPORT_LD_DEBUG_EARLY enabledKonstantin Vasin
2018-12-31csky: Add EM_CSKY for ldsoGuo Ren
Support EM_CSKY 252 elf format. Changelog: Increase EM_NUM to 253 Signed-off-by: Guo Ren <ren_guo@c-sky.com> Signed-off-by: Mao Han <han_mao@c-sky.com>
2018-11-01Add support for Thumb-only processors.Christophe Lyon
* ldso/ldso/arm/aeabi_read_tp.S: Add Thumb version. * ldso/ldso/arm/dl-startup.h: Do not force ARM encoding, adjust for Thumb. * ldso/ldso/arm/resolve.S: Force Thumb encoding on Thumb-only processors. * libc/sysdeps/linux/arm/crt1.S: Do not force ARM encoding, adjust for Thumb. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-10-27ARC: Accommodate TLS fix in BinutilsEvgeniy Didin
[1] fixes clash of TLS variables on ARC and since LD now calculates relocations a bit different now we need to update dynamic loader as well otherwise relocs will be calculated improperly. Note this is an ABI change and should go in-line with corresponding ARC tools. That said either arc-2018.09 (to be released in few weeks) or the next version of upstream Binutils (2.32) are required for normal TLS work on ARC. Testcase: ----------------------------------8<------------------------------- #include <stdio.h> int foo3(void); int foo1(void); #ifdef _SHARED int foo1(){ static __thread int val3=1; val3 += 2; return val3; } #elif _SHARED2 int foo3(){ static __thread int val2=0; val2 += 2; return val2; } #else int main(){ printf("foo1 = %d \n", foo1()); printf("foo3 = %d \n", foo3()); return 0; } #endif --------------------------------->8--------------------------------------- The result shoud be: ----8<---- foo1 = 3 foo3 = 2 ---->8---- Commands to build artefacts: ----------------------------------------8<------------------------------- arc-linux-gcc -fPIE -ffunction-sections -fdata-sections -pthread -Os \ -fPIC -o testtls.o -D_SHARED -c tst.c arc-linux-gcc -fPIE -ffunction-sections -fdata-sections -pthread -Os \ -fPIC -o testtls2.o -D_SHARED2 -c tst.c arc-linux-gcc -shared -o libtesttls.so testtls.o testtls2.o -lm -Os arc-linux-gcc tst.c -o tst.out -L./ -ltesttls -Os -fPIE --------------------------------->8--------------------------------------- Add path to libtesttls.so file to LD_LIBRARY_PATH before runnig tst.out application. [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=714e9a954a2e4123dcb26bb8da850e1344de4f5f Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com> Signed-off-by: Evgeniy Didin <didin@synopsys.com> CC: Cupertino Miranda <cmiranda@synopsys.com> CC: Vineet Gupta <vgupta@synopsys.com> CC: Waldemar Brodkorb <wbx@uclibc-ng.org>
2018-08-10rtld: Avoid crash on R_ARM_NONE relocationChristophe Lyon
R_ARM_NONE contains no data, so avoid dereferencing it. * ldso/ldso/arm/elfinterp.c (_dl_do_reloc): Handle R_ARM_NONE relocation (_dl_do_reloc_lazy): Likewise. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10Fix htab_delete loop counterChristophe Lyon
dlclose can crash or stuck the system: When calling dlclose() then system can crash or freeze, because htab_delete() in ldso/ldso/fdpic/dl-inlines.h uses size_t for i which is a typedef to unsigned int. We exit the loop on negative value of i which can never occur since i is an unsigned int. This leads to random free of various pointers that kill the system. * ldso/include/inline-hashtab.h (htab_delete): Change type of 'i' to int. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10rtld: Initialize _dl_error_catch_tsd without FUNCDESC relocationChristophe Lyon
Make _dl_initial_error_catch_tsd hidden, such that we do not need a FUNCDESC relocation when initializing _dl_error_catch_tsd. * ldso/ldso/dl-tls.c (_dl_initial_error_catch_tsd): Declare hidden. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10rtld: Use ELF_RTYPE_CLASS_DLSYMChristophe Lyon
rtld must call _dl_find_hash() with ELF_RTYPE_CLASS_DLSYM since we want a function descriptor. * ldso/ldso/ldso.c (_dl_get_ready_to_run): Support __FDPIC__. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10rtld: Compile with -fno-unwind-tables -fno-asynchronous-unwind-tablesChristophe Lyon
Otherwise we have link errors because of unresolved refs in libgcc.a: ld: /lib/gcc/arm-none-uclinuxfdpiceabi/9.0.0/libgcc.a(pr-support.o): in function `_Unwind_GetDataRelBase': /libgcc/config/arm/pr-support.c:378: undefined reference to `abort' ld: /lib/gcc/arm-none-uclinuxfdpiceabi/9.0.0/libgcc.a(unwind-arm.o): in function `unwind_phase2_forced': /libgcc/unwind-arm-common.inc:511: undefined reference to `memcpy' * ldso/ldso/Makefile.in (CFLAGS-rtld): Always use -fno-unwind-tables -fno-asynchronous-unwind-tables on arm Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10rtld: Add lazy binding supportChristophe Lyon
Add support for R_ARM_FUNCDESC_VALUE and implement _dl_linux_resolver for FDPIC on ARM. * ldso/ldso/arm/elfinterp.c (_dl_linux_resolver): Support __FDPIC__. (_dl_do_lazy_reloc): Likewise. * ldso/ldso/arm/resolve.S (_dl_linux_resolve): Likewise. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10TLS: fix relocation computationChristophe Lyon
* ldso/ldso/dl-elf.c (_dl_load_elf_shared_library): Fix l_tls_initimage computation. * ldso/ldso/ldso.c (_dl_get_ready_to_run): Likewise. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10Fix bug in _dl_pread when using pread64 syscallChristophe Lyon
In ARM_EABI mode, the pread64 syscall parameters are aligned on 64-bits. This syscall is used in rtld when processing FDPIC relocations. * ldso/include/dl-syscall.h (__syscall_pread): Fix definition. (__dl_pread): Fix syscall invocation. * ldso/ldso/fdpic/dl-sysdep.h (__DL_PREAD): Handle __NR_pread64. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10rtld: Add startup codeChristophe Lyon
Implement _start: compute parameters for __self_reloc, and give control to the user program. * ldso/ldso/arm/dl-startup.h: Implement _start for __FDPIC__. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10rtld: Avoid FUNCDESC relocation on _startChristophe Lyon
* ldso/ldso/ldso.c (_start): Fix definition for __FDPIC__. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10rtld: Add FDPIC code for armChristophe Lyon
Add FDPIC dynamic relocations support, similar to what other FDPIC targets do. Lazy binding is implemented in a folllow-up patch. Disable the SEND* macros because they involve relocations to access constant strings that are unsupported by the existing arm version. Define DL_START, START, ARCH_NEEDS_BOOTSTRAP_RELOCS, DL_CHECK_LIB_TYPE similarly to what other FDPIC targets do. Define raise() because _dl_find_hash references __aeabi_uidivmod, which uses __aeabi_idiv0 which in turn references raise. * include/elf.h (R_ARM_FUNCDESC): Define. (R_ARM_FUNCDESC_VALUE): Define. * ldso/include/dl-string.h (SEND_STDERR, SEND_ADDRESS_STDERR) (SEND_NUMBER_STDERR): Define empty for __FDPIC__. * ldso/ldso/arm/dl-inlines.h: New file. * ldso/ldso/arm/dl-startup.h (PERFORM_BOOTSTRAP_RELOC): Fix type of load_addr. Fix handling of R_ARM_RELATIVE, add support for R_ARM_FUNCDESC_VALUE. (DL_START, START): Define for __FDPIC__. (raise): Define. * ldso/ldso/arm/dl-sysdep.h (ARCH_NEEDS_BOOTSTRAP_RELOCS): Define. (DL_CHECK_LIB_TYPE): Define. (elf_machine_type_class): Take into account FDPIC related relocations. (elf_machine_load_address): Support __FDPIC__. (elf_machine_relative): Likewise. * ldso/ldso/arm/elfinterp.c (_dl_linux_resolver): Dummy support for __FDPIC__, implemented in a later patch. (_dl_do_reloc): Fix reloc_adr computation for __FDPIC__, fix handling of local symbols. Fix handling of R_ARM_RELATIVE, add support for R_ARM_FUNCDESC_VALUE, R_ARM_FUNCDESC. * ldso/ldso/arm/resolve.S: Make _dl_linux_resolve hidden. * ldso/ldso/fdpic/dl-inlines.h (htab_delete): Declare. * libc/sysdeps/linux/arm/bits/elf-fdpic.h: New file, similar to bfin's. * libc/sysdeps/linux/arm/crtreloc.c: Likewise. * libc/sysdeps/linux/arm/find_exidx.c (__dl_addr_in_loadaddr) Define. (find_exidx_callback): Support __FDPIC__. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10rtld: Add #if defined (__FDPIC__)Christophe Lyon
Like for other FDPIC targets, add defined(__FDPIC__) where needed. * include/link.h: Include bits/elf-fdpic.h if __FDPIC__ is defined. (link_map): Use elf32_fdpic_loadaddr if __FDPIC__ is defined. (dl_phdr_info): Likewise. * ldso/include/dl-elf.h (__dl_parse_dynamic_info): Support __FDPIC__. * ldso/include/dl-hash.h (elf_resolve): Add funcdesc_ht field if __FDPIC__ is defined. * ldso/ldso/dl-hash.c (_dl_find_hash): Support __FDPIC__. * libc/misc/elf/dl-iterate-phdr.c (dl_iterate_phdr): Support __FDPIC__. Signed-off-by: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-08-10rtld: Do not protect RELRO segments when we don't use an MMU.Christophe Lyon
Without MMU, we cannot mark memory regions as read-only. * ldso/ldso/dl-elf.c (_dl_protect_relro): Do nothing if __ARCH_USE_MMU__ is defined. Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
2018-06-29ldso/arc: fix LD_DEBUG segv when printing R_ARC_NONEVineet Gupta
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2018-06-06remove unused assembler functions for armFlorian La Roche
These assembler functions seem to be unused/referenced, so we can remove them completely. Signed-off-by: Florian La Roche <Florian.LaRoche@googlemail.com>
2018-04-27libdl: first execute all destructors, then munmap libraryWaldemar Brodkorb
Fix problem which might exist since 2011. We need to execute the destructors for all dependant libraries, before munmap the shared libraries, otherwise running destructor of a dependent library might cause a segfault, trying to access an already unmapped memory. This fixes for example segfaults while running php -m with ldap module. Reported-By: Dave Flogeras <dflogeras2@gmail.com> Tested-By: Dave Flogeras <dflogeras2@gmail.com>
2018-04-27libdl: calculate the length for second parameter of munmap.Dave Flogeras
Revert 35105679b9a900d58dadd0852e679c235f8176ba and add some debug code.
2018-04-22libdl: end must be bigger than startWaldemar Brodkorb
2018-04-22libdl: remove gcc warningsWaldemar Brodkorb
2018-04-17libdl: fix problem with unmappingWaldemar Brodkorb
The munmap was still called with broken length, as sometimes start was empty. This finally solves segfaults when running php -m with ldap module activated.
2018-04-17libdl: better checking and logging for ctors/dtorsWaldemar Brodkorb
2018-04-17libdl: remove dead codeWaldemar Brodkorb
2018-04-17libdl: remove LDSO_NO_CLEANUPWaldemar Brodkorb
2018-04-17Revert "libdl: fix dlclose() issue"Waldemar Brodkorb
This reverts commit bf4c2d242f587700e3eb2ffd5721ddaf3cdbc7e5.
2018-03-15libdl: fix dlclose() issueWaldemar Brodkorb
There is a patch included in https://bugs.busybox.net/show_bug.cgi?id=6158 from 2013, which was never applied. This really fixes the php -m segfaults.
2018-03-14Revert "Revert "libdl: fix size parameter when unmap library in dlclose""Waldemar Brodkorb
This reverts commit 952bb00f0b2eb576b0bf48c4f87018429a42e28d. And adds this fix for 64 Bit systems. http://lists.busybox.net/pipermail/uclibc/2014-December/048737.html
2018-02-03bits/mman.h: consolidate header fileWaldemar Brodkorb
Sync with GNU C library and consolidate duplicate non architecture specific defines. MAP_UNINITIALIZED is only defined to 0x4000000 and used by the Linux kernel when CONFIG_MMAP_ALLOW_UNINITIALIZED is enabled. CONFIG_MMAP_ALLOW_UNINITIALIZED is only available for nommu. See Documentation/nommu-mmap.txt.
2018-01-21xtensa: fix R_XTENSA_TLSDESC_ARG handling in _dl_do_relocMax Filippov
R_XTENSA_TLSDESC_ARG is a true RELA relocation, the addend is in the relocation record itself, not in place. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
2018-01-21xtensa: fix _dl_tlsdesc_dynamicMax Filippov
There are multiple errors in _dl_tlsdesc_dynamic: - the reference C implementation should return pointer to the thread-local variable, not offset from the thread pointer, because the xtensa ABI expects TLSDESC_FN to return pointer to the TLS variable; - addx8 used for indexing into dtv has its second and third registers in wrong order, the index must be multiplied by 8, not the base; - the same addx8 uses wrong base: instead of dtv it adds the offset to the threadptr; - the return value in the fast path is calculated as td->tlsinfo.ti_offset - __builtin_thread_pointer, not what was intended; - both fast and slow paths should not subtract __builtin_thread_pointer from the result. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
2018-01-06ld.so: Rewrite elf_machine_load_address using _DYNAMIC symbolWaldemar Brodkorb
Sync with GNU C library commit: commit a68ba2f3cd3cbe32c1f31e13c20ed13487727b32 Author: Szabolcs Nagy <szabolcs.nagy@arm.com> Date: Wed Oct 18 17:26:23 2017 +0100 Fixes issues with binutils version > 2.29.1.
2017-12-31m68k: add NPTL/TLS supportWaldemar Brodkorb
Port over NPTL/TLS support from GNU C Library. In the first step only the slower syscall is used for TLS access. The uClibc-ng testsuite shows 79 errors, so their is room for bugfixes and improvements.
2017-12-28csky: add Copyright.Guo Ren
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
2017-11-19csky: port to uclibc-ngGuo Ren
Follow the steps to build c-sky uclibc linux system: 1. git clone https://github.com/c-sky/buildroot.git 2. cd buildroot 3. make qemu_csky_ck810_uclibc_defconfig 4. make Follow the buildroot/board/qemu/csky/readme.txt to run. This buildroot toolchain is pre-build, But you can rebuild the c-sky uclibc-ng alone and install it to the buildroot sysroot manually. We'll try our best to improve the uclibc-ng continuously. Signed-off-by: Guo Ren <ren_guo@c-sky.com>