Commit Graph

637 Commits

Author SHA1 Message Date
Ed Maste
688fd61ae8 Use canonical __PIC__ flag
It is automatically set when -fPIC is passed to the compiler.

Reviewed by:	dim, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D1179
2014-11-21 02:05:48 +00:00
Simon J. Gerraty
9268022b74 Merge from head@274682 2014-11-19 01:07:58 +00:00
Ed Maste
54ac10780f Always return pathname in dl_iterate_phdr's dlpi_name, as Linux does
Linux LD_ITERATE_PHDR(3):
    The dlpi_name field is a null-terminated string giving the
    pathname from which the shared object was loaded.

That functionality is much more useful than returning just the short
name.

Approved by:	kan
Sponsored by:	The FreeBSD Foundation
2014-10-09 20:39:18 +00:00
Andrew Turner
6d4766c1b8 Remove MK_ARM_EABI, the armeb issues have been fixed. The code to support
the oabi is still in the tree, but it is expected this will be removed
as developers work on surrounding code.

With this commit the ARM EABI is the only supported supported ABI by
FreeBSD on ARMa 32-bit processors.

X-MFC after:	never
Relnotes:	yes
Differential Revision: https://reviews.freebsd.org/D876
2014-10-01 08:26:51 +00:00
Konstantin Belousov
d3b06cf2be Document the whole settings needed to build a debug version of rtld.
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2014-08-29 10:44:58 +00:00
Konstantin Belousov
74b0daf4f9 Optimize r270798, only do the second pass over non-plt relocations
when the first pass found IFUNCs.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2014-08-29 10:43:56 +00:00
Konstantin Belousov
14c3564759 IFUNC symbol type shall be processed for non-PLT relocations,
e.g. when a global variable is initialized with a pointer to ifunc.
Add symbol type check and call resolver for STT_GNU_IFUNC symbol types
when processing non-PLT relocations, but only after non-IFUNC
relocations are done.  The two-phase proceessing is required since
resolvers may reference other symbols, which must be ready to use when
resolver calls are done.

Restructure reloc_non_plt() on x86 to call find_symdef() and handle
IFUNC in single place.

For non-x86 reloc_non_plt(), check for call for IFUNC relocation and
do nothing, to avoid processing relocs twice.

PR:	193048
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2014-08-29 09:29:10 +00:00
Konstantin Belousov
e404dc33e2 Remove stray newline. 2014-08-27 00:48:09 +00:00
Enji Cooper
35829c84f1 Fix "make checkdpadd" by "spoofing" DPADD
Approved by: jmmv (mentor)
Phabric: D631
PR: 192769
2014-08-26 09:01:11 +00:00
Pedro F. Giffuni
0fa46a4231 Always check the limits of array index variables before using them.
Obtained from:	DragonFlyBSD
MFC after:	1 week
2014-08-21 02:40:33 +00:00
Bryan Drewery
5608fd23c2 Revert r267233 for now. PIE support needs to be reworked.
1. 50+% of NO_PIE use is fixed by adding -fPIC to INTERNALLIB and other
   build-only utility libraries.
2. Another 40% is fixed by generating _pic.a variants of various libraries.
3. Some of the NO_PIE use is a bit absurd as it is disabling PIE (and ASLR)
   where it never would work anyhow, such as csu or loader. This suggests
   there may be better ways of adding support to the tree. Many of these
   cases can be fixed such that -fPIE will work but there is really no
   reason to have it in those cases.
4. Some of the uses are working around hacks done to some Makefiles that are
   really building libraries but have been using bsd.prog.mk because the code
   is cleaner. Had they been using bsd.lib.mk then NO_PIE would not have
   been needed.

We likely do want to enable PIE by default (opt-out) for non-tree consumers
(such as ports). For in-tree though we probably want to only enable PIE
(opt-in) for common attack targets such as remote service daemons and setuid
utilities. This is also a great performance compromise since ASLR is expected
to reduce performance. As such it does not make sense to enable it in all
utilities such as ls(1) that have little benefit to having it enabled.

Reported by:	kib
2014-08-19 15:04:32 +00:00
Simon J. Gerraty
ee7b0571c2 Merge head from 7/28 2014-08-19 06:50:54 +00:00
Enji Cooper
fd5c99b51e Similar to r269506, fix LIBDIR to not duplicate TESTSDIR
Phabric: D536
Reviewed by: jmmv
Approved by: jmmv (mentor)
Sponsored by: EMC / Isilon Storage Division
2014-08-05 18:09:39 +00:00
Enji Cooper
522da0b0ad Remove unnecessary .PATH directive
All of the sources for the tests are contained in the
current working directory and the subdirectories

Phabric: D537
Reviewed by: jmmv
Approved by: jmmv (mentor)
Sponsored by: EMC / Isilon Storage Division
2014-08-05 18:05:31 +00:00
Enji Cooper
2db8752cef Fix BINDIR to not duplicate "${TESTSDIR}
This should fix 'make release' with MK_TESTS != no

Phabric: D525 (part of a larger patch)

Reviewed by: jmmv
Approved by: jmmv (co-mentor)
2014-08-04 05:50:21 +00:00
Enji Cooper
07014efe94 Move a -L argument from LDADD to LDFLAGS
Phabric: D525 (part of a larger patch)

Reviewed by: jmmv
Approved by: jmmv (co-mentor)
2014-08-04 05:49:13 +00:00
Enji Cooper
35e8923e7e Fix a -Wsecurity warning with clang
Phabric: D525 (part of a larger patch)

Reviewed by: jmmv
Approved by: jmmv (co-mentor)
2014-08-04 05:46:10 +00:00
Enji Cooper
1a49685c28 Remove hardcoded path to TESTSDIR (Makefile, ld_library_pathfds.c) at
build time by using atf_tc_get_config_var(tc, "srcdir"))

This will allow end-users to move the binaries to different locations
after they've been built without having to rebuild the binaries with
the new paths

Phabric: D525 (part of a larger patch)

Reviewed by: jmmv
Approved by: jmmv (co-mentor)
2014-08-04 05:45:09 +00:00
Julio Merino
2504a6af6b libpythagoras needs libm.
This fixes "make tinderbox" failures on various architectures when
WITH_TESTS=yes is enabled.  Problem introduced in r267679.
2014-07-16 16:42:58 +00:00
Marcel Moolenaar
e7d939bda2 Remove ia64.
This includes:
o   All directories named *ia64*
o   All files named *ia64*
o   All ia64-specific code guarded by __ia64__
o   All ia64-specific makefile logic
o   Mention of ia64 in comments and documentation

This excludes:
o   Everything under contrib/
o   Everything under crypto/
o   sys/xen/interface
o   sys/sys/elf_common.h

Discussed at: BSDcan
2014-07-07 00:27:09 +00:00
Andrew Turner
0685d955d6 Align the stack in _rtld_bind_start. Normally this is called with the
correct stack alignment, however when we have a leaf function that uses
thread local storage it calls __aeabi_read_tp to get the thread pointer.
Neither GCC or clang see this as a function call so will align the stack
to a 4-byte boundary. This may be a problem as _rtld_bind expects to be
on an 8-byte boundary.

The solution is to store a copy of the stack pointer and force the
alignment before calling _rtld_bind.

This fixes a problem with armeb where applications would crash in odd ways.
It should also remove the need for a local patch to clang to force the
stack alignment to an 8-byte boundary, even for leaf functions. Further
testing will be needed before reverting this local change to clang as we
may rely on it in other places.

Reviewed by:	jmg@
2014-07-06 10:24:06 +00:00
Marcel Moolenaar
97ef768914 Fix r264346 for ia64. We need to allocate memory for the function
descriptors in order to relocate RTLD itself. To allocate memory,
we need the pagesizes array initialized, but that happens after
RTLD is relocated. This ordering is important for amd64, but it's
opposite of what ia64 needs. Handle this conflict with the define
called RTLD_INIT_PAGESIZES_EARLY. When defined, obtain the page
sizes before relocating rtld, otherwise do it after.
2014-07-02 22:04:12 +00:00
Joel Dahl
df2d82e003 mdoc: remove superfluous paragraph macros. 2014-06-23 18:40:21 +00:00
Jonathan Anderson
6b22f423cf Test RTLD's new LD_LIBRARY_PATH_FDS variable.
Test LD_LIBRARY_PATH_FDS by linking a binary that requires a shared
library that isn't in any of the usual search paths.  Ensure this fails
when we don't supply LD_LIBRARY_PATH_FDS or we pass invalid information
in it.  Ensure it works when we pass the correct directory in various
places in the variable.

Approved by:	rwatson (mentor)
MFC after:	3 weeks
Sponsored by:	DARPA/AFRL
2014-06-20 17:14:59 +00:00
Jonathan Anderson
02d3b38e0a Add the LD_LIBRARY_PATH_FDS environmental variable.
This variable allows the loading of shared libraries via directory descriptors
rather than via library paths.  If LD_LIBRARY_PATH_FDS=3:4:12, the directories
represented by file descriptors 3, 4 and 12 will searched for shared libraries
before the normal path-based mechanisms are used.  This allows us to execute
unprivileged binaries from within a Capsicum sandbox even if they require
shared libraries.

Approved by:	rwatson (mentor)
Reviewed by:	kib
MFC after:	3 weeks
Sponsored by:	DARPA/AFRL
2014-06-20 17:08:32 +00:00
Bryan Drewery
864c53ead8 In preparation for ASLR [1] support add WITH_PIE to support building with -fPIE.
This is currently an opt-in build flag. Once ASLR support is ready and stable
it should changed to opt-out and be enabled by default along with ASLR.

Each application Makefile uses opt-out to ensure that ASLR will be enabled by
default in new directories when the system is compiled with PIE/ASLR. [2]

Mark known build failures as NO_PIE for now.

The only known runtime failure was rtld.

[1] http://www.bsdcan.org/2014/schedule/events/452.en.html
Submitted by:		Shawn Webb <lattera@gmail.com>
Discussed between:	des@ and Shawn Webb [2]
2014-06-08 17:29:31 +00:00
Konstantin Belousov
1c70d00733 Right now, the rtld prefork hook locks the rtld bind lock in the read
mode.  This allows the binder to be functional in the child after the
fork (assuming no lazy loading of a filter is needed), but other rtld
services which require write lock on rtld_bind_lock cause deadlock, if
called by child.

Change the _rtld_atfork() to lock the bind lock in write mode, making
the rtld fully functional after the fork.

Pre-resolve the symbols which are called by the libthr' fork()
interposer, since dynamic resolution causes deadlock due to the
rtld_bind_lock already owned in the write mode.

Reported and tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2014-05-24 10:23:06 +00:00
Konstantin Belousov
490c68de98 Fix LD_LIBMAP.
The r232862 passed the pointer to end of string to lmc_parse() and free().

Submitted by:	Wolfgang Jenkner <wjenkner@inode.at>
MFC after:	1 week
2014-05-18 17:14:08 +00:00
Simon J. Gerraty
cc3f4b9965 Merge from head 2014-05-08 23:54:15 +00:00
Mark Johnston
7a61fc5a8e - Export the function added in r265456 rather than the non-existent
_rtld_debug_postinit(). [1]
- Use __compiler_membar() instead of inline asm in _r_debug_state() and
  _r_debug_postinit(). [2]

Pointy hat to:	markj [1]
Reported by:	attilio [2]
Discussed with:	kib
X-MFC-With:	r265456
2014-05-07 17:21:22 +00:00
Mark Johnston
a8509eb20e Add a postinit debugger hook to rtld. This will be used by dtrace(1) to halt
the victim process before its entry point is called, at which point probes
and DOF data are registered with the kernel. The r_debug_state hook cannot
be used for this purpose, as it is called before the program's init routines
are invoked and in particular before DOF data is registered (via drti.o).

Reviewed by:	kib
MFC after:	2 weeks
2014-05-06 18:07:58 +00:00
Warner Losh
c6063d0da8 Use src.opts.mk in preference to bsd.own.mk except where we need stuff
from the latter.
2014-05-06 04:22:01 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Konstantin Belousov
8cc5663495 Add dwarf annotations to the amd64 _rtld_bind_start to allow debuggers
to unwind around the calls from PLT to binder.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2014-04-14 22:44:50 +00:00
Alan Cox
ea8577c712 Before calling mmap() on a shared library's text and data sections, rtld
first calls mmap() with the arguments PROT_NONE and MAP_ANON to reserve a
single, contiguous range of virtual addresses for the entire shared library.
Later, rtld calls mmap() with the the shared library's file descriptor
and the argument MAP_FIXED to place the text and data sections within the
reserved range.  The rationale for mapping shared libraries in this way is
explained in the commit message for Revision 190885.  However, this approach
does have an unintended, negative consequence.  Since the first call to
mmap() specifies MAP_ANON and not the shared library's file descriptor, the
kernel has no idea what alignment the vm object backing the file prefers.
As a result, the reserved range's alignment is unlikely to be the same as
the vm object's, and so mapping with superpages becomes impossible.  To
address this problem, this revision adds the argument MAP_ALIGNED_SUPER to
the first call to mmap() if the text section is larger than the smallest
superpage size.

To determine if the text section is larger than the smallest superpage
size, rtld must always fetch the page size information.  As a result, the
private code for fetching the base page size in rtld's builtin malloc is
redundant.  Eliminate it.  Requested by: kib

Tested by:	zbb (on arm)
Reviewed by:	kib (an earlier version)
Discussed with:	jhb
2014-04-11 16:55:25 +00:00
David Xu
eab68f795a Increase alignment to size of pointer if the alignment is too small.
Some modules do not align data at least to size of pointer, they uses a
smaller alignment, but our pointer should be aligned to its native
boundary, otherwise on some platforms, hardware alignment checking
will cause bus error.
2014-02-22 11:06:48 +00:00
David Xu
209782e06f malloc_aligned() may not leave enough space for pointer to allocated memory,
saving the pointer will overwrite bytes belongs to another memory block
unexpectly, to fix the problem, use (allocated address + sizeof(void *)) as
initial value, and slip to next aligned address, so maximum extra bytes is
sizeof(void *) + align - 1.

Tested by: Andre Albsmeier < mail at ma17 dot ata dot myota dot orgndre >
2014-02-21 03:36:16 +00:00
Christian Brueffer
5efaea4cc6 Remove the 3rd clause ("advertising clause") of the BSD license as
permitted by the University of Berkeley on July 22, 1999.

Reviewed by:	imp
MFC after:	1 week
2014-02-17 22:27:32 +00:00
Ed Schouten
37656b872b Replace LIBGCC by LIBCOMPILER_RT.
We now use libcompiler_rt on all platforms now. Instead of referring
directly to -lgcc and LIBGCC, use -lcompiler_rt and LIBCOMPILER_RT.
2014-01-18 14:22:56 +00:00
Konstantin Belousov
6cd2b1dc63 Cast Elf_Addr to void * to match the free_aligned() argument type.
Found by:	gcc
Sponsored by:	The FreeBSD Foundation
MFC after:	6 days
2013-12-07 15:49:16 +00:00
Konstantin Belousov
16a93df7eb For variant II static TLS, properly align tls segments. Pre-calculate
the max required alignment for the static tls segments, and honor it
when carving the pieces for next module, from the static space.  Use
aligned allocator to get properly-aligned dynamic blocks.

Reported by:	dt71@gmx.com
Reviewed by:	kan
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2013-12-06 21:39:45 +00:00
Konstantin Belousov
dfe296c43a Build an allocator for the aligned memory on top of the rtld-private
malloc.

Reviewed by:	kan
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2013-12-06 21:30:31 +00:00
Mark Johnston
7a89ddd40f Include rtld itself when iterating over loaded ELF objects in
dl_iterate_phdr(3).

Reviewed by:	kib
2013-11-07 20:45:50 +00:00
Simon J. Gerraty
3caf0790a8 Merge head@256284 2013-10-13 02:35:19 +00:00
Konstantin Belousov
3cf98c19e8 Implement support for the interpose dso flag.
Requested by:	bf
Reviewed by:	kan
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Approved by:	re (glebius)
2013-10-07 08:19:30 +00:00
Ed Maste
d24aca1b00 Populate .rld_map on MIPS for debuggers
On MIPS the .dynamic section is read-only, so the pointer to rtld
information for debuggers cannot be stored there (in DT_DEBUG).
Instead, a special section .rld_map is used.

Sponsored by:	DARPA, AFRL
Approved by:	re (delphij)
2013-10-02 02:32:58 +00:00
Dag-Erling Smørgrav
8182b3bee1 Make the directory mapping functionality, which was previously only
available in 32-bit compatibility mode, unconditional.

Overhaul the man page, which had evolved more by accretion than by design.

Approved by:	re (gjb)
MFC after:	3 weeks
2013-09-21 21:03:52 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Andriy Gapon
a29cc9a34b Revert r253748,253749
This WIP should not have been committed yet.

Pointyhat to:	avg
2013-07-28 18:44:17 +00:00
Andriy Gapon
c722ec3a51 remove needless inclusion of machine/cpu.h in userland
MFC after:	21 days
2013-07-28 18:35:43 +00:00
Konstantin Belousov
3c9cb0c6c9 Properly terminate the result string for intermediate results, to
allow the final strcpy() to start at the intended place.

Reported and tested by:	pgj
Pointy hat to:	kib
MFC after:	3 days
2013-04-29 21:12:25 +00:00
Konstantin Belousov
32e1d8010b The origin_subst_one() function limits the length of the string to
PATH_MAX after the token substitution.  This is wrong, because
origin_subst_one() performs the substitution on the whole rpath and
similar strings, which contain several pathes separated by colon.  As
result, long (but correct) rpath consisting of many path elements is
rejected by the function.

Correct the problem by rewriting the origin_subst_one() to perform two
passes, first pass to calculate the number of substitutions to be
performed, and second pass to generate the resulting string.  Second
pass allocates the memory for the result based on the count from the
first pass, without enforcing a limit.

Reported and tested by:	pgj
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2013-04-15 20:06:56 +00:00
Simon J. Gerraty
69e6d7b75e sync from head 2013-04-12 20:48:55 +00:00
Tijl Coosemans
157895135a Map libraries linked with -Ttext-segment=base_addr at base_addr.
Normal libraries have base address 0 and are unaffected by this change.

PR:		176216
Submitted by:	Damjan Jovanovic <damjan.jov@gmail.com>
Reviewed by:	kib
MFC after:	1 week
2013-02-27 09:34:09 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
Nathan Whitehorn
746ae9df1f Avoid use of register variables, which some compilers (e.g. clang)
don't like. It makes the code a little clearer as well.

MFC after:	1 week
2013-02-08 17:44:44 +00:00
David E. O'Brien
d9a447559b Sync with HEAD. 2013-02-08 16:10:16 +00:00
Andrew Turner
de2be60c4f When building for ARM EABI link against libgcc for the __aeabi_* functions. 2013-01-19 04:34:33 +00:00
Pawel Jakub Dawidek
456b64c443 Use absolute path for /usr/libexec/ld-elf.so.1 symlink.
Requested by:	kan, kib

Use -h flags for chflags, so we won't remove 'schg' flag from system's
/libexec/ld-elf.so.1.

MFC after:	2 weeks
2012-12-04 14:36:01 +00:00
Pawel Jakub Dawidek
f31c1e3fd3 Do not change entire BINDIR, it might be needed later, just change
symlink target.

MFC after:	2 weeks
2012-12-04 12:51:33 +00:00
Pawel Jakub Dawidek
dee6306480 Change /usr/libexec/ld-elf.so.1 to point at ../../libexec/ld-elf.so.1
instead of /libexec/ld-elf.so.1. Below in the Makefile we execute
'chflags noschg ${DESTDIR}/usr/libexec/ld-elf.so.1', which follows
symlink and removes 'schg' flag from system's /libexec/ld-elf.so.1
instead of the one in DESTDIR. It is also more friendly to use
replative paths in symlink in case of jail/chroot environments.

Obtained from:	WHEEL Systems
MFC after:	2 weeks
2012-12-04 12:39:26 +00:00
Jilles Tjoelker
e194282943 rtld: Fix fd leak with parallel dlopen and fork/exec.
Rtld did not set FD_CLOEXEC on its internal file descriptors; therefore,
such a file descriptor may be passed to a process created by another thread
running in parallel to dlopen() or fdlopen().

No other threads are expected to be running during parsing of the hints
and libmap files but the file descriptors need not be passed to child
processes so add O_CLOEXEC there as well.

This change will break fdlopen() (as used by OpenPAM) on kernels without
F_DUPFD_CLOEXEC (added in July). Note that running new userland on old
kernels is not supported.

Reviewed by:	kib
2012-11-04 21:42:24 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Konstantin Belousov
1a4f1f697c Do not reference z_nodeflib for !objgiven case, thus fixing LD_PRELOAD
for a non-absolute path.

PR:	bin/171604
MFC after:	3 days
2012-09-19 05:11:25 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Alexander Kabaev
5763679b4d Do not call process_nodelete with NULL object pointer.
The place where the function is called can be reached if object loading
and relocation fails too, in which case obj pointer will be NULL. Do not
call process_nodelete then, or crash will follow.

Pointy hat to: kan
2012-08-20 23:43:03 +00:00
Oleksandr Tymoshenko
c9e95645f6 Merging of projects/armv6, part 2
Handle TLS for ARMv6 and ARMv7
2012-08-15 03:07:41 +00:00
Alexander Kabaev
207eee57b1 Pospone the DF_1_NODELETE processing until object DAG is fully loaded.
Trying to up the reference from the load loop risks missing dependencies
that have not been loaded yet.

MFC afer: 1 week
Reported by: nox
Reviewd by: kib
2012-08-14 13:28:30 +00:00
Andrew Turner
782b05f96b Ensure we align the stack to 8 bytes in rtld.
This is not strictly required with the current ABI but will be when we
switch to the ARM EABI. The aapcs requires the stack to be 4 byte aligned
at all times and 8 byte aligned when calling a public subroutine where the
current ABI only requires sp to be a multiple of 4.
2012-08-04 05:30:20 +00:00
Alexander Kabaev
d958a71be2 Parse notes only after object structure had been allocated.
Reported by: kargl
Reviewed by: kib (sans whitespace)
2012-08-03 17:04:41 +00:00
Konstantin Belousov
bca2f6239d Import the DragonFly BSD commit 4f0bc915b65fcf5a23214f6d221d65c80be68ad4
by John Marino <draco@marino.st>, with the following (edited) commit
message
Date: Sat, 24 Mar 2012 06:40:50 +0100
Subject: [PATCH 1/1] rtld: Implement DT_RUNPATH and -z nodefaultlib

DT_RUNPATH is incorrectly being considered as an alias of DT_RPATH.  The
purpose of DT_RUNPATH is to have two different types of rpath: one that
can be overridden by the environment variable LD_LIBRARY_PATH and one that
can't.  With the currently implementation, LD_LIBRARY_PATH will always
trump any embedded rpath or runpath tags.

Current path search order by rtld:
==================================
LD_LIBRARY_PATH
DT_RPATH / DT_RUNPATH (always the same)
ldconfig hints file (default: /var/run/ld-elf.so.hints)
/usr/lib

New path search order by rtld:
==============================
DT_RPATH of the calling object if no DT_RUNPATH
DT_RPATH of the main binary if no DT_RUNPATH and binary isn't calling obj
LD_LIBRARY_PATH
DT_RUNPATH
ldconfig hints file
/usr/lib

The new path search matches how the linux runtime loader works.  The other
major added feature is support for linker flag "-z nodefaultlib".  When
this flag is passed to the linker, rtld will skip all references to the
standard library search path ("/usr/lib" in this case but it could handle
more color delimited paths) except in DT_RPATH and DT_RUNPATH.

New path search order by rtld with -z nodefaultlib flag set:
============================================================
DT_RPATH of the calling object if no DT_RUNPATH
DT_RPATH of the main binary if no DT_RUNPATH and binary isn't calling obj
LD_LIBRARY_PATH
DT_RUNPATH
ldconfig hints file (skips all references to /usr/lib)

FreeBSD notes:
- we fixed some bugs which were submitted to DragonFly and merged there
  as commit 1ff8a2bd3eb6e5587174c6a983303ea3a79e0002;
- we added LD_LIBRARY_PATH_RPATH environment variable to switch to
  the previous behaviour of considering DT_RPATH a synonym for DT_RUNPATH;
- the FreeBSD default search path is /lib:/usr/lib and not /usr/lib.

Reviewed by:   kan
MFC after:     1 month
MFC note:      flip the ld_library_path_rpath default value for stable/9
2012-07-15 10:53:48 +00:00
Konstantin Belousov
a33cb5feab Ensure that for the object which is a dependency for some filtee,
relocations are performed before the object's initializer is called.
When dlopen()ing an object, relocate the whole DAG rooted in the
object instead of only relocating the object itself and list of newly
loaded dependencies.

Reversed sequence currently can occur if the same object is a
dependency for both filtee and filter, since filtees are loaded
typically during the relocation processing, when some filter
dependencies might be already loaded but not relocated yet.

Reported and tested by:	swills
Reviewed by:	kan
MFC after:	1 week
2012-06-27 20:24:25 +00:00
Konstantin Belousov
e474e51e07 Eliminate the static buffer used to read the first page of the mapped
object, and eliminate the pread(2) call as well [1]. Mmap the first
page of the object temporaly, and unmap it on error or last use.
Potentially, this leaves one-page gap between succeeding dlopen(3),
but there are other mmap(2) consumers as well.

Fix several cases were the whole mapping of the object leaked on error.

Use MAP_PREFAULT_READ for mmap(2) calls which map real object pages [2].

Insipired by the patch by:	Ian Lepore <freebsd damnhippie dyndns org> [1]
Suggested by:	alc [2]
MFC after:	2 weeks
2012-06-14 11:20:22 +00:00
Baptiste Daroussin
5c98f30724 open the resolved path
fix debug message

Submitted by:	John Marino <draco@marino.st>
Approved by:	des (mentor)
2012-05-05 16:37:14 +00:00
Konstantin Belousov
eb6910ccca Work around a situation where symlook_obj() could be called for the
object for which digest_dynamic1() was not done yet. Just return
EINVAL and do not try to dereference NULL buckets hash array.

This seems to happen on ia64 for rtld object itself, where the
R_IA_64_FPTR64LSB relocations require symbol lookup. The dynamic
linker itself does not rely on identity of the C-level function
pointers (i.e. function descriptors).

Reported and reviewed by:	marcel
MFC after:   8 days
2012-05-05 11:26:08 +00:00
Baptiste Daroussin
faf66437f8 Add two special directives to libmap.conf:
include <file>:
  Parse the contents of file before continuing with the current file.
includedir <dir>:
  Parse the contents of every file in dir that ends in .conf before continuing
  with the current file.
Any file or directory encountered while processing include or includedir
directives will be parsed exactly once, even if it is encountered multiple
times.

Reviewed by:	kib, des
Approved by:	des (mentor)
MFC after:	1 month
2012-04-30 21:26:35 +00:00
Konstantin Belousov
f62651920d Add GNU hash support for rtld.
Based on dragonflybsd support for GNU hash by John Marino <draco marino st>
Reviewed by:	kan
Tested by:	bapt
MFC after:	2 weeks
2012-04-30 13:31:10 +00:00
Konstantin Belousov
34cb87ba95 Split the symlook_obj1 into a loop iterating over the ELF object symbol
hash elements, and a helper matched_symbol() which match the given hash
entry and request, performing needed type and version checks.

Based on dragonflybsd support for GNU hash by John Marino <draco marino st>
Reviewed by:	kan
Tested by:	bapt
MFC after:	2 weeks
2012-04-30 13:29:21 +00:00
Nathan Whitehorn
c606eab458 Fix a missed file in r234580: replace the now-obsolete powerpc_mb() with
regular mb().
2012-04-23 00:54:06 +00:00
Konstantin Belousov
fdfc035be6 Propagate the current state of rtld_bind_lock to dlopen_object() calls
through the filter loading call chain. This fixes attempts to
write-lock the already locked rtld_bind_lock when filter loading is
initiated by relocation of dlopening dso.

Reported and tested by:	Taku YAMAMOTO <taku tackymt homeip net>
MFC after:	1 week
2012-04-12 10:32:22 +00:00
Konstantin Belousov
3f4e35f752 Properly handle absent AT_CANARY aux entry.
Submitted by:	Andrey Zonov <andrey zonov org>
MFC after:	3 days
2012-04-05 18:47:54 +00:00
Alexander Kabaev
4aed2ce86e Remove extra blank line from revious commit.
Submitted by:	trema
2012-04-02 11:59:13 +00:00
Alexander Kabaev
7605b428c9 Do not try to adjust stacks if dlopen_object is called too early.
This is a follow-up to r233231, which fixed similar issue with
object initialization code.

Reviewed by:	kib
MFC after:	1 week (with 233231)
2012-04-02 11:50:14 +00:00
Konstantin Belousov
5b7a7b02b8 Fix ia64 build after r233655.
MFC after:	1 week
2012-03-29 17:50:01 +00:00
Konstantin Belousov
5ceeeba90c Import DragonFly BSD commit
From: Sascha Wildner <saw@online.de>
  Date: Fri, 2 Mar 2012 09:15:56 +0000 (+0100)
  Subject: rtld: Add a special case in do_dlsym() for TLS stored symbols.
  X-Git-Url: http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/1388aaafe730c85693936aaf9bc6d83fc2d981be?hp=bca4412595a8979ab9f1bf36068c806ce88a667a

  rtld: Add a special case in do_dlsym() for TLS stored symbols.

  Submitted-by: Markus Pfeiffer <markus.pfeiffer@morphism.de>

Discussed with:	kan
MFC after:	1 week
2012-03-29 10:32:34 +00:00
Konstantin Belousov
ff17bc61e2 Prevent rtld_verify_object_versions() from being called several times
for the same object. This can happen when object is a dependency of the
dlopen()ed dso. When called several times, we waste time due to unneeded
processing, and memory, because obj->vertab is allocated anew on each
iteration.

Reviewed by:	kan
MFC after:	2 weeks
2012-03-27 14:10:15 +00:00
Konstantin Belousov
2aa3a46729 Remove libssp_nonshared from the rtld linking set. The only use for the
library was definition for the weak alias of __stack_chk_fail.

No objections from:	kan
MFC after:	2 weeks
2012-03-24 19:14:44 +00:00
Konstantin Belousov
83dd177761 Provide short-circuit exit(3) implementation for rtld.
There is no atexit finalizers in rtld to call on rtld exiting (due to errors).

Submitted by:	bde
No objections from:	kan
MFC after:	2 weeks
2012-03-24 19:13:10 +00:00
Oleksandr Tymoshenko
bbc54af80e Before jumping to application's entry point set ra == pc in order
to let backtracing routine know to go no further.
2012-03-23 17:54:06 +00:00
Konstantin Belousov
e24348df7f Remove superfluous extern keywords.
MFC after:	   2 weeks
2012-03-23 12:13:31 +00:00
Konstantin Belousov
f7c419f22d Centralize the calculation of the top source directory. This
simplifies the build of rtld with partial checkout, allowing to
override only one place to reference other tree.

Submitted by:	bde
MFC after:	2 weeks
2012-03-23 12:10:12 +00:00
Konstantin Belousov
f7b343037f Implement xstrdup() using strlen()/xmalloc()/memcpy() already
presented in rtld, instead of pulling in libc strdup().

Submitted by:	   bde
MFC after:	   2 weeks
2012-03-23 12:04:44 +00:00
Konstantin Belousov
758ffbfa3b Use xmalloc() instead of malloc() in the places where malloc() calls
are assumed to not fail.

Make the xcalloc() calling conventions follow the calloc(3) calling
conventions and replace unchecked calls to calloc() with calls to
xcalloc().

Remove redundand declarations from xmalloc.c, which are already
present in rtld.h.

Reviewed by:	kan
Discussed with:	bde
MFC after:	2 weeks
2012-03-22 14:20:51 +00:00
Konstantin Belousov
ff6cd33319 Remove the fragments which are not needed on FreeBSD. The caltech
malloc hardly would ever be updated.

Reviewed by:  bde, kan
MFC after:    2 weeks
2012-03-22 14:11:10 +00:00
Konstantin Belousov
082f959ac8 Fix several problems with our ELF filters implementation.
Do not relocate twice an object which happens to be needed by loaded
binary (or dso) and some filtee opened due to symbol resolution when
relocating need objects.  Record the state of the relocation
processing in Obj_Entry and short-circuit relocate_objects() if
current object already processed.

Do not call constructors for filtees loaded during the early
relocation processing before image is initialized enough to run
user-provided code.  Filtees are loaded using dlopen_object(), which
normally performs relocation and initialization.  If filtee is
lazy-loaded during the relocation of dso needed by the main object,
dlopen_object() runs too earlier, when most runtime services are not
yet ready.

Postpone the constructors call to the time when main binary and
depended libraries constructors are run, passing the new flag
RTLD_LO_EARLY to dlopen_object().  Symbol lookups callers inform
symlook_* functions about early stage of initialization with
SYMLOOK_EARLY.  Pass flags through all functions participating in
object relocation.

Use the opportunity and fix flags argument to find_symdef() in
arch-specific reloc.c to use proper name SYMLOOK_IN_PLT instead of
true, which happen to have the same numeric value.

Reported and tested by:	theraven
Reviewed by:	kan
MFC after:	2 weeks
2012-03-20 13:20:49 +00:00
Konstantin Belousov
31f7a2032e Remove write-only variable.
MFC after:	3 days
2012-03-16 19:09:34 +00:00
Konstantin Belousov
6fea10fb9f Rtld on diet 3.
Stop using strerror(3) in rtld, which brings in msgcat and stdio.
Directly access sys_errlist array of errno messages with private
rtld_strerror() function.

Now,
$ size /libexec/ld-elf.so.1
   text    data     bss     dec     hex filename
  96983    2480    8744  108207   1a6af /libexec/ld-elf.so.1

Reviewed by:	dim, kan
MFC after:	2 weeks
2012-03-14 15:39:59 +00:00
Oleksandr Tymoshenko
0bf1897832 Use PTR_SUBU instead of subu (missed this one) 2012-03-12 20:59:18 +00:00
Oleksandr Tymoshenko
7730e5971e Use PTR_(ADD|SUB)U macrosses instead of hardcoded addu/subu
Spotted by: juli
2012-03-12 20:58:09 +00:00
Oleksandr Tymoshenko
33ddd0f61a - Although we pass first 4 arguments in registers, function callinf ABI requires
space to be reserved for them in stack. _rtld() prologue saves a1 and a2 in
   this space.

- Whitespace cleanup while I'm at it
2012-03-12 20:24:59 +00:00
Konstantin Belousov
68f1db20b3 Rtld on diet part 2:
Do not use stdio for libmap.conf read.  Directly map the file and
parse lines from the mappings.

Reviewed by:	kan
MFC after:	3 weeks
2012-03-12 12:16:08 +00:00
Konstantin Belousov
ef5cdcbd69 Rtld on diet part 1:
Provide rtld-private implementations of __stack_chk_guard,
__stack_chk_fail() and __chk_fail() symbols, to be used by functions
linked from libc_pic.a.  This avoids use of libc stack_protector.c,
which pulls in syslog(3) and stdio as dependency.

Also, do initialize rtld-private copy __stack_chk_guard, previously
libc-provided one was not initialized, since we do not call rtld
object _init() methods.

Reviewed by:	kan
MFC after:	3 weeks
2012-03-12 12:15:47 +00:00
Dimitry Andric
3c5b7c6fb9 Amend r232857, now dropping the casts entirely, as they were not
necessary at all.

Submitted by:	stefanf
2012-03-12 11:22:23 +00:00
Dimitry Andric
addfbd03b7 Fix the following warning/error with clang:
libexec/rtld-elf/rtld.c:1898:22: error: comparison between pointer and integer ('Elf_Addr *' (aka 'unsigned int *') and 'Elf_Addr' (aka 'unsigned int')) [-Werror]
    if (preinit_addr == (Elf_Addr)NULL)
        ~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
libexec/rtld-elf/rtld.c:2039:16: error: comparison between pointer and integer ('Elf_Addr *' (aka 'unsigned int *') and 'Elf_Addr' (aka 'unsigned int')) [-Werror]
        if (init_addr != (Elf_Addr)NULL) {
            ~~~~~~~~~ ^  ~~~~~~~~~~~~~~

Reviewed by:	kib
2012-03-12 11:04:48 +00:00
Konstantin Belousov
5eab36f290 When iterating over the dso program headers, the object is not initialized
yet, and object segments are not yet mapped.  Only parse the notes that
appear in the first page of the dso (as it should be anyway), and use
the preloaded page content.

Reported and tested by:	stass
MFC after:	20 days
2012-03-12 10:36:03 +00:00
Konstantin Belousov
83aa9cc00c Add support for preinit, init and fini arrays. Some ABIs, in
particular on ARM, do require working init arrays.

Traditional FreeBSD crt1 calls _init and _fini of the binary, instead
of allowing runtime linker to arrange the calls.  This was probably
done to have the same crt code serve both statically and dynamically
linked binaries.  Since ABI mandates that first is called preinit
array functions, then init, and then init array functions, the init
have to be called from rtld now.

To provide binary compatibility to old FreeBSD crt1, which calls _init
itself, rtld only calls intializers and finalizers for main binary if
binary has a note indicating that new crt was used for linking.  Add
parsing of ELF notes to rtld, and cache p_osrel value since we parsed
it anyway.

The patch is inspired by init_array support for DragonflyBSD, written
by John Marino.

Reviewed by:	kan
Tested by:	andrew (arm, previous version), flo (sparc64, previous version)
MFC after:	3 weeks
2012-03-11 20:03:09 +00:00
Konstantin Belousov
6bfe9e8ccf Optimize tls_get_addr_common(). The change provides around 30% speedup
for TLS microbenchmark using global-dynamic TLS model on amd64 (which is
default for PIC dso objects).

Split the slow path into tls_get_addr_slow(), for which inlining is
disabled. This prevents the registers spill on tls_get_addr_common()
entry.

Provide static branch hint to the compiler, indicating that slow path
is not likely to be taken.

While there, do some minimal style adjustments.

Reported and tested by:	davidxu
MFC after:	1 week
2012-03-10 08:49:44 +00:00
Konstantin Belousov
5983b87199 Remove the use of toupper() from rtld_printf.c. Use of the libc function
relies on working TLS, which is particulary not true for LD_DEBUG uses.

MFC after:	1 week
2012-03-09 16:21:40 +00:00
Sergey Kandaurov
44976acae3 Cosmetic nit:
- rename isspace1() macro to the more appropriate rtld_isspace().

Discussed with:	kib
2012-03-06 09:34:30 +00:00
Oleksandr Tymoshenko
0a0f480835 - Switch to saving non-offseted pointer to TLS block in order too keep things simple 2012-03-06 03:27:08 +00:00
Konstantin Belousov
b36070f555 The libmap.conf initialization is performed before TLS is functional.
Since after r232498 the ctype macros require working access to
thread-local variables, rtld crashes when libmap.conf is present.

Use hand-made isspace1() macro which is enough to detect spaces in
libmap.conf.

Reported by:	alc, lme, many on current@
Tested by:	lme
Reviewed by:	dim, kan
MFC after:	1 week
2012-03-05 20:43:06 +00:00
Oleksandr Tymoshenko
dc3b6c3aa0 Add thread-local storage support for ARM to rtld-elf
Reviewed by:    cognet
Obtained from:  NetBSD
2012-02-14 00:16:34 +00:00
Konstantin Belousov
0eddfb0608 Add missed EOL when die() was converted to use rtld_fdputstr() instead
of errx().

Reported by:	amdmi3
PR:	bin/165075
MFC after:	3 days
2012-02-13 11:15:29 +00:00
Oleksandr Tymoshenko
b098345b9e Add handlers for TLS-related relocation entries 2012-02-11 00:54:57 +00:00
Oleksandr Tymoshenko
9b4f251484 Remove debug output 2012-02-10 19:58:04 +00:00
Oleksandr Tymoshenko
20c390af63 Switch MIPS TLS implementation to Variant I 2012-02-10 06:42:50 +00:00
Oleksandr Tymoshenko
cf9c1f8158 Fix debug output for MIPS part of rtld 2012-02-10 03:30:57 +00:00
Konstantin Belousov
6d7610d75a Add support for GNU RELRO.
Submitted by:	John Marino <draco marino st>
MFC after:	2 weeks
2012-01-30 19:52:17 +00:00
Ed Schouten
581f58e7a3 Remove unneeded dtv variable.
It is only assigned and not used at all. The object files stay identical
when the variables are removed.

Approved by:	kib
2012-01-17 21:55:20 +00:00
Ulrich Spörlein
1acf0dba17 Spelling fixes for libexec/ 2012-01-07 16:09:54 +00:00
Konstantin Belousov
5d8aec9c02 Implement fdlopen(3), an rtld interface to load shared object by file
descriptor.

Requested and tested by:	des (previous version)
Reviewed by:  des, kan (previous version)
MFC after:    2 weeks
2012-01-07 10:33:01 +00:00
Konstantin Belousov
68266d5aba Postpone the resolution of IRELATIVE relocations and IFUNC-targeted
relocations until tls is initialized and stacks permissions correctly
set. This allows the ifunc to call malloc(3) and some other heavy
services.

Add debug banner.

MFC after:	3 days
2012-01-04 17:17:11 +00:00
Nathan Whitehorn
4b51c69976 Additional icache paranoia: non-PLT relocations can modify the text segment.
It is then important to make sure the icache is synchronized again to
prevent (rare) random seg faults and illegal instructions.

MFC after:	3 days
2011-12-17 16:20:27 +00:00
Nathan Whitehorn
17bbcc52d1 Fix RTLD on PowerPC after r228435. Changing the order of init_pltgot()
caused the icache to be invalidated at the wrong time, resulting in
an icache full of nonsense in the PLT section.
2011-12-17 15:31:00 +00:00
Konstantin Belousov
5734c46c68 _rtld_bind() read-locks the bind lock, and possible plt resolution
from the dispatcher would also acquire bind lock in read mode, which
is the supported operation. plt is explicitely designed to allow safe
multithreaded updates, so the shared lock do not cause problems.

The error in r228435 is that it allows read lock acquisition after the
write lock for the bind block.  If we dlopened the shared object that
contains IRELATIVE or jump slot which target is STT_GNU_IFUNC, then
possible recursive plt resolve from the dispatcher would cause it.

Postpone the resolution for irelative/ifunc right before initializers
are called, and drop bind lock around calls to dispatcher.  Use
initlist to iterate over the objects instead of the ->next, due to
drop of the bind lock in iteration.

For i386/reloc.c:reloc_iresolve(), fix calculation of the dispatch
function address for dso, by taking into account possible non-zero
relocbase.

MFC after:	3 weeks
2011-12-14 16:47:53 +00:00
Konstantin Belousov
6be4b69715 Add support for STT_GNU_IFUNC and R_MACHINE_IRELATIVE GNU extensions to
rtld on 386 and amd64. This adds runtime bits neccessary for the use
of the dispatch functions from the dynamically-linked executables and
shared libraries.

To allow use of external references from the dispatch function, resolution
of the R_MACHINE_IRESOLVE relocations in PLT is postponed until GOT entries
for PLT are prepared, and normal resolution of the GOT entries is finished.
Similar to how it is done by GNU, IRELATIVE relocations are resolved in
advance, instead of normal lazy handling for PLT.

Move the init_pltgot() call before the relocations for the object are
processed.

MFC after:	3 weeks
2011-12-12 11:03:14 +00:00
Konstantin Belousov
5b646fa11c Typo.
MFC after:	3 days
2011-12-09 20:40:24 +00:00
Konstantin Belousov
953cc85489 Fix fd leak.
Reported by:	slonoman2011 yandex ru
MFC after:	1 week
2011-11-18 09:55:47 +00:00
Eitan Adler
36daf0495a - change "is is" to "is" or "it is"
- change "the the" to "the"

Approved by:	lstewart
Approved by:	sahil (mentor)
MFC after:	3 days
2011-10-16 14:30:28 +00:00
Konstantin Belousov
ef9cbd91d0 Handle the R_386_TLS_TPOFF32 relocation, which is similar to R_386_TLS_TPOFF,
but with negative relocation value.

Found by:	mpfr test suite, pointed to by ale
Reviewed by:	kan
MFC after:	1 week
2011-10-08 12:42:19 +00:00
Konstantin Belousov
4e63ea7386 Setting up TLS block for the main thread must be done after the
relocations are processed, since tls initialization section might be
itself subject for relocations. Only set up of the block is postponed,
the tls block offsets are allocated before relocation processing, since
TLS-related relocations may need offsets ready.

Reported by:	ale
PR:	threads/161344
Reviewed by:	kan
MFC after:	1 week
2011-10-08 12:39:47 +00:00
Konstantin Belousov
750b5e3134 Restore the writing of the .bss sections of the dsos (not the main
executable) after r190885. The whole region for the dso is mmaped with
MAP_NOCORE flag, doing only mprotect(2) over .bss prevented it from
writing .bss to core files.

Revert the optimization of using mprotect(2) to establish .bss, overlap
the section with mmap(2).

Reported by:	attilio
Reviewed by:	attilio, emaste
Approved by:	re (bz)
MFC after:	2 weeks
2011-09-20 21:49:54 +00:00
Konstantin Belousov
f785588713 Use the proper dynamic tls block to calculate the tls variable address
in case tls data generation was updated.

PR:	misc/160721
Submitted by:	"Thinker K.F. Li" <thinker codemud net>
Tested by:	flo
Approved by:	re (bz)
MFC after:	1 week
2011-09-15 11:50:09 +00:00
Konstantin Belousov
b236731716 Do not use the function pointers for the internal operation of rtld_printf()
functions. The _rtld_error() function might be called early during the rtld
bootstrap, in which case function pointers are not yet functional on ia64
due to required relocations not yet performed.

Reported, reviewed and tested by:	marcel
Approved by:	re (bz)
2011-09-06 10:21:33 +00:00
Dimitry Andric
cce0f33cda When libexec/rtld-elf/rtld.c is compiled with clang, the r_debug_state()
function (a hook necessary for gdb support), is inlined, but since the
function contains no code, no calls to it are generated.  When gdb is
debugging a dynamically linked program, this causes backtraces to be
corrupted.

Fix it by marking the function __noinline, and inserting an empty asm
statement, that pretends to clobber memory.  This forces the compiler to
emit calls to r_debug_state() throughout rtld.c.

Approved by:	re (kib)
2011-09-03 11:41:00 +00:00
Konstantin Belousov
0e9a260520 Rtld links with the specially built pic static libc library to get some
C runtime services, like printf(). Unfortunately, the multithread-safeness
measures in the libc do not work in rtld environment.

Rip the kernel printf() implementation and use it in the rtld instead of
libc version. This printf does not require any shared global data and thus
is mt-safe. Systematically use rtld_printf() and related functions, remove
the calls to err(3).

Note that stdio is still pulled from libc due to libmap implementaion using
fopen(). This is safe but unoptimal, and can be changed later.

Reported and tested by:	pgj
Diagnosed and reviewed by:	kan (previous version)
Approved by:	re (bz)
2011-08-24 20:05:13 +00:00
Ben Laurie
5f301949ef Fix clang warnings.
Approved by:	philip (mentor)
2011-06-18 13:56:33 +00:00
Nathan Whitehorn
f33b8de1dc Compile RTLD with global dot symbols on 64-bit PowerPC, as a crutch for
GDB's ability to locate r_debug_state (which is actually the only function
that need be compiled this way).
2011-06-08 13:23:35 +00:00
Andriy Gapon
6014c8de1d rtld: eliminate double call to close(2) that may occur in load_object
The second close(2) call resulted in heisenbugs in some multi-threaded
applications where e.g. dlopen(3) call in one thread could close a file
descriptor for a file having been opened in other thread concurrently.

My litmus test for this issue was an openoffice.org build.

Reviewed by:	jhb
MFC after:	2 weeks
2011-03-25 18:23:10 +00:00
Marius Strobl
080ca1a51b - Add support for TLS relocations.
- Emitt an error when encountering an unsupported and in case of the
  kernel also for unaligned relocations.
- Fix R_SPARC_LOX10 relocations. Apparently these are hardly ever used.
2011-03-11 21:08:02 +00:00
Marius Strobl
cb32ba5229 - Remove clause 3 and 4 from TNF licenses. [1]
- Add the _RF_X committed in r212998 also to the tables in the sparc64
  reloc.c in order reduce differences between the kernel and the userland
  source. This results in no functional change though.
- Fix further inconsistencies in the abbreviations of the names of the
  relocations.
- Further whitespace fixes.

Obtained from:	NetBSD [1]
2011-03-11 20:30:58 +00:00
Nathan Whitehorn
a43ce960b5 Remove dead code that snuck in from the 32-bit PowerPC version of this
file. The error being checked for does not exist on 64-bit systems.
2011-03-07 20:32:46 +00:00
Marius Strobl
25b31a9496 - With the addition of TLS support binutils started to make the addend
values for resolved symbols relative to relocbase instead of sections
  so detect this case and handle as appropriate, which allows using
  kernel modules linked with affected versions of binutils. Actually I
  think this is a bug in binutils but given that apparently nobody
  complained for nearly six years and powerpc has basically the same
  workaround I decided to put it in for the sparc64 kernel, too.
- Fix R_SPARC_HIX22 relocations. Apparently these are hardly ever used.
2011-03-06 15:20:11 +00:00
Marius Strobl
d374d11285 - Consistently abbreviate the names of the relocations.
- End sentences with dots.
- Fix whitespace.
2011-03-06 13:25:46 +00:00
Nathan Whitehorn
7a159e4971 Remove a hack made obsolete by the binutils 2.17 merge. 2011-02-20 16:16:42 +00:00
Nathan Whitehorn
79c77d726e Turn off default generation of userland dot symbols on powerpc64 now that
we have a binutils that supports it. Kernel dot symbols remain on to assist
DDB.
2011-02-18 21:44:53 +00:00
Konstantin Belousov
a7bc470a84 Use sigsetjmp/siglongjmp with disabled signal mask access for
lock upgrade in rtld. There is no need to care about the mask,
which causes a lot of unneeded sigprocmask(2) calls during each
symbol lookup.
2011-02-09 09:20:27 +00:00
Konstantin Belousov
54a6cb4e7b Fix grammar in comment.
Pointy hat to:	kib
MFC after:	1 week
2011-01-30 16:21:25 +00:00
Konstantin Belousov
2c95328822 Make ldd(1) work when versioned dependency file is cannot be loaded.
Instead of aborting in locate_dependency(), propagate the error to
caller. The rtld startup function does the right thing with an error
from rtld_verify_versions(), depending on the mode of operation.

Reported by:	maho
In collaboration with:	kan
MFC after:	1 week
2011-01-30 16:14:09 +00:00
Alexander Kabaev
20a86d1f34 Eliminate the use of symlook_needed function in favor of DAGS.
Place elements on DAG lists in breadth-first order. This allows us to
walk pre-built list in all cases where breadth-first dependency chain
enumeration is required.

Fix dlsym on special handle obtained by dlopen(NULL, ...) to do what
comment claims it does. Take advantage of recently added symlook_global
function to iterate over main objects and global DAGs lists properly in
search of a symbol. Since rtld itself provides part of the global
namespace, search rtld_obj too.

Remove recursion from init_dag and symlook_needed functions. Use
symlook_needed for ELF filtee processing only and change lookup order
used in the function to match the order used by Solaris runtime linker
under same circumstances. While there, fix weak symbol handling in the
loop so that we return the first weak symbol definition if no strong one
was found, instead of the last one.

Reviewed by: kib
MFC after:   1 month
2011-01-28 23:44:57 +00:00