Commit Graph

112 Commits

Author SHA1 Message Date
Szabolcs Nagy c9783e4d32 treat STB_WEAK and STB_GNU_UNIQUE like STB_GLOBAL in find_sym
A weak symbol definition is not special during dynamic linking, so
don't let a strong definition in a later module override it.
(glibc dynamic linker allows overriding weak definitions if
LD_DYNAMIC_WEAK is set, musl does not.)

STB_GNU_UNIQUE means that the symbol is global, even if it is in a
module that's loaded with RTLD_LOCAL, and all references resolve to
the same definition. This semantics is only relevant for c++ plugin
systems and even there it's often not what the user wants (so it can
be turned off in g++ by -fno-gnu-unique when the c++ shared lib is
compiled). In musl just treat it like STB_GLOBAL.
2017-03-11 19:10:57 -05:00
rofl0r 1f53e7d00c fix crashes in x32 __tls_get_addr
x32 has another gratuitous difference to all other archs:
it passes an array of 64bit values to __tls_get_addr().
usually it is an array of size_t.
2017-01-13 10:47:08 +00:00
Rich Felker 27b3fd68f6 fix crash from corrupted tls module list after failed dlopen
commit d56460c939 introduced this
regression as part of splitting the tls module list out of the dso
list. the new code added to dlopen's failure path to undo the changes
adding the partially-loaded libraries reset the tls_tail pointer
correctly, but did not clear its link to the next list entry. thus, at
least until the next successful dlopen, the list was not terminated
but ended with an invalid next pointer, which __copy_tls attempted to
follow when a new thread was created.

patch by Mikael Vidstedt.
2017-01-04 22:54:06 -05:00
Bobby Bingham 54482898ab treat null vdso base same as missing
On s390x, the kernel provides AT_SYSINFO_EHDR, but sets it to zero, if the
program being run does not have a program interpreter.  This causes
problems when running the dynamic linker directly.
2016-11-11 12:58:27 -05:00
Rich Felker b418ea1b66 generalize ELF hash table types not to assume 32-bit entries
alpha and s390x gratuitously use 64-bit entries (wasting 2x space and
cache utilization) despite the values always being 32-bit.

based on patch by Bobby Bingham, with changes suggested by Alexander
Monakov to use the public Elf_Symndx type from link.h (and make it
properly variable by arch) rather than adding new internal
infrastructure for handling the type.
2016-11-11 12:46:06 -05:00
Szabolcs Nagy 5ffe515ca4 fix ldso reserved library name handling
If a DT_NEEDED entry was the prefix of a reserved library name
(up to the first dot) then it was incorrectly treated as a libc
reserved name.

e.g. libp.so dependency was not loaded as it matched libpthread
reserved name.
2016-11-07 12:00:32 -05:00
Szabolcs Nagy 86e8cc0fd4 fix accidental global static pointer in ldso
this was harmless as load_library is not called concurrently,
but it used one word of bss.
2016-11-07 11:59:58 -05:00
Rich Felker 71392a91c3 generalize mips-specific reloc code not to hard-code sym/type encoding
this change is made in preparation for adding the mips64 port, which
needs a 64-bit (and mips64-specific) form of the R_INFO macro, but
it's a better abstraction anyway.

based on part of the mips64 port patch by Mahesh Bodapati and Jaydeep
Patil of Imagination Technologies.
2016-03-06 17:25:52 +00:00
Rich Felker 2d0290debf fix regression in SH/FDPIC dynamic linker
the dynamic linker was found to hang when used as the PT_INTERP, but
not when invoked as a command. the mechanism of this failure was not
determined, but the cause is clear:

commit 5552ce5200 removed the SHARED
macro, but arch/sh/crt_arch.h is still using it to choose the right
form of the crt/ldso entry point code. moving the forced definition
from rcrt1.c to dlstart.c restores the old behavior. eventually the
logic should be changed to fully remove the SHARED macro or at least
rename it to something more reasonable.
2016-02-18 04:13:05 +00:00
Felix Fietkau c18d05f0e8 ldso: fix GDB dynamic linker info on MIPS
GDB is looking for a pointer to the ldso debug info in the data of the
..rld_map section.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2016-01-30 20:55:22 -05:00
Rich Felker 140ad50cbf fix regression in dynamic-linked tls when both main app & libs have tls
commit d56460c939 introduced this bug by
setting up the tls module chain incorrectly when the main app has tls.
the singly-linked list head pointer was setup correctly, but the tail
pointer was not, so the first attempt to append to the list (for a
shared library with tls) would treat the list as empty and effectively
removed the main app from the list. this left all tls module id
numbers off-by-one.

this bug did not appear in any released versions.
2016-01-30 14:34:45 -05:00
Rich Felker 5552ce5200 move dynamic linker to its own top-level directory, ldso
this eliminates the last need for the SHARED macro to control how
files in the src tree are compiled. the same code is used for both
libc.a and libc.so, with additional code for the dynamic linker (from
the new ldso tree) being added to libc.so but not libc.a. separate .o
and .lo object files still exist for the src tree, but the only
difference is that the .lo files are built as PIC.

in the future, if/when we add dlopen support for static-linked
programs, much of the code in dynlink.c may be moved back into the src
tree, but properly factored into separate source files. in that case,
the code in the ldso tree will be reduced to just the dynamic linker
entry point, self-relocation, and loading of libraries needed by the
main application.
2016-01-25 19:29:55 -05:00