Commit Graph

1034 Commits

Author SHA1 Message Date
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
joerg 6d0511e34f Expand symnum, GCC's uninitialized used tracking is too imprecise. 2017-06-20 12:41:49 +00:00
joerg fd7c99c412 Drop symbol number from default branch diagnostic, it isn't set at this
point and most likely not valid either.
2017-06-20 11:01:18 +00:00
joerg e45d4ba084 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.
2017-06-19 11:57:01 +00:00
joerg 28b12dab1c Fix indentation. 2017-06-15 23:08:46 +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
uwe 672fc2f785 PR port-macppc/47464 - Old binutils generated bogus zero-sized COPY
relocations for _SDA_BASE_ and _SDA2_BASE_ that happened to work by
accident.  They no longer happen to work when old binaries are run on
newer systems.  Explicitly ignore these bogus relocations.
2017-04-27 08:37:15 +00:00
maya cfef4500d4 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.
2017-03-10 09:13:49 +00:00
chs cf66c8999a 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.
2017-03-09 00:43:50 +00:00
chs 1c75bf6f84 tag the powerpc hackish_return_address() as __noinline. 2017-02-27 20:25:26 +00:00
christos a80110f6b6 need <sys/stat.h> 2017-01-10 21:08:48 +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 07303da5f3 revert, I'll fix libc instead. 2016-10-07 19:10:03 +00:00
christos 94e616077b Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare(). 2016-10-07 17:12:59 +00:00
martin fee8b601f9 Despite the 10 in the name, the OLO10 relocation targets a 13 bit field,
the offset (O) providing the additional data.
2016-08-29 16:00:10 +00:00
martin 115160e654 Fix a few bounds and instruction sequences generated in the PLT; exercised
by ASLR and verified to work with the aslr fixed random debug sysctls.
2016-06-20 08:12:25 +00:00
christos 4910b5ce72 Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)
2016-06-16 11:34:13 +00:00
christos 3ee1ef9906 Turn off GNU_RELRO for now. 2016-06-15 12:08:47 +00:00
christos 0e6265fc35 Add support for GNU RELRO headers from Matthias Weckbecker. 2016-06-14 13:06:41 +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
joerg 6e49b77769 obj->phdr must be the absolute address, not the virtual offset from the
main binary. Historically, this has been the same. For PIE though,
relocbase can be pretty much anywhere. Fixes PR toolchain/51159.
2016-05-22 19:28:39 +00:00
skrll 42fe483061 Remove duplicated __RCSIDs I added years ago - I blame CVS.
Spotted by Miod Vallat
2016-04-14 20:17:07 +00:00
christos 80c3d4eb2a - Print a warning for text relocations
- Don't remap the text segment executable while relocating
2016-04-12 19:10:48 +00:00
christos 80fa2ce1a5 where is already void * 2016-02-20 15:20:23 +00:00
macallan 3709f36323 make debug code compile again
from christos
2016-02-19 22:09:09 +00:00
skrll 19b4c45621 Actually, descsz should not contain the padding. The note still needs to
be padded out.
2016-02-09 10:20:03 +00:00
skrll a5b645efc7 Fix .note.netbsd.march by ensuring correct padding 2016-02-08 11:59:39 +00:00
christos a21e664447 we don't need <sys/mbuf.h> 2016-01-24 01:56:04 +00:00
christos ffeb8dbf4e Define _KERNTYPES for things that need it. 2016-01-23 21:22:45 +00:00
joerg 3490cc6261 Add an explicit note about the search path used by dlopen(3). 2015-07-03 10:19:29 +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
matt 32b939b05c Update RISCV to use the ELF relocations and new ABI. 2015-03-27 23:14:53 +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
chs a60c43758e fix powerpc TLS problems by removing the hacks for PPC EABI.
the kernel no longer treats R2 specially and its use as
the TLS register is now handled entirely in userland.
2014-12-14 23:49:17 +00:00
martin 2782e828f4 Avoid use after free, reported by the coverity scanner. 2014-10-30 07:53:41 +00:00
matt 463829e46a RISC-V support. 2014-09-19 17:43:33 +00:00
matt 6cf6fe02a9 New files for Userland support of UCB RISC-V (both 32-bit and 64-bit) 2014-09-19 17:36:24 +00:00
matt 27620987b8 New files for OR1K support 2014-09-03 19:34:25 +00:00
matt 00cc626e2f OR1K support 2014-09-03 19:31:32 +00:00
joerg e4cd9bc4a2 Remove (now duplicated) target computation. 2014-08-31 20:06:22 +00:00
christos 94e1a89978 remove unused define 2014-08-27 04:07:04 +00:00
joerg c1a71e8076 Restore parenthesis to cast in the right order. 2014-08-26 21:20:05 +00:00
joerg b88be9f652 Replace casts in the inline version of _rtld_call_function_void of
_rtld_call_function_addr with ifdef on RTLD_LOADER.
2014-08-26 19:49:33 +00:00
christos db25848c17 fix set but not used. 2014-08-26 15:06:50 +00:00
joerg 5d06599748 Go back to skipping init/fini handling for ldd, makes problems for 32bit
compat on LP64.
2014-08-26 12:14:14 +00:00
christos d9972a4666 Introduce a cast to fix the build for Elf32 on _LP64. 2014-08-26 07:54:27 +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 f5cd842d49 Outdated, kill. 2014-08-23 19:18:41 +00:00
joerg 6a83645936 Typo. 2014-08-23 18:05:33 +00:00
matt 5b3354816c Add proper registers for register counts. 2014-08-17 16:57:37 +00:00
matt d32bdc3217 add a missing register prefix. 2014-08-17 16:14:19 +00:00