Commit Graph

205 Commits

Author SHA1 Message Date
joerg
25a494ecc4 Rename __atomic_fork to __locked_fork and give it &errno as argument.
rtld and libc use different storage, so the initial version would
incorrectly report the failure reason for fork().

There is still a small race condition inside ld.elf_so as it doesn't use
thread-safe errno internally, but that's a more contained internal
issue.
2020-04-19 01:06:15 +00:00
joerg
11954c74b6 Introduce intermediate locking for fork, so that the dynamic linker is
in a consistent state. This most importantly avoids races between dlopen
and friends and fork, potentially resulting in dead locks in the child
when it itself tries to acquire locks.
2020-04-16 14:39:58 +00:00
thorpej
da570a6238 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
2020-03-04 01:21:17 +00:00
kamil
4e9bea3d5d Implement and integrate GNU Hashing function
Define Elf_Hash struct that contains ELF/SYSV and GNU hash checksum.
Implement _rtld_gnu_hash() for DT_GNU_HASH.
Adapt existing code to compute all Elf_Hash types, instead of only
the ELF/SYSV one.
Rename _rtld_elf_hash() to _rtld_sysv_hash() to match the GNU toolchain
terminology.

_rtld_gnu_hash() uses Dan Bernstein's string hash function posted eons ago
on comp.lang.c.
2020-02-29 04:23:05 +00:00
uwe
9332bf7c88 _rtld_relro - fix debug printf format for a size_t argument 2019-12-08 22:35:27 +00:00
christos
7519806b07 use __func__ (c99, c++11) instead of __FUNCTION__ 2019-10-04 01:57:53 +00:00
tnn
e91fbc780d improve error message 2019-10-03 10:34:30 +00:00
kamil
3b610a6e8d Return the ELF loader dl_phdr_info information for dl_iterate_phdr(3)
Sync the behavior of dl_iterate_phdr(3) with Linux/FreeBSD/OpenBSD.
2019-09-15 13:40:46 +00:00
christos
fb007af046 undo previous unlock/relock; it is not needed now that we added the tls model
declaration to all externs in jemalloc (suggested by joerg@)
2019-04-14 19:21:37 +00:00
christos
15018ca013 Fix c++ exceptions on arm; jemalloc calls _rtld_tls_get_addr from inside
dl_iterate_phdr, so we need to unlock and relock.
2019-04-13 03:15:25 +00:00
christos
61268f23da binutils 2.31.1 can put copy relocations in the relro segment. Delay
protecting the relro segment for the main object until copy relocations
are done.
2018-12-30 01:48:37 +00:00
christos
ba044c6310 explain why we skip objmain. 2018-12-27 18:57:43 +00:00
joerg
4312beab4f Move compatibility for pre-2.0 ELF binaries into separate file.
Early ELF binaries defined dlopen and friends in crt0.o by
using function pointers in the object handle passed from rtld.
This contract wastes space when many shared objects are allocated
and ties dynamic linker and rest of the system tightly together.
Fake the entry points in a static object and restrict them to the
platforms that had working ELF support at the time. Keep the magic and
version field used by modern crt0.o for all architectures. The checks
will be removed from crt0.o in a follow-up step.
2018-10-17 23:36:58 +00:00
joerg
f80c3669c3 Rework ifunc support to address a number of short comings:
- Move to a shared _rtld_call_ifunc for rel and rela architectures
- Architectures using rel format must patch IRELATIVE non-PLT
  relocations like RELATIVE in additition to the later ifunc handling
- Consistently record the delta to the end of the relocation group for
  non-PLT IRELATIVE relocations

Hidden ifunc is now supported on all ifunc platforms, even when using
-fno-plt. The combination of -fno-plt and relro is broken due to
incorrect GNU ld output though.
2018-04-03 21:10:27 +00:00
joerg
64156cbaf3 Like Sparc, PowerPC can use IRELATIVE relocations in non-PLT sections. 2018-03-09 20:19:11 +00:00
jakllsch
db546b38aa Wrap PowerPC #pragma goop in #if __GNUC_PREREQ__(6,0).
Our older GCC warns/errors on it.
2018-02-11 18:58:44 +00:00
mrg
1bf47496e9 update for GCC 6:
ignore -Wframe-address warnings for the ppc hack.
2018-02-07 06:17:45 +00:00
joerg
da03f1ef14 init/fini for the main program is handled by crt0.o, so ifunc handling
is skipped right now as it iterates the same list. Don't repeat that
mistake and explicitly take care of it in the dynamic linker.
2017-11-06 21:16:03 +00:00
joerg
610e531ea3 Add sparc/sparc64 support for irelative relocations. 2017-08-12 09:03:27 +00:00
joerg
e78cfb8eb8 Add IRELATIVE support for ARM, X86 and PowerPC. 2017-08-10 19:03:25 +00:00
joerg
e5678be828 Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.

If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.

Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
2017-07-11 15:21:31 +00:00
joerg
130ea7cf18 Call _rtld_debug_state before running the global initialisers, so give
gdb a chance to set break points etc.
2017-06-08 18:24:39 +00:00
chs
1c75bf6f84 tag the powerpc hackish_return_address() as __noinline. 2017-02-27 20:25:26 +00:00
christos
c8c18415f0 n dl_iterate_phdr return the path not the name. 2016-12-01 18:21:39 +00:00
christos
f9f702d000 Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@
2016-12-01 14:29:15 +00:00
christos
1abd6678f6 add missing newline in comment 2016-11-30 20:25:23 +00:00
christos
d32757ced4 Emulate the standard symbol search order in dlsym() i.e. resolve weak or
not found symbols that are in the dynamic linker list of exported symbols
from the dynamic linker itself.
2016-11-30 19:43:32 +00:00
christos
564475388a Put the name of the dynamic linker in allocated memory, so that it becomes
part of the core file link-map, so that gdb can find it.
2016-05-24 20:32:33 +00:00
yamt
b549d229c6 Fix membars around rtld internal mutex.
This fixes the most of lockups i observed with Open vSwitch
on NetBSD/amd64.  ("most of" because it still occasionally
locks up because of other problems.  see PR/49816)
2015-04-06 09:34:15 +00:00
joerg
e0985a06ba lib/49813: Release mutex on error. 2015-04-04 18:51:57 +00:00
skrll
70289840ad HPPA hack for a problem where gdb doesn't see _rtld_debug_state when
it's a single bv,n %r0(%rp) instruction.

The nullify confuses something.
2015-03-05 09:49:53 +00:00
joerg
7a1a6f1cf3 Add basic support for indirect functions. It allows providing a public
function symbol with an implementation choosen at run time.
Refactor calls to functions by address in ld.elf_so to create temporary
function descriptors on the stack, if the address is not leaked outside.

Limitations:
- no support for initialising static storage with function pointers
- no support for unnamed resolver functions

Inspired by FreeBSD's r228435 by kib@freebsd.org.
2014-08-25 20:40:52 +00:00
joerg
47875e291b Ignore LD_BIND_NOW for setuid binaries, but keep it in the environment
otherwise.
2014-03-18 16:05:34 +00:00
joerg
15f3733bef Catch up with _lwp_park change. 2014-01-31 22:46:40 +00:00
skrll
03ee7fc3bc If dlopen of the dynamic linker is requested, e.g. by rump in
rumpuser_dl_bootstrap, then return &_rtld_objself as the handle and do
not create a duplicate mapping.

The handle is mostly useless as _rtld_objself doesn't appear on
_rtld_objlist.

This fixes a problem on earm platforms where ld.elf_so (currently) has
an init_array section.  Calling this caused binaries to segv.
2013-11-20 07:18:23 +00:00
christos
193b880fad fix unused variable warnings 2013-10-19 17:19:30 +00:00
skrll
1f32502b56 Remove redundant assignment. Hasn't been needed since 1999. 2013-05-09 15:47:34 +00:00
christos
c188b90222 remove stray debugging 2013-05-09 15:39:10 +00:00
christos
3c085045e3 convert to SIMPLEQ like the rest of the queues. 2013-05-09 15:38:14 +00:00
christos
a3fedff4d1 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?
2013-05-06 19:59:29 +00:00
skrll
b49eab8ee4 Trailing whitespace 2013-05-06 08:02:20 +00:00
skrll
5aa71ff59a Disalble a debug only where it causes problems. 2013-05-06 07:58:43 +00:00
matt
d631499dcf Remove dbg for _ctype_ 2013-05-03 18:31:24 +00:00
matt
5d1d1ac212 Print out &_DYNAMIC too. 2013-05-02 21:11:18 +00:00
dsl
c8b3cc05d4 Fix the other lwp_park() to pass 0 for the 'unpark' lwp. 2012-12-16 23:00:46 +00:00
dsl
1ba527af78 You need to pass 0 (not -1) to lwp_park() if you don't also
want to do an unpark.
Clearly this code path was never tested!
Needs pullup to netbsd-6
2012-12-16 11:15:21 +00:00
riastradh
6f24a346a4 On failure in _rtld_dlcheck, call _rtld_error, not xwarnx.
Callers need not call _rtld_error themselves now.

Fixes PR lib/41760.  Should add the test case from the PR too.
2012-10-01 03:03:46 +00:00
matt
e3dfed33b6 Add .init_array/.fini_array support (conditionalized on HAVE_INITFINI_ARRAY). 2012-08-15 03:46:06 +00:00
joerg
8ae54e9304 Mark _rtld_debug_state as not to be inlined. Add an explicit instruction
barrier to prevent removal of calls to it.
2012-03-13 21:00:31 +00:00
joerg
52a4c27e3e Add _dlauxinfo helper function to provide access to the ELF auxilary
vector. This can normally be found via __ps_strings, but libc is
initialised too early when linked dynamically and doesn't have access to
it yet, so provide an alternative mechanism via ld.elf_so.
Bump libc minor.
2012-02-16 23:00:38 +00:00