Commit Graph

988 Commits

Author SHA1 Message Date
skrll
69e8dca2e5 Adapt https://svnweb.freebsd.org/base?view=revision&revision=342113 to
NetBSD.

This brings us resolving for dynamically loaded libraries and makes
tests/libexec/ld.elf_so/t_thread_local_dtor pass.

With suggestions from joerg@
2019-01-18 11:59:03 +00:00
christos
d17b8a0ea7 print the program name when we don't find a library.
XXX: really most _rtld_error() should do that, and most do.
2019-01-12 18:58:10 +00:00
joerg
06c9aa1116 When loading a non-PIE main binary, the virtual address must match.
Use MAP_TRYFIXED and verify that the result matches the expectation.
2019-01-06 19:44:54 +00:00
joerg
08e505b543 MAP_ALIGNED has existed for years, just assume it exists. 2019-01-04 19:54:56 +00:00
martin
e4d02a93c7 Add support for DT_RUNPATH - it is just the same as we always have treated
DT_RPATH.  Approved by core.
2018-12-30 11:55:15 +00:00
christos
d30b19ef3d - fix wrong reloc name in assert
- fix uninitialized
2018-12-30 03:23:46 +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
2c62c57fa6 initfini array support for everyone. 2018-12-27 18:58:14 +00:00
christos
ba044c6310 explain why we skip objmain. 2018-12-27 18:57:43 +00:00
skrll
66b7511afb Fix typos 2018-12-01 13:01:57 +00:00
joerg
335f313f07 Now that lib/csu no longer uses the object handle, drop the magic and
version field from the internal object. It is kept in the legacy version
of the main object.
2018-11-26 17:40:26 +00:00
skrll
c7af211bee Fix RTLD_DEBUG_RELOC build 2018-11-23 11:26:05 +00:00
skrll
0d71550e67 Trailing whitespace 2018-11-23 10:59:20 +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
jakllsch
3c05430e55 Revise previous to not deadlock. 2018-09-20 19:02:22 +00:00
jakllsch
df54aa978e Improve support for R_AARCH64_TLSDESC relocations.
In large part from FreeBSD.
2018-09-20 18:41:05 +00:00
joerg
da0b29937f Apply relocbase for tlsinit of the executable itself. Fixes PIE where
relocbase typically is not zero.

PR bin/53465
2018-07-24 13:48:48 +00:00
christos
8de0d28182 Initialize new_value to account for bogus return from the function. 2018-07-16 00:29:37 +00:00
christos
64715b9aa8 We can't build those three with MKSANITIZER, they are used too early. 2018-06-09 22:41:55 +00:00
christos
b5fd6cb2a8 rename flag to the official name. 2018-05-24 17:05:54 +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
2d65afd272 Move the complex logic for dynamically writing branches from ld.elf_so
into a header for reuse in crt0.o for static ifunc support. Change the
existing logic for sparc64 to use the Bicc variant of ba,a as it allows
+-8MB displacement compared to the BPcc variant's +-1MB. Teach the sparc
variant the same trick for using ba,a and not sethi+jmp when possible.
2018-03-29 13:23:39 +00:00
joerg
033ffc4d89 Don't skip PLT processing for the main binary. It can still contain
ifunc references.
2018-03-25 18:56:01 +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
skrll
e958e889a2 Various fixes / changes from Ryo Shimizu / Toru Nishimura to make this
work.

_rtld_call_ifunc copied from other rela platforms by me - not tested in
any way.
2018-02-04 21:49:51 +00:00
christos
381da60e92 don't forget to eat the high bits. 2018-01-19 23:17:41 +00:00
joerg
e5e34a6c86 Since GNU ld doesn't honor the PLT entry reservation, also compensate
for JMP_IREL relocations at the start of the PLT.
2017-12-25 17:00:15 +00:00
maya
0a4e3118cb Fix typo in comment
from freebsd
2017-12-25 05:29:27 +00:00
maya
6f158d565c fix debug build 2017-12-24 01:22:16 +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
nisimura
dfab1def86 explain AARCH64 PLT design 2017-08-28 06:59:25 +00:00
nisimura
695ffc63ca - avoid caddr_t. use Elf_Addr instead.
- iron out rdbg() errors.
2017-08-23 09:17:48 +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
493a7561e4 If a DF_1_NODELETE DSO has been removed from the DAG list, it still
needs to be able to resolve relocations against itself. As such, search
the referencing object explicitly last, if it hasn't been searched
before.
2017-08-09 18:44:32 +00:00
martin
806d1922a8 Fix thinko in previous: even if the address is an unsigned value and we
have verified the range before, we still need to mask the bit pattern
to the target instruction field.
2017-07-24 08:08:34 +00:00
martin
41cf8822e9 Simplify and fix the offset calculation when doing a %pc relative
branch from the PLT slot to the target.
2017-07-23 14:37:51 +00:00
joerg
bde7a58ae6 Fix two bugs related to promotion of DSO TLS blocks into the static
thread allocation:
(1) Set the DTV vector up whenever an offset into the static allocation
is assigned, even if the block itself is not initialized. This has been
seen in libstdc++.
(2) Do not free a DTV block if it is part of the static thread
allocation.
2017-07-13 14:10:38 +00:00
christos
97c79d531d rename the macro 2017-07-12 17:55:24 +00:00
christos
15e7a34b21 make this compile with debug again (symnum uninitialized) 2017-07-12 17:54:23 +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
88b397335b Drop comments about symbol exporting, the relevant code is gone. 2017-07-09 17:57:59 +00:00
wiz
01869ca4d2 Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
joerg
a7f7db4a1a Remove old assert that only two segments exist. The rest of the code has
been changed to cope with more and at least Go actively creates them.
Adjust the mapping size computation to use the maximum and not depend on
PT_LOAD segments to be in order.
2017-06-23 15:29:21 +00:00
joerg
3870ab1fa7 Replace last use of r_type. 2017-06-21 12:34:01 +00:00
joerg
152a0d21c4 Add back symnum, fix debug print. 2017-06-20 15:02:54 +00:00
joerg
ddeaaf811f Add last_symnum, move up def and defobj. 2017-06-20 13:45:20 +00:00
joerg
d5127e3ef7 Fix C&P bug. Deal with more MIPS hacks overriding def. 2017-06-20 13:24:03 +00:00