Commit Graph

637 Commits

Author SHA1 Message Date
Sergey Kandaurov
3fce3875e5 Remove SuperH architecture from a comment as we do not support it.
Presumably it was leaked from NetBSD together with rtld-elf mips support.

Approved by:	kib (mentor)
MFC after:	3 days
2011-01-28 17:30:24 +00:00
Konstantin Belousov
cb38d4941c When loading dso without PT_GNU_STACK phdr, only call
__pthread_map_stacks_exec() on architectures that allow executable
stacks.

Reported and tested by:	marcel (ia64)
2011-01-25 21:12:31 +00:00
Konstantin Belousov
4503c8f7bd Fix get_program_var_addr() when type of the resolved symbol is functional.
Use make_function_pointer then, otherwise ia64 is broken.

Reported and tested by:	marcel
2011-01-25 21:04:55 +00:00
Konstantin Belousov
cb48d32015 Add my copyright.
Discussed with:	kan
2011-01-22 19:25:49 +00:00
Konstantin Belousov
8ae32158df Mark rtld on PowerPC as not requiring executable stack.
Reviewed and tested by:	nwhitehorn
2011-01-14 11:32:31 +00:00
Konstantin Belousov
bf390c1fbd get_program_var_addr() must prefer the strong symbol to the weak
one. Search global objects, together with main object and
dependencies, for the requested symbol.

Move the common code from symlook_default() into new helper
symlook_global(), and use it both in symlook_global() and
get_program_var_addr().

Supply lock state to get_program_var_addr().

Reviewed by:	kan
Tested by:	Mykola Dzham <i levsha me>
2011-01-10 16:09:35 +00:00
Konstantin Belousov
212f264cd6 In rtld, read the initial stack access mode from AT_STACKPROT as set
by kernel, and parse PT_GNU_STACK phdr from linked and loaded dsos.

If the loaded dso requires executable stack, as specified by PF_X bit
of p_flags of PT_GNU_STACK phdr, but current stack protection does not
permit execution, the __pthread_map_stacks_exec symbol is looked up
and called. It should be implemented in libc or threading library and
change the protection mode of all thread stacks to be executable.

Provide a private interface _rtld_get_stack_prot() to export the stack
access mode as calculated by rtld.

Reviewed by:	   kan
2011-01-08 17:11:49 +00:00
Konstantin Belousov
3ad6376e56 Add section .note.GNU-stack for assembly files used by 386 and amd64. 2011-01-07 16:07:05 +00:00
Dimitry Andric
9a17b89ccf Sort -mno-(mmx|3dnow|sse|sse2|sse3) options consistently throughout the
tree.

Submitted by:	arundel
2011-01-05 21:23:26 +00:00
Dimitry Andric
e172464728 On amd64 and i386, tell the compiler to refrain from generating SSE,
3DNow, MMX and floating point instructions in rtld-elf.

Otherwise, _rtld_bind() (and whatever it calls) could possibly clobber
function arguments that are passed in SSE/3DNow/MMX/FP registers,
usually floating point values.  This can happen, for example, when clang
generates SSE code for memset() or memcpy() calls.

One symptom of this is sshd dying early on amd64 with "PRNG not seeded",
which is ultimately caused by libcrypto.so.6 calling RAND_add() with a
double parameter.  That parameter is passed via %xmm0, which gets wiped
out by an SSE memset() in _rtld_bind().

Reviewed by:	kib, kan
2011-01-04 20:51:28 +00:00
Dimitry Andric
7606ddab28 Remove '-elf' from build flags for libexec/rtld-elf for amd64 and i386.
ELF has been the default format for almost 12 years now.
2011-01-04 20:26:41 +00:00
Nathan Whitehorn
9cc92083b0 Add support for R_PPC64_UADDR64 relocations. 2011-01-03 23:11:52 +00:00
Nathan Whitehorn
071a51cf97 Fix an error in the ABI in rtld_bind_start(). When passing arguments to a
C function, the caller's stack frame must have room to store all of the
arguments to that function. While here, fix stack frame alignment issues.

Without this change, the compiler will save r3 and r4 into the caller's
stack frame before calling setjmp() in _rtld_bind(). These would then
overwrite arguments to the newly-bound function, causing eventual failures.
2010-12-28 22:31:59 +00:00
Alexander Kabaev
43c9be3d24 Fix an apparent cop-and-paste mistake in previous commit.
This makes dlsym(RTLD_DEFAULT) work properly again.
2010-12-27 00:30:29 +00:00
Konstantin Belousov
8569deaf1c Implement support for ELF filters in rtld. Both normal and auxillary
filters are implemented.

Filtees are loaded on demand, unless LD_LOADFLTR environment variable
is set or -z loadfltr was specified during the linking. This forces
rtld to upgrade read-locked rtld_bind_lock to write lock when it
encounters an object with filter during symbol lookup.

Consolidate common arguments of the symbol lookup functions in the
SymLook structure.  Track the state of the rtld locks in the
RtldLockState structure. Pass local RtldLockState through the rtld
symbol lookup calls to allow lock upgrades.

Reviewed by:	kan
Tested by:	Mykola Dzham <i levsha me>, nwhitehorn (powerpc)
2010-12-25 08:51:20 +00:00
Konstantin Belousov
06786ccfb3 Add a hook to pass debug flags to the build of rtld when doing make in
the rtld directory.

Reviewed by:	kan
2010-12-25 08:42:38 +00:00
Jaakko Heinonen
4ef75f147a If dlclose() is called recursively from a _fini() function, the inner
dlclose() call may unload the object of the outer call prematurely
because objects are unreferenced before _fini() calls.

Fix this by unreferencing objects after calling objlist_call_fini() in
dlclose(). Therefore objlist_call_fini() now calls the fini function if
the reference count of an object is 1. In addition we must restart the
list_fini traversal after every _fini() call because another dlclose()
call might have modified the reference counts.

Add an XXX comment to objlist_call_fini() about possible race with
dlopen().

PR:		133246, 149464
Reviewed by:	kan, kib
2010-12-16 16:56:44 +00:00
Dimitry Andric
b9c727d84e Use -fPIC to build libexec/rtld-elf on sparc64, so it will also be able
to link with newer binutils, without overflowing the GOT.

Obtained from:	projects/binutils-2.17
2010-11-11 22:53:55 +00:00
Konstantin Belousov
4495a80b97 In r214728, if dlopen() is called for the object that has been already
loaded as a dependency and marked -z nodlopen, object' DAG is already
initialized by load_needed_objects(). Due to this, the init_dag() call
from dlopen() does not increment refcount for the object [1].

Change init_dag() to not increment DAG refcount. Require explicit calls
to ref_dag() to increment, and assert that ref_dag() and unref_dag()
are called for root that has dag initialized. To fix the noted issue,
unconditionally call both init_dag() and ref_dag() in dlopen() for the
case when the object was already loaded, making it similar to the case
of newly loaded object.

Noted by:	jh [1]
Reviewed by:	jh, kan
MFC after:	6 days
2010-11-04 09:29:00 +00:00
Konstantin Belousov
5dc7bbafc8 Fix style.
MFC after:	6 days
2010-11-04 09:19:14 +00:00
Konstantin Belousov
b8fc1b23be If dlopen() is called for the dso that has been already loaded as a
dependency, then the dso never has its DAG initialized. Empty DAG
makes ref_dag() call in dlopen() a nop, and the dso refcount is off
by one.

Initialize the DAG on the first dlopen() call, using a boolean flag
to prevent double initialization.

From the PR (edited):
Assume we have a library liba.so, containing a function a(), and a
library libb.so, containing function b(). liba.so needs functionality
from libb.so, so liba.so links in libb.so.

An application doesn't know about the relation between these libraries,
but needs to call a() and b(). It dlopen()s liba.so and obtains a
pointer to a(), then it dlopen()s libb.so and obtains a pointer to b().

As soon as the application doesn't need a() anymore, it dlclose()s liba.so.

Expected result: the pointer to b() is still valid and can be called
Actual result: the pointer to b() has become invalid, even though the
application did not dlclose() the handle to libb.so. On calling b(), the
application crashes with a segmentation fault.

PR:	misc/151861
Based on patch by:	jh
Reviewed by:	kan
Tested by:	Arjan van Leeuwen <freebsd-maintainer opera com>
MFC after:	1 week
2010-11-03 09:23:08 +00:00
Marcel Moolenaar
30ec71ad04 Unbreak ia64.
With r169630 I disabled symbol versioning because it broke rtld.  With
r211706 rtld got broken for ia64 & powerpc64.  It was fixed for powerpc64
with r212497.  In between, r211749 removed the exports table because the
version script handled the exports.  But wait, symbol versioning was
disabled on ia64.

With exports controlled by the version script and symbol versioning
disabled, all symbols are exported and too many symbols bind to the
definition in rtld. Let's just say that waird things happen.

So, enable symbol versioning on ia64 and apply a work-around for the
SIGSEGV that triggered r169630 to begin with: when rtld relocates
itself, it comes across r_debug_state and for some reason can't find the
definition. This causes a failure, relocation aborts and null pointers
galore. The work-around is to ignore the missing definition when rtld
is relocating itself and keep going.

Maybe with the next binutils this will all go away. Maybe not, in
which case I still need to figure out why r_debug_state cannot be found.

BTW: r_debug_state is in the symbol map -- I don't think any other rtld
symbols that rtld references are in the symbol map...
2010-10-22 04:43:04 +00:00
Ulrich Spörlein
0d9deed52c mdoc: drop redundant .Pp and .LP calls
They have no effect when coming in pairs, or before .Bl/.Bd
2010-10-08 12:40:16 +00:00
Nathan Whitehorn
9d00444d9c Fix two subtle problems in PPC32 RTLD. The first is a concurrency issue
where long PLT calls in multi-threaded environments could end up with
incorrect jmptab values. The second is that, after the addition of extended
PLT support, I forgot to update the PLT icache synchronization code to cover
the extended PLT instead of just the basic PLT.

MFC after:	10 days
2010-10-04 16:02:11 +00:00
Nathan Whitehorn
d48dde6f68 Check for undefined weak symbols during PLT binding on powerpc64, and do
not attempt to copy NULL function descriptors. This fixes LD_BIND_NOW on
powerpc64 after r211706.

Reviewed by:	kib
2010-09-12 17:04:51 +00:00
Nathan Whitehorn
789e85458b Make RTLD work on powerpc64 again. If there is a sub-directory named
MACHINE_ARCH, use that specific one, otherwise use MACHINE_CPUARCH.

Reviewed by:	imp
2010-08-24 23:19:14 +00:00
Konstantin Belousov
d4ba3a5619 Remove exports table. Export control by the version script is enough.
Reviewed by:	kan
MFC after:	3 weeks
2010-08-24 13:01:14 +00:00
Warner Losh
25faff346c MFtbemd:
Prefer MACHNE_CPUARCH to MACHINE_ARCH in most contexts where you want
to test of all the CPUs of a given family conform.
2010-08-23 22:24:11 +00:00
Konstantin Belousov
ea246b6369 On shared object unload, in __cxa_finalize, call and clear all installed
atexit and __cxa_atexit handlers that are either installed by unloaded
dso, or points to the functions provided by the dso.

Use _rtld_addr_phdr to locate segment information from the address of
private variable belonging to the dso, supplied by crtstuff.c. Provide
utility function __elf_phdr_match_addr to do the match of address against
dso executable segment.

Call back into libthr from __cxa_finalize using weak
__pthread_cxa_finalize symbol to remove any atfork handler which
function points into unloaded object.

The rtld needs private __pthread_cxa_finalize symbol to not require
resolution of the weak undefined symbol at initialization time. This
cannot work, since rtld is relocated before sym_zero is set up.

Idea by:	kan
Reviewed by:	kan (previous version)
MFC after:	3 weeks
2010-08-23 15:38:02 +00:00
Konstantin Belousov
e048186a62 Introduce implementation-private rtld interface _rtld_addr_phdr, which
fills struct dl_phdr_info for the shared object that contains the
specified address, if any.

Idea and reviewed by:	kan
MFC after:	3 weeks
2010-08-23 15:27:03 +00:00
Konstantin Belousov
8fc4852252 Provide the starting image with the pointer to ELF aux vector. It is
written into the __elf_aux_vector variable, if the symbol is present.

Idea from:	kan
Tested by:	marius (sparc64)
MFC after:	1 month
2010-08-17 09:08:28 +00:00
Konstantin Belousov
d59a6353d7 Use the newly provided aux vectors to get pagesize and osreldate information.
Use local version of getpagesize(), rtld_getpagesize() in private allocator.
Override the __getosreldate() previously fetched from libc_pic.a with
local version that uses aux value if present. Note that __getosreldate()
is used by rtld indirectly, by mmap(2) libc wrapper.

To be able to utilize aux, split digest_dynamic() for use by init_rtld()
into two parts, where the first one does not call malloc(), and the
second part uses it. init_rtld() is able to initialize global variables
before digest_dynamic2() calls. In particular, pagesize and osreldate are
set up from the aux values.

Now, rtld avoids (two) sysctl calls in startup.

Tested by:	marius (sparc64)
MFC after:	1 month
2010-08-17 09:05:39 +00:00
Neel Natu
247d222548 Add parentheses around the argument 'x' used in the __bswapXX(x) macros. Revert
r211130 in favor of this more general fix.

This fixes a compilation error for mips 64-bit little endian build.
libexec/rtld-elf/mips/reloc.c:196: warning: right shift count >= width of type

Suggested by:	stefanf, jchandra, bde
2010-08-11 02:28:39 +00:00
Neel Natu
8508c6bd40 Fix compilation error for 64-bit little endian build:
libexec/rtld-elf/mips/reloc.c:196: warning: right shift count >= width of type

When the expression '(r_info) >> 32' was passed to bswap32() it was promptly
changed to '(uint32_t)(r_info) >> 32' which is not what we intended.
2010-08-10 05:15:35 +00:00
Jayachandran C.
4c4a1ce8f8 64 bit support for MIPS rtld.
- Handle the case where pltgot[1] is 64 bit.
- use 'ifdef __mips_n64' instead of 'ELFSIZE == 64' to detect 64 bit compile.
2010-07-29 20:18:52 +00:00
Nathan Whitehorn
27bd4146a1 RTLD support for powerpc64. A few small modifications to the Makefile
and symbol map are required to support various consequences of the dot
symbol scheme:

- Symbols beginning with a dot are reserved, so start private symbols with
  an underscore.
- In order to set RTLD breakpoints, gdb must be able to locate the text
  entry point, not the data section function descriptor, so add
  .r_debug_state to the symbol map on powerpc64.

Obtained from:	projects/ppc64
2010-07-10 17:43:24 +00:00
Nathan Whitehorn
153d788f31 Revert r209544. It papers over a binutils bug, and is not even a reliable
fix for it.

The bug occurs when using the --as-needed flag to ld in the presence of
synthetic linker-generated symbols that reference symbols defined in
linked-to shared libraries with versioned symbols. When the only symbols
used from a library fall into this category, ld will drop the DT_NEEDED
entry for it, but retain the versioning information. This bug is best
fixed/hacked around in binutils, not in rtld.

Discussed with:	kan
2010-06-28 01:40:56 +00:00
Nathan Whitehorn
5540acc1ba Ignore versioned dependencies on shared objects to which we do not link.
This fixes an error with files like this created by GNU ld under certain
circumstances.
2010-06-26 22:04:52 +00:00
Jayachandran C.
a77be127e6 Merge jmallett@'s n64 work into HEAD - changeset 3
Update rtld MIPS code to use assembly macros that work on o32/n64.

Changes from http://svn.freebsd.org/base/user/jmallett/octeon

Approved by:	rrs(mentor), jmallett
2010-06-16 16:39:01 +00:00
Alexander Kabaev
f28c411c0c Plug possible memory leak.
Found by:  Coverity
MFC after: 2 weeks
2010-06-03 00:25:43 +00:00
Roman Divacky
1dfdc15bb0 Only use the cache after the early stage of loading. This is
because calling mmap() etc. may use GOT which is not set up
yet. Use calloc() instead of mmap() in cases where this
was the case before (sparc64, powerpc, arm).

Submitted by:	Dimitry Andric (dimitry andric com)
Reviewed by:	kan
Approved by:	ed (mentor)
2010-05-18 08:55:23 +00:00
Pietro Cerutti
071ab531db - Remove const'ness from dlerror(3) prototype, for consistency with POSIX.
Approved by:	cognet
MFC after:	1 week
2010-03-24 15:59:51 +00:00
Warner Losh
5d7dfd42c7 Updated rtld for n32 support.
Submitted by:	jmallet@
Obtained from:	NetBSD
2010-03-04 04:53:05 +00:00
Nathan Whitehorn
4f2730f723 Support the extended PLT format used when objects have more than 8192
PLT relocations on PPC32.
2010-02-22 16:49:45 +00:00
Warner Losh
6f76ed8008 The NetBSD Foundation has granted permission to remove clauses 3 and 4.
Obtained from:	NetBSD
2010-02-16 21:49:36 +00:00
Marcel Moolenaar
e45051c39e Improve TLS variant I:
o   Use obj->tlsinitsize to determine whether there's initialized data.
o   If obj->tlssize > obj->tlsinitsize, then bzero uninitialized data.
o   Don't exclude variant I from the work-around in free_tls_offset().
2010-02-16 02:48:11 +00:00
Ed Schouten
1100c00131 Make WARNS=6 the default for libexec/.
Just like bin/ and sbin/, I think setting WARNS to the highest value
possible will make it more attractive for people to fix warnings.

- The WARNS variable is set in the Makefile in the directory of the
  application itself, making it more likely that it will be removed out
  of curiosity to see what happens.
- New applications will most likely build with WARNS=6 out of the box,
  because the author would more likely fix the warnings during
  development than lower WARNS.

Unfortunately almost all apps in libexec require a lowered value of
WARNS.
2010-01-02 09:50:19 +00:00
Colin Percival
f349fbc4a6 Fix local root vulnerability.
Security:	Advisory will be coming soon.
X-MFC-After:	30 seconds
2009-12-01 02:57:06 +00:00
Konstantin Belousov
abf48e8311 Allow to load not-openable dso when tracing. This fixes ldd on such dso or
dso linked to non-openable object.
Remove '\n' at the end of error message.
End comments with dot.

MFC after:	3 weeks (together with r199829)
2009-11-28 14:29:32 +00:00
Konstantin Belousov
0d3bc8a930 Implement rtld part of the support for -z nodlopen (see ld(1)).
Reviewed by:	kan
MFC after:	3 weeks
2009-11-26 13:57:20 +00:00
Konstantin Belousov
45d276ce3c Flag controlling origin expansion in DT_FLAGS is DF_ORIGIN, not DF_1_ORIGIN.
Reviewed by:	kan
MFC after:	3 days
2009-11-26 13:55:49 +00:00
Robert Watson
de8b11d839 Fix white space in rtld runtime error printf.
MFC after:	3 days
2009-11-14 15:08:44 +00:00
Konstantin Belousov
dec4912e62 Calculate relocation base for the main object, and apply the relocation
adjustment for all virtual addresses encoded into the ELF structures of
it. PIE binary could and should be loaded at non-zero mapbase.

For sym_zero pseudosymbol used as a return value from find_symdef()
for undefined weak symbols, st_value also should be adjusted, since
_rtld_bind corrects symbol values by relocbase.

Discussed with:	bz
Reviewed by:	kan
Tested by:	bz (i386, amd64), bsam (linux)
MFC after:	some time
2009-10-10 15:27:10 +00:00
Robert Watson
1c232cd509 In rtld's map_object(), use pread(..., 0) rather than read() to read the
ELF header from the front of the file.  As all other I/O on the binary
is done using mmap(), this avoids the need for seek privileges on the
file descriptor during run-time linking.

MFC after:	1 month
Sponsored by:	Google
2009-10-06 17:14:39 +00:00
Konstantin Belousov
49e8c06b45 Implement RTLD_NOLOAD flag for dlopen(3).
Requested and tested by:	jkim
Reviewed by:	kan
Approved by:	re (kensmith)
2009-07-17 19:45:42 +00:00
Konstantin Belousov
69ca61ba5e Only perform .bss mapping and cleaning operations when segment file size
is not equal to its memory size.

This eliminates unneeded clearing of the text segment that often
happens due to text end not being page-aligned.

For instance,
$ readelf -l /lib/libedit.so.6
Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x00000000 0x00000000 0x139e1 0x139e1 R E 0x1000
  LOAD           0x014000 0x00014000 0x00014000 0x00f04 0x00f14 RW  0x1000
  DYNAMIC        0x014cc4 0x00014cc4 0x00014cc4 0x000d0 0x000d0 RW  0x4
$ procstat -v $$ (for /bin/sh)
68585 0x28097000 0x280aa000 r-x    6    0  21  14 CN vn /lib/libedit.so.6
68585 0x280aa000 0x280ab000 r-x    1    0   1   0 CN vn /lib/libedit.so.6 <==
68585 0x280ab000 0x280ac000 rwx    1    0   1   0 CN vn /lib/libedit.so.6
Note the splitted map entry marked by '<=='.

Reviewed by:	kan
Approved by:	re (kensmith)
MFC after:	1 month
2009-07-17 19:32:04 +00:00
Alexander Kabaev
2286fe7635 Second attempt at eliminating .text relocations in shared libraries
compiled with stack protector.

Use libssp_nonshared library to pull __stack_chk_fail_local symbol into
each library that needs it instead of pulling it from libc. GCC
generates local calls to this function which result in absolute
relocations put into position-independent code segment, making dynamic
loader do extra work every time given shared library is being relocated
and making affected text pages non-shareable.

Reviewed by:        kib
Approved by:        re (kib)
2009-07-14 21:19:13 +00:00
Alexander Kabaev
d48890cfb8 Back out previous revision until better tested fix is ready.
Approved by: re (impliciti, by approving previos check-in)
2009-06-29 01:33:59 +00:00
Alexander Kabaev
a162c9ae9c Eliminate .text relocations in shared libraries compiled with stack protector.
Use libssp_nonshared library to pull __stack_chk_fail_local symbol into
each library that needs it instead of pulling it from libc. GCC generates
local calls to this function which result in absolute relocations put into
position-independent code segment, making dynamic loader do extra work everys
time given shared library is being relocated and making affected text pages
non-shareable.

Reviewed by:        kib
Approved by:        re (kensmith)
2009-06-28 23:51:39 +00:00
Ed Schouten
26d0788e89 Fix a typo in the same comment, one line below.
Submitted by:	bf1783 googlemail com
2009-06-23 14:12:49 +00:00
Ed Schouten
75b872ee53 Fix typo in comment.
Submitted by:	Christoph Mallon
2009-06-23 09:50:50 +00:00
Alexander Kabaev
6c3154f6a1 Allow order of initialization of loaded shared objects to be
altered through their .init code. This might happen if init
vector calls dlopen on its own and that dlopen causes some not
yet initialized object to be initialized earlier as part of that
dlopened DAG.

Do not reset module reference counts to zero on final fini vector
run when process is exiting. Just add an additional parameter to
force fini vector invocation regardless of current reference count
value if object was not destructed yet. This allows dlclose called
from fini vector to proceed normally instead of failing with handle
validation error.

Reviewed by:	kib
Reported by:	venki kaps
2009-06-20 14:16:41 +00:00
Alexander Kabaev
1310f23766 FreeBSD returns main object handle from dlopen(NULL, ...) calls.
dlsym seaches using this handle are expected to look for symbol
definitions in all objects loaded at the program start time along
with all objects currently in RTLD_GLOBAL scope.

Discussed with: kib
Reported by:	Maho NAKATA
MFC after:	2 weeks
2009-06-16 16:38:54 +00:00
Doug Rabson
22a91927b3 Increase the size of the static TLS area slightly (required for the NVidia's
OpenGL driver on amd64).
2009-05-27 18:54:31 +00:00
Robert Watson
3f2f85a6de Prefer <sys/param.h> to <machine/param.h> for the definition of
CACHE_LINE_SIZE.

Submitted by:	bde
MFC after:	2 weeks
2009-04-20 10:35:50 +00:00
Robert Watson
d9d845a99c Explicitly include machine/param.h for CACHE_LINE_SIZE.
MFC after:	2 weeks
2009-04-19 23:03:57 +00:00
Robert Watson
d1f2f1c3f3 Now that the kernel defines CACHE_LINE_SIZE in machine/param.h, use
that definition in the custom locking code for the run-time linker
rather than local definitions.

Pointed out by:	tinderbox
MFC after:	2 weeks
2009-04-19 23:02:50 +00:00
Konstantin Belousov
a3c8e04ef7 Currently, when mapping an object, rtld reserves the whole address space
for the mapping by the object' file with the protection and mode of
the first loadable segment over the whole region. Then, it maps other
segments at the appropriate addresses inside the region.

On amd64, due to default alignment of the segments being 1Gb, the
subsequent segment mappings leave the holes in the region, that usually
contain mapping of the object' file past eof. Such mappings prevent
wiring of the address space, because the pages cannot be faulted in.

Change the way the mapping of the ELF objects is constructed, by first
mapping PROT_NONE anonymous memory over the whole range, and then
mapping the segments of the object over it. Take advantage of this new
order and allocate .bss by changing the protection of the range instead
of remapping.

Note that we cannot simply keep the holes between segments, because
other mappings may be made there. Among other issues, when the dso is
unloaded, rtld unmaps the whole region, deleting unrelated mappings.

The kernel ELF image activator does put the holes between segments, but
this is not critical for now because kernel loads only executable image
and interpreter, both cannot be unloaded. This will be fixed later, if
needed.

Reported and tested by:	Hans Ottevanger <fbsdhackers beasties demon nl>
Suggested and reviewed by:	kan, alc
2009-04-10 10:14:04 +00:00
Konstantin Belousov
11e0093f28 Update comment to the reality, rtld supports any number of loadable segments.
Fix spacing.

Reviewed by:	kan
2009-04-10 09:52:42 +00:00
Konstantin Belousov
c8da4f07d7 Allow the NULL, RTLD_SELF and RTLD_NEXT handles to work with dlfunc(3).
dlfunc() called dlsym() to do the work, and dlsym() determines the dso
that originating the call by the return address. Due to this, dlfunc()
operated as if the caller is always the libc.

To fix this, move the dlfunc() to rtld, where it can call the internal
implementation of dlsym, and still correctly fetch return address.
Provide usual weak stub for the symbol from libc for static binaries.
dlfunc is put to FBSD_1.0 symver namespace in the ld.so export to
override dlfunc@FBSD_1.0 weak symbol, exported by libc.

Reported, analyzed and tested by:	Tijl Coosemans <tijl ulyssis org>
PR: standards/133339
Reviewed by:	kan
2009-04-03 19:17:23 +00:00
Konstantin Belousov
b2e4ce45d9 Document RTLD_NODELETE, -z nodelete and -z origin support. 2009-04-01 14:38:20 +00:00
Konstantin Belousov
2b0b4ee359 Implement support for RTLD_NODELETE flag for dlopen() and -z nodelete
static linker option. Do it by incrementing reference count on the loaded
object and its dependencies.

Reviewed by:	davidxu, kan
2009-03-30 08:47:28 +00:00
Konstantin Belousov
4d59cc85e8 Do not dereference NULL pointer. refobj is NULL for the objects that are
preloaded.

Reported and tested by:	ed
2009-03-28 15:54:08 +00:00
Xin LI
569e2ef6a9 Support for a new environment variable, LD_ELF_HINTS_PATH for overriding
the rtld hints file.  This environment variable would be unset if the
process is considered as tainted with setuid/setgid.  This feature gives
a convenient way of using a custom set of shared library that is not
located in the default location and switch back.

Feature requested by:	iXsystems
Original patch by:	John Hixson
MFC after:		2 weeks
2009-03-23 16:49:00 +00:00
Konstantin Belousov
28551690e0 Implement the dynamic string token substitution in the rpath and
soneeded pathes. The $ORIGIN, $OSNAME, $OSREL and $PLATFORM tokens
are supported. Enabling the substitution requires DF_ORIGIN flag in
DT_FLAGS or DF_1_ORIGIN if DF_FLAGS_1, that may be set with -z origin
gnu ld flag. Translation is unconditionally disabled for setuid/setgid
processes.

The $ORIGIN translation relies on the AT_EXECPATH auxinfo supplied
by kernel.

Requested by:	maho
Tested by:	maho, pho
Reviewed by:	kan
2009-03-18 13:40:37 +00:00
Ruslan Ermilov
d9ca85fca7 Fix build when WITH_SSP is set explicitly.
Submitted by:	Jeremie Le Hen
2009-02-21 15:04:31 +00:00
Konstantin Belousov
10b4034657 Provide custom simple allocator for rtld locks in libthr. The allocator
does not use any external symbols, thus avoiding possible recursion into
rtld to resolve symbols, when called.

Reviewed by:	kan, davidxu
Tested by:	rink
MFC after:	1 month
2008-12-02 11:58:31 +00:00
Konstantin Belousov
cb5c4b10ba Add two rtld exported symbols, _rtld_atfork_pre and _rtld_atfork_post.
Threading library calls _pre before the fork, allowing the rtld to
lock itself to ensure that other threads of the process are out of
dynamic linker. _post releases the locks.

This allows the rtld to have consistent state in the child. Although
child may legitimately call only async-safe functions, the call may
need plt relocation resolution, and this requires working rtld.

Reported and debugging help by:	rink
Reviewed by:	kan, davidxu
MFC after:	1 month (anyway, not before 7.1 is out)
2008-11-27 11:27:59 +00:00
Warner Losh
1d178313cc This code has no copyright. It is fairly obvious to me that we're a
derivitive of NetBSD's mips_reloc.c, so pull in the copyright notice
from there.

Also, a minor tweak to load/store pointers.  Other changes from NetBSD
likely would be useful too...

Obtained from:	NetBSD
2008-10-13 20:24:03 +00:00
Warner Losh
2ab1831e76 MFp4: Fix a bug in the mips relocation code that prevents shared images
from working.

From p4 filelog of the upstream file in p4

//depot/projects/mips2-jnpr/src/libexec/rtld-elf/mips/reloc.c
... #6 change 140737 edit on 2008/04/27 by gonzo@gonzo_jeeves (text+ko)

        o Looks like handler for R_MIPS_REL32 brought by CS 137942
            is broken for tradmips. Code from NetBSD's
            libexec/ld.elf_so/arch/mips/mips_reloc.c works just fine.

... #3 change 137942 edit on 2008/03/17 by rrs@rrs-mips2-jnpr (text+ko)

        Any relocation symbol lookup if its 0. It looks like
               this is the way the compiler indicates you need to
               look in another shared library. When we hit these
               as we relocate a object we will do the symbol
               lookups and setup the relocation table with the
               right value.

Submitted by:	rrs@, gonzo@
2008-10-10 05:10:10 +00:00
Alexander Kabaev
657d9f9ae9 Allow strong symbols to override weak ones for lookups done through
dlsym with RTLD_NEXT/RTLD_SELF handles.

Allow symbols from ld-elf.so to be located this way too.

Based on report and original patch from sobomax@.
2008-10-10 00:16:32 +00:00
David Xu
d8b04dc0d4 Allow multiple locks to be acquired by detecting corresponding
bit flag, otherwise if a thread acquired a lock, another thread
or the current thread itself can no longer acquire another lock
because thread_mask_set() return whole flag word, this results
bit leaking in the word and misbehavior in later locking and
unlocking.
2008-09-16 01:46:11 +00:00
Alexander Kabaev
61adda8468 Make sure internal rtld malloc routines are not called from unlocked
contexts as rtld's malloc is not thread safe and is only supposed to be
called with exclusive bind lock already held.

The originating PR submitted a patch on top of different pre-requisite
workaroud for unsafe dlopen calls, and the patch was midief slighlty to apply
to stock sources for the purpose of this commit. Running rtld malloc from
unlocked contexts is a bug on its own.

PR: 126950
Submited by: Oleg Dolgov
2008-09-03 01:05:32 +00:00
Ruslan Ermilov
042df2e2da Enable GCC stack protection (aka Propolice) for userland:
- It is opt-out for now so as to give it maximum testing, but it may be
  turned opt-in for stable branches depending on the consensus.  You
  can turn it off with WITHOUT_SSP.
- WITHOUT_SSP was previously used to disable the build of GNU libssp.
  It is harmless to steal the knob as SSP symbols have been provided
  by libc for a long time, GNU libssp should not have been much used.
- SSP is disabled in a few corners such as system bootstrap programs
  (sys/boot), process bootstrap code (rtld, csu) and SSP symbols themselves.
- It should be safe to use -fstack-protector-all to build world, however
  libc will be automatically downgraded to -fstack-protector because it
  breaks rtld otherwise.
- This option is unavailable on ia64.

Enable GCC stack protection (aka Propolice) for kernel:
- It is opt-out for now so as to give it maximum testing.
- Do not compile your kernel with -fstack-protector-all, it won't work.

Submitted by:	Jeremie Le Hen <jeremie@le-hen.org>
2008-06-25 21:33:28 +00:00
Bruce M Simpson
523b17effe Make the meaning of the %A format specifier, as passed to
LD_TRACE_LOADED_OBJECTS_FMT[12], more obvious for users like me.
2008-05-15 10:47:14 +00:00
Konstantin Belousov
e91ff25c0c Fix the problem with the C++ exception handling for the multithreaded
programs.

From the PR description:
The gcc runtime's _Unwind_Find_FDE function, invoked during exception
handling's stack unwinding, is not safe to execute from within multiple
threads. FreeBSD' s dl_iterate_phdr() however permits multiple threads
to pass through it though. The result is surprisingly reliable infinite
looping of one or more threads if they just happen to be unwinding at
the same time.

Introduce the new lock that is write locked around the dl_iterate_pdr,
thus providing required exclusion for the stack unwinders.

PR:	threads/123062
Submitted by:	Andy Newman <an at atrn org>
Reviewed by:	kan
MFC after:	2 weeks
2008-05-06 09:27:41 +00:00
Warner Losh
652d402e7b MFp4: Add mips support for dynamic linking.
This code came from the merged mips2 and Juniper mips repositories.
Warner Losh, Randall Seager, Oleksandr Tymoshenko and Olivier Houchard
worked to merge, debug and integrate this code.  This code may also
contain code derived from NetBSD.
2008-04-04 20:59:26 +00:00
Robert Watson
19ab4b35fb For un-prototyped static inline functions declared in pthread_md.h on
sparc64, use ANSI function headers and specifically indicate the lack of
arguments with 'void'.  Otherwise, warnings are generated at WARNS=3 for
libkse, leading to a compile failure with -Werror.
2007-12-01 14:24:44 +00:00
John Birrell
1566f9a7f9 Include an extra header to get a function prototype. 2007-11-19 08:58:11 +00:00
Marius Strobl
77ddefb873 - Fix the handling of R_SPARC_OLO10, which is a bit of a special case
in the way we implement handling of relocations.
  As for the kernel part this fixes the loading of lots of modules,
  which failed to load due to unresolvable symbols when built after
  the GCC 4.2.0 import. This wasn't due to a change in GCC itself
  though but one of several changes in configuration done along the
  import. Specfically, HAVE_AS_REGISTER_PSEUDO_OP, which causes GCC
  to denote global registers used for scratch purposes and in turn
  GAS uses R_SPARC_OLO10 relocations for, is now defined.
  While at it replace some more ELF_R_TYPE which should have been
  ELF64_R_TYPE_ID but didn't cause problems so far.
- Sync a sanity check between kernel and rtld(1) and change it to be
  maintenance free regarding the type used for the lookup table.
- Sprinkle const on lookup tables.
- Use __FBSDID.

Reported and tested by:	yongari
MFC after:		5 days
2007-10-16 19:17:48 +00:00
Marcel Moolenaar
99227f1ec4 Unbreak the dynamic linker by not creating a cache for rtld-elf
itself. It needs mmap(2), which now needs getosreldate(3) and
which in turn uses a global variable to cache the result. This
cannot be done before linking is done.

See also: ../sparc64/reloc.c:1.15
Approved by: re (kensmith)
2007-07-15 22:52:15 +00:00
Ken Smith
6e5e629f07 Cache does not serve any purpose when rtld is relocating itself, do
not bother allocating one.

Submitted by:	kan
Approved by:	re (bmah)
2007-07-13 16:18:43 +00:00
Alexander Kabaev
03c4fb02dd Add r_debug_state to the list of symbols exported from rtld. GDB needs to
be able to find it in order to trap shared library events from rtld.

Approved by:	re (rwatson)
2007-07-11 23:07:37 +00:00
Christian S.J. Peron
b075897e99 Update the man page to reflect that certain variables will be unset in
the case that the program is set-user-ID or set-group-ID. Add missing
annotations for LIBMAP and LIBMAP_DISABLE.
2007-05-17 19:14:25 +00:00
Christian S.J. Peron
d61e5aa4ed In the event a process is tainted (setuid/setgid binaries), un-set any
potentially dangerous environment variables all together. It should be
noted that the run-time linker will not honnor these environment variables
if the process is tainted currently. However, once a child of the tainted
process calls setuid(2), it's status as being tainted (as defined by
issetugid(2)) will be removed. This could be problematic because
subsequent activations of the run-time linker could honnor these
dangerous variables.

This is more of an anti foot-shot mechanism, there is nothing I am
aware of in base that does this, however there may be third party
utilities which do, and there is no real negative impact of clearing
these environment variables.

Discussed on:	secteam
Reviewed by:	cperciva
PR:		kern/109836
MFC after:	2 weeks
2007-05-17 18:00:27 +00:00
Marcel Moolenaar
cc09c7fb77 Don't enable symbol versioning on ia64 for now. It causes
symbol lookup failures that later result in null-pointer
dereferences. This needs looking into, but since we're
close to release it's possible that it's not resolved before
that time.
2007-05-16 23:24:15 +00:00
Marcel Moolenaar
878dd988ef We don't need --export-dynamic for ld-elf.so.1, because it's a
shared object.
2007-05-16 23:19:51 +00:00
Daniel Eischen
00fb440c1a Enable symbol versioning by default. Use WITHOUT_SYMVER to disable it.
Warning, after symbol versioning is enabled, going back is not easy
(use WITHOUT_SYMVER at your own risk).

Change the default thread library to libthr.

There most likely still needs to be a version bump for at least the
thread libraries.  If necessary, this will happen later.
2007-05-13 14:12:40 +00:00
Pav Lucistnik
88922cf00e Remove %m formatter, it's ifdef 0'ed in the code from the very beginning
MFC after:	1 week
2007-05-12 12:26:25 +00:00
Pav Lucistnik
b9e1d83e61 Expand documentation for LD_TRACE_LOADED_OBJECTS_FMT? variables
PR:		docs/66265 (inspired by)
Submitted by:	Michel Lavondes <fox@vader.aacc.cc.md.us>
MFC after:	1 week
2007-05-12 12:24:49 +00:00
David Xu
25785f9165 Fix a TLS memory leak.
PR: threads/112297
MFC: 1 week
2007-05-05 08:44:59 +00:00
Daniel Eischen
7046601eca Catch up with the private namespace change (s/FBSDprivate/FBSDprivate_1.0). 2007-05-01 13:46:27 +00:00
Alexander Kabaev
effa5b4e71 Retire rtld-specific Versions.def. Symbols exported by rtld are supposed
to override weak symbols exported by libc, so by definition these two
are using the same symbol version names.

Reflect the reality by referring to libc's Versions.def directly.
2007-04-29 16:12:06 +00:00
Daniel Eischen
b5a71dda23 Give the private version namespace a number to match libc. 2007-04-29 14:16:19 +00:00
Daniel Eischen
5f864214bb Use C comments since we now preprocess these files with CPP. 2007-04-29 14:05:22 +00:00
Alexander Kabaev
3c0d0ca74b Bring rtld exports in line with corresponding symbols exported from
libc.

Disable SYMVER_DEFAULT n rtld until its implications are understood
better.
2007-04-09 23:00:29 +00:00
Alexander Kabaev
95a6a22d0a Remove reference to FBSDprivate version. We do not use it in this
module yet.
2007-04-07 23:23:10 +00:00
Alexander Kabaev
ac34654dd9 Catch up on rtld's special status. Since it does not appear on
main object list, its versioning information needs to be examined
separately.

This hopefully fixes problems that people running with SYMVER_ENABLED
are experiencing.
2007-04-07 23:17:00 +00:00
Alexander Kabaev
7ca8e6a670 Prepare rtld for symbol versioning. Disable it by default for now. 2007-04-03 19:01:06 +00:00
Alexander Kabaev
49f90ad282 Implement dl_iterate_phdr function.
Convert boolean flags in internal Obj_Entry structure into bitfields.
Properly check for loaded segment alignment in map_object.
2007-04-03 18:31:20 +00:00
Alexander Kabaev
fb6395da91 Use u_int for variable manipulated by atomic ops to match atomic
ops function prototypes.
2007-04-03 18:28:13 +00:00
John Baldwin
f0ac0f92fb Document LD_UTRACE.
MFC after:	3 days
2007-01-23 22:38:39 +00:00
John Baldwin
1f4b63f824 Add various utrace's for use with ktrace to the ELF runtime linker. To
activate the traces, set the LD_UTRACE (or LD_32_UTRACE) environment
variable.  This also includes code in kdump(8) to parse the traces.

Reviewed by:	kan, jdp
MFC after:	2 weeks
2007-01-09 17:50:05 +00:00
Kip Macy
b84c7a797c Fix TLS on sparc64 for statically and dynamically linked binaries
Approved by: rwatson (mentor)
Reviewed by: jmg and marcel
2006-10-08 02:50:34 +00:00
Jung-uk Kim
da7bf2bb26 Clean up white spaces and fix style(9). 2006-09-19 16:48:08 +00:00
Konstantin Belousov
5fd885b07b Fix the buggy rev. 1.117. dagmembers are only initialized for dlopen'ed
dso that are actually loading. If dso a.so depends on b.so, then dlsym
with handle from dlopen("b.so") will fail unconditionally.

Correct implementation shall use the Obj_Entry.needed list to walk
dependencies DAG.

Test provided by: jkim
Tested (prev. version) by:	jkim, Nicolas Blais <nb_root at videotron ca>, h.blanke at chello nl
Pointy hat to:	kib
Approved by:	kan (mentor)
2006-09-19 12:47:13 +00:00
Ruslan Ermilov
a3ec17db37 Markup fixes. 2006-09-17 21:48:47 +00:00
Konstantin Belousov
d0cb0064fe When looking up the symbol by dlsym, look it not only in the object
given as dso handle, but also in the implicit dependencies of that dso.

Also, const-ify the read-only parameter objlist of symlook_list.

Reported by:	"Simon 'corecode' Schubert" <corecode at fs ei tum de>
Approved by:	kan (mentor)
X-MFC-After:	6.2
2006-09-08 14:59:54 +00:00
Marcel Moolenaar
3614156c7d Fix the variant I allocation for KSE: Allow a larger TCB and assume
that the documented TCB is at the tail of the extended TCB. In other
words, the base of the TCB has a negative offset from the TLS.
2006-09-01 06:13:16 +00:00
Marcel Moolenaar
9d34b1a911 o Fix the static TLS relocation. We were subtracting the size of
the TCB.
o  Use NULL for null pointer argument.
o  Replace magic 8 with TLS_TCB_SIZE.
2006-09-01 06:08:50 +00:00
Marcel Moolenaar
653d825a9a Use NULL for null-pointer argument. 2006-09-01 06:07:26 +00:00
Marcel Moolenaar
862894168d Replace magic 16 with TLS_TCB_SIZE. 2006-08-31 19:42:39 +00:00
Marcel Moolenaar
7d3f85133a Prevent dead code elimination for the TP assignmient by using inline
assembly.
2006-08-30 00:39:07 +00:00
Ruslan Ermilov
2b46c64c9c Remove alpha left-overs. 2006-08-22 08:03:01 +00:00
Xin LI
c93b8edf09 In symlook_obj(): fix _rtld_error output.
MFC After:	2 weeks
2006-08-04 13:37:54 +00:00
Dag-Erling Smørgrav
4421d895a9 *thwack*! all the world's not i386.
Pointy hat to:	des
2006-03-29 12:29:01 +00:00
Dag-Erling Smørgrav
370e5ea48c Don't use dbg if it isn't defined (such as when this file is used by
code outside of rtld-elf)
2006-03-28 18:28:07 +00:00
Dag-Erling Smørgrav
1dc39023f8 Use C99's varadic macro syntax instead of gcc's. 2006-03-28 18:26:47 +00:00
David Xu
c771787169 Er, forgot to clear tls space to zero for Variant II. 2006-03-28 06:14:22 +00:00
David Xu
c0d2338cdd Allocate space for thread pointer, this allows thread library to access
its pointer from begin, and simplifies _get_curthread() in libthr.
2006-03-28 06:09:24 +00:00
Pav Lucistnik
8a50f51b1b - Document LD_32_* environment variables
- Mention 32-bit files in FILES section

MFC after:	1 week
2006-03-27 00:53:58 +00:00
Peter Wemm
8c6a035ead Fix a malloc overrun in 32-bit compat libmap lookup code. 2006-01-31 06:08:28 +00:00
Marcel Moolenaar
05157fa0a1 s/DT_IA64_PLT_RESERVE/DT_IA_64_PLT_RESERVE/ 2006-01-28 17:58:22 +00:00
Marcel Moolenaar
4af16b88cc s/R_IA64_/R_IA_64_/ 2006-01-28 17:56:16 +00:00
Marcel Moolenaar
853b7411b6 s/R_IA64_/R_IA_64_/g as per the ia64 psABI. 2006-01-17 21:03:22 +00:00
Jason Evans
52828c0e9c In preparation for a new malloc implementation:
* Add posix_memalign().

  * Move calloc() from calloc.c to malloc.c.  Add a calloc() implementation in
    rtld-elf in order to make the loader happy (even though calloc() isn't
    used in rtld-elf).

  * Add _malloc_prefork() and _malloc_postfork(), and use them instead of
    directly manipulating __malloc_lock.

Approved by:	phk, markm (mentor)
2006-01-12 07:28:21 +00:00
Alexander Kabaev
96ff9a2bf4 Make lookups for relocations from old unversioned binaries return
oldest versioned symbol available. Do not accept hidden symbols for
all other versions.

Use "<obj->path>: <error message>" for all error messages in new
functions to make them more consistent.
2005-12-24 15:37:30 +00:00
Alexander Kabaev
b80d39d0c0 Remove debugging statement that slipped into lone of the previous commits
unintentionally.
2005-12-23 15:30:53 +00:00
Alexander Kabaev
f6e5db226f Initialize object dagmembers list before checking version dependencies. 2005-12-22 16:42:38 +00:00
Alexander Kabaev
0eb88f2029 Implement ELF symbol versioning using GNU semantics. This code aims
to be compatible with symbol versioning support as implemented by
GNU libc and documented by http://people.redhat.com/~drepper/symbol-versioning
and LSB 3.0.

Implement dlvsym() function to allow lookups for a specific version of
a given symbol.
2005-12-18 19:43:33 +00:00
Marcel Moolenaar
757686b115 Make our ELF64 type definitions match standards. In particular this
means:
o  Remove Elf64_Quarter,
o  Redefine Elf64_Half to be 16-bit,
o  Redefine Elf64_Word to be 32-bit,
o  Add Elf64_Xword and Elf64_Sxword for 64-bit entities,
o  Use Elf_Size in MI code to abstract the difference between
   Elf32_Word and Elf64_Word.
o  Add Elf_Ssize as the signed counterpart of Elf_Size.

MFC after: 2 weeks
2005-12-18 04:52:37 +00:00
Marcel Moolenaar
55dfaa9163 Explicitly cast ELF_R_TYPE() to the right type. 2005-12-18 01:38:26 +00:00
John Baldwin
4d5fe96d68 Fix a bug in dlinfo(RTLD_DI_SERINFOSIZE) requests. For each search path
we included the length of the path in the returned size but not the length
of the associated Dl_serpath structure.  Without this fix, programs
attempting to allocate a structure to hold the search path information
would allocate too small of a buffer and rtld would overrun the buffer
while filling it via a subsequent RTLD_DI_SERINFO request.

Submitted by:	"William K. Josephson" wkj at morphisms dot net
Reviewed by:	jdp
MFC after:	2 weeks
2005-11-11 19:57:41 +00:00
Peter Wemm
3b4399f6a7 Clean out the leftovers from the i386_set_gsbase() TLS conversion.
Like on libthr, there is an i386_set_gsbase() stub implementation here
to avoid libc.so.5 issues.  This should likely be a weak symbol and I
expect this will be fixed soon.

Approved by:	re
2005-06-29 23:15:36 +00:00
Ruslan Ermilov
cc4fdb1de9 Removed trailing whitespace.
Approved by:	re (blanket)
2005-06-14 08:41:11 +00:00
Marius Strobl
8698905073 MFNetBSD: src/libexec/ld.elf_so/arch/sparc64/mdreloc.c 1.26 (partial)
Fix an obvious bug in the 64-bit PLT fixup: the SLLX was by 12 bits, when
it should be 32.

MFC after:	1 month
2005-06-04 20:49:15 +00:00
Marcel Moolenaar
d4337d869f Fix the load64 and store64 macros, created to handle 8-byte unaligned
loads and stores (resp.) The ldq_u and stq_u instruction mask off the
lower 3 bits of the final address before loading from or storing to
the address, so as to avoid unaligned loads and stores. They do not
themselves allow loads from or stores to unaligned addresses. Replace
the macro definitions by a packed struct dereference.

Submitted by: Richard Henderson (rth at twiddle dot net)
2005-06-02 05:34:08 +00:00
Doug Rabson
9310a53def Align the stack to a 16 byte boundary before calling _rtld so that we can
safely initialise shared libraries that use SSE in their init sections.

MFC After: 1 week
2005-05-19 07:32:42 +00:00
David Xu
9b0c632a4c Fix compilation problem. 2005-04-27 13:17:23 +00:00
Peter Wemm
8d598c0d01 Stop calling _amd64_set_gsbase() for COMPAT_32BIT. The amd64 kernel
implements i386_set_gsbase(), so there is no need for the variation.
2005-04-26 20:38:44 +00:00
Peter Wemm
8a477e0a7a Attempt to use i386_set_gsbase(), and gracefully fall back to LDT methods
if the direct access methods are not implemented.
2005-04-14 00:04:50 +00:00
Olivier Houchard
2204e78f5e No need to provide atomic_cmpset_32() anymore. 2005-04-07 22:04:49 +00:00
Doug Rabson
3709906a1d When allocating TLS and DTV, make sure that any unused slots in the DTV
are initialised to zero. When freeing TLS, don't attempt to free DTV
slots which were not used.

Pointed out by: Joerg Sonnenberger
X-MFC-After: After the branch, probably
2005-03-30 08:28:26 +00:00
Colin Percival
8fe7df9b68 If "dangerous" environment variables (LD_PRELOAD, LD_LIBMAP,
LD_LIBMAP_DISABLE, LD_LIBRARY_PATH) are used, then make sure the
libraries being loaded aren't on a noexec-mounted filesystem.

This is a compromise position: I'm assuming that nobody will be silly
enough to set the noexec mount flag on part of the default library
path, in order to avoid adding extra overhead into the common case
(where those environment variables aren't used).

Discussed with:	csjp, secteam
MFC after:	1 week
2005-03-24 10:12:29 +00:00
David Xu
c5fa3778bb Add locking code for tls routines. 2005-03-20 23:28:25 +00:00
Doug Rabson
ddab7ee80a Attempt to free any static TLS space used by a shared library when it
is unloaded. This allows applications which load and unload libraries
like libGL.so.1 several times to work properly.

MFC after: 2 days
2005-02-27 12:55:40 +00:00
Olivier Houchard
c6ac5bfcae Only provide the dummy, non-atomic atomic_cmpset_32() if
ARM_HAS_ATOMIC_CMPSET_32 isn't defined.
2005-02-26 22:49:19 +00:00
Matthew N. Dodd
5b08cb0449 Description from Dan:
Another handy libmap patch.  Lets you do stuff like this:

	LD_LIBMAP="libpthread.so.1=libthr.so.1" mythreadedapp

	If you already have a program-specific override in libmap.conf, note
	that you must use a program-specific override in LD_LIBMAP:

	LD_LIBMAP="[mythreadedapp],libpthread.so.1=libthr.so.1" mythreadedapp

PR:		bin/74471
Submitted by:	Dan Nelson <dnelson AT allantgroup.com>
MFC after:	2 weeks
2005-02-04 02:46:41 +00:00
Matthew N. Dodd
d33da23f4c style(9) 2005-02-04 02:13:37 +00:00
Olivier Houchard
25a252899e Implement a dummy atomic_cmpset_32(). It should be safe to use it in rtld as
the signals are masked anyway.
2004-11-23 16:32:34 +00:00
John Baldwin
165204a75f Remove 80386 support from the ELF run time linker. 2004-11-16 20:45:51 +00:00
Ruslan Ermilov
1b1aa7e465 So do it like we do in usr.bin/tip/tip/Makefile. ;) 2004-11-14 22:18:31 +00:00
Jens Schweikhardt
443ceb1c7e Revert previous commit. As ru explains:
In the old world (as the surrounding comment in makefile says), there
 was the /usr/libexec/ld-elf.so.1 binary which is now a symlink to
 /libexec/ld-elf.so.1. To symlink, we need to make sure that the
 _target_ (and the target is /usr/libexec/ld-elf.so.1) doesn't have
 "schg" flag set. A real solution is to protect the chflags call only if
 target exists, like we do in usr.bin/tip/tip/Makefile.

Requested by:	ru
2004-11-14 21:14:06 +00:00
Jens Schweikhardt
6ccc491b4b Avoid an (ignored) error by invoking chflags on the link target, not the
symlink.

PR:		kern/73016
Submitted by:	John E. Hein <jhein@timing.com>
MFC after:	1 week
2004-11-14 12:47:20 +00:00
John Baldwin
2939195e46 Remove these unused files before any other archs include the same bogus
file.
2004-11-12 18:05:30 +00:00
Peter Wemm
24b4ec3d21 The 32 bit compatability ld-elf32.so.1 cannot use i386_set_ldt() when
running on an amd64 kernel.  Use the recently exposed direct %fs/%gs set
routines instead for the TLS setup of 32 bit binaries.
2004-11-06 03:32:07 +00:00
Ruslan Ermilov
dee651eb15 Introduce the PRECIOUSPROG knob in bsd.prog.mk, similar
to PRECIOUSLIB from bsd.lib.mk.  The side effect of this
is making installing the world under jail(8) possible by
using another knob, NOFSCHG.

Reviewed by:	oliver
2004-11-03 18:01:21 +00:00
Suleiman Souhlal
6c2a9753f2 Implement TLS relocations for powerpc.
Approved by:	grehan (mentor)
2004-11-02 09:47:01 +00:00
Suleiman Souhlal
5bbd22ee8d Do the TLS offset allocations before relocations, as otherwise there
can be overlap in the TLS offsets, if the relocations are done in a
certain order.

Approved by:	dfr, grehan (mentor)
2004-11-02 09:42:21 +00:00
Ruslan Ermilov
a35d88931c For variables that are only checked with defined(), don't provide
any fake value.
2004-10-24 15:33:08 +00:00
Olivier Houchard
34be051190 Don't try to relocate the dynamic loader in reloc_non_plt(). It has already
been done before.
2004-09-28 14:43:12 +00:00
Olivier Houchard
0e030636cb Use add instead of saving the sp in a register. 2004-09-28 14:41:15 +00:00
Olivier Houchard
9ac88d19dc Add stubs for TLS.
Arbitraly choose the 2nd variant until I figure out which one I should use.
2004-09-23 23:04:52 +00:00
Doug Rabson
fca32c746e Add stubs for powerpc TLS.
Submitted by: ssouhlal
2004-08-04 19:12:14 +00:00
Doug Rabson
017246d02f Add support for Thread Local Storage. 2004-08-03 08:51:00 +00:00
Stefan Farfeleder
5908d366fb Consistently use __inline instead of __inline__ as the former is an empty macro
in <sys/cdefs.h> for compilers without support for inline.
2004-07-04 16:11:03 +00:00
Thomas Moestl
d05bb9a2a6 Fix the problem that surfaced with the new binutils import on sparc64
(and that is for now being worked around by a binutils patch).

The rtld code tested &_DYNAMIC against 0 to see whether rtld itself
was built as PIC or not. While the sparc64 MD code did not rely
on the preset value of the GOT slot for _DYNAMIC any more due
to previous binutils changes, it still used to not be 0, so
that this check did work. The new binutils do however initialize
this slot with 0. As a consequence, rtld would not properly initialize
itself and crash.
Fix that by introducing a new macro, RTLD_IS_DYNAMIC, to take the role
of this test. For sparc64, it is implemented using the rtld_dynamic()
code that was already there. If an architecture does not provide its
own implementation, we default to the old check.

While being there, mark _DYNAMIC as a weak symbol in the sparc64
rtld_start.S. This is needed in the LDSCRIPT case, which is however
not currently supported for want of an actual ldscript.

Sanity checked with md5 on alpha, amd64, i386 and ia64.
2004-06-18 02:01:37 +00:00
Olivier Houchard
45ab3f5350 This comment should have been removed in the previous commit.
Spotted out by: marcus, simon
2004-06-17 19:01:53 +00:00
Olivier Houchard
f77d42ce5c Woohoo !
the latest binutils import mades this gross hack useless, so just remove it.
2004-06-17 17:53:16 +00:00
Oliver Eikemeier
0a16eb8341 give out a little more information in case of a missing dependency
PR:		56549
Submitted by:	edwin
Reviewed by:	joerg, ru
Approved by:	joerg
MFC after:	2 weeks
2004-05-28 00:05:28 +00:00
Matthew N. Dodd
966efcc767 Support basename and path based constrained matches.
eg:
	[foo]
	...

	matches any executable 'foo'

	[/usr/bin/foo/]
	...

	matches any executable under the directory /usr/bin/foo/

Exact matches continue to function as before.

PR:		 bin/66769
Submitted-by:	 Dan Nelson
2004-05-24 01:24:13 +00:00
Olivier Houchard
3088daddf3 Work around a problem somewhere with binutils (?) on arm, hopefully without
breaking any other arch this time.
2004-05-15 00:13:14 +00:00
Stefan Eßer
55a4ccf3e8 Fix breakage caused by alphabetically sorting SRCS: rtld_start.S must come first!
The previous version made all shared binaries dump core.
2004-05-14 21:01:52 +00:00
Olivier Houchard
e659267f1e Import arm bits for rtld-elf.
Obtained from:	NetBSD
2004-05-14 12:15:51 +00:00
Doug Rabson
f88e6caca2 If we change obj_rtld.path after initialising __progname, make sure we
change __progname to point at the new storage otherwise it ends up
pointing at freed memory which leads to confusing garbled error messages.
2004-03-29 18:37:37 +00:00
Peter Wemm
c707fea10b More stack alignment fixes. Arrange so we call _rtld() in ld-elf.so.1
with the correct alignment.  This is important because this calls to
library static constructors are made from here.  The bug in the old crt*.s
files hid this because in this case, two wrongs do indeed make a right.
Also, call _rtld_bind() with the correct alignment, because it calls back
into the pthread library locking functions.  If things happen just
the wrong way, we get a SIG10 due to the broken stack alignment.
2004-03-21 01:43:39 +00:00
Peter Wemm
c905e45dc0 Add initial support for compiling a special 32 bit version of
ld-elf.so.1 on 64 bit systems.  Most of this involves using alternate
paths, environment variables and diagnostic messages.

The build glue is seperate.
2004-03-21 01:21:26 +00:00
Mark Murray
16fc3635f7 Make NULL a (void*)0 whereever possible, and fix the warnings(-Werror)
that this provokes. "Wherever possible" means "In the kernel OR NOT
C++" (implying C).

There are places where (void *) pointers are not valid, such as for
function pointers, but in the special case of (void *)0, agreement
settles on it being OK.

Most of the fixes were NULL where an integer zero was needed; many
of the fixes were NULL where ascii <nul> ('\0') was needed, and a
few were just "other".

Tested on: i386 sparc64
2004-03-05 08:10:19 +00:00
Alexander Kabaev
2627f3570d Do not depend on existence of _end symbol in obj_from_addr, use
obj->mapbase and obj->mapsize instead.

Prompted by: 	OpenOffice debugging session at last BSDCon.
2004-02-25 17:06:16 +00:00
Max Khon
6e918a4d5e Fix "warning: value computed is not used".
Found by:	gcc 2.95.4 [FreeBSD]
2004-02-03 18:53:40 +00:00
Doug Rabson
ae59481b1a Initialise some uninitialised variables.
Thanks to: valgrind
2003-12-31 15:10:41 +00:00
Peter Wemm
6143d8ba5f Fix dynamic linking a bit more.. enough that mozilla-firebird works if you
dig up the patches for amd64 support for it.

Note to self: do not put a 64 bit value in a 32 bit space.
2003-12-12 01:12:41 +00:00
Peter Wemm
080f5381b7 Revert last change. ../rtld.c uses CACHE_LINE_SIZE too.
Change it to 64 while here.

Reported by:  ps
2003-12-11 18:42:51 +00:00
Peter Wemm
165d50f626 Only define CACHE_LINE_SIZE in one place.. 2003-12-11 04:49:37 +00:00
Peter Wemm
40a7c81112 CACHE_LINE_SIZE is 64 on athlon and amd64 chips, not 32. This should
probably be 128 since that is what the hardware prefetch fill size is
on both the p3, p4 and athlon* cpus.
2003-12-11 04:47:53 +00:00
Anton Berezin
4893027ac4 Sync comment with code's reality.
MFC after:	1 week
2003-11-14 12:56:56 +00:00
Matthew N. Dodd
5515f48ce3 Retire the WITH_LIBMAP compile knob; libmap is now a standard feature. 2003-09-13 21:50:36 +00:00
Matthew N. Dodd
4402996dea Change libmap.c:lm_init() to return a status value; 0 for success
(libmap available) and 1 for failure.  Assign this return to the
global 'libmap_disable' variable in rtld.c.

This totally prevents any libmap functions from being called after
lm_init() if no config file is present.
2003-09-13 21:43:08 +00:00
Warner Losh
566ef09073 Very minor style nit: sort include files alphabetically. 2003-08-22 02:22:59 +00:00
Gordon Tetlow
df7bdd0ae9 Forgot one instance of ld-elf.so.1. Convert to ${PROG}
Pointed out by:	obrien
2003-08-17 22:12:26 +00:00
Gordon Tetlow
dbbcd515ff Don't forget to honor DESTDIR. Also switch over to using PROG instead of
the binary name directly.
2003-08-17 18:59:30 +00:00
Gordon Tetlow
a857d9305c Don't forget to chflags noschg the existing binary so we can symlink
over it safely.

Pointed out by:	yosimoto@waishi.jp
2003-08-17 18:50:56 +00:00
Gordon Tetlow
df7c0368c1 As long threatened, stage 2 of making a dynamically-linked root a reality.
Install rtld into /libexec.
2003-08-17 08:06:00 +00:00
Gordon Tetlow
7b73593acd Prepend /lib to the builtin library search path in rtld. 2003-08-17 07:55:17 +00:00
Jake Burkholder
d037213487 Avoid using the global offset table to get the address of _DYNAMIC in
rtld.  When _DYNAMIC is referenced normally from C the global offset
table is used implicitly, but newer versions of binutils don't initialize
it statically in the binary, so this doesn't work until rtld is relocated,
which _DYNAMIC is needed for...  So, as on other systems with the same
problem, we disassemble a call instruction to _DYNAMIC in order to get
its address.
2003-07-04 00:05:15 +00:00
Matthew N. Dodd
e2a474429e Fix warnings on 64 bit platforms.
Noticed by:	 jake
2003-06-19 16:09:18 +00:00
Matthew N. Dodd
5407dd5b82 Add function prototypes. 2003-06-19 05:28:26 +00:00
Matthew N. Dodd
ded0e52363 LD_DUMP_REL_PRE and LD_DUMP_REL_POST don't output to stderr; don't
claim that they do.
2003-06-19 04:34:09 +00:00
Matthew N. Dodd
c5d061c17a Provide a mechanism for dumping relocation information.
Setting the LD_DUMP_REL_PRE or LD_DUMP_REL_POST environment variables
cause rtld-elf to output a table of all relocations.

This is useful for debugging.
2003-06-19 03:55:38 +00:00
Matthew N. Dodd
94040887ee Move MD function prototypes together. 2003-06-19 02:42:04 +00:00
Matthew N. Dodd
2c297acb7a Fix warnings; no parameters in function prototypes. 2003-06-19 02:39:37 +00:00
Matthew N. Dodd
5952de4b1b Avoid a NULL pointer dereference. 2003-06-18 16:17:13 +00:00
Matthew N. Dodd
7227105f74 Include libmap.h for prototypes. 2003-06-18 05:31:08 +00:00
Matthew N. Dodd
da9f245470 - Add support for DT_FLAGS.
- Define various things from the most recent ELF spec.
2003-06-18 03:34:29 +00:00
Marcel Moolenaar
b615f6d2b1 Don't fail if we encounter a relocation of type "none". Just ignore
it. It's a no-op relocation.

Trigger case: ports/x11-toolkits/pango
2003-06-07 07:52:17 +00:00
David E. O'Brien
8f17707c61 Set CSTD to gnu99. We can only use on of the gnu?9 C languages.
We can't use c89 due to use of 'inline', and c99 produces bad code.
2003-06-04 05:42:04 +00:00
Ruslan Ermilov
09f84dd1d3 Assorted mdoc(7) fixes. 2003-06-02 15:02:06 +00:00
Matthew N. Dodd
c930fec7a2 - use issetugid()
- be paranoid about honoring LD_LIBMAP_DISABLE.

Suggested by:	 rwatson
2003-05-31 15:24:29 +00:00
Matthew N. Dodd
341b3de62b Simplify map_object() by breaking out the ELF header validation bits
into a separate function.
2003-05-31 14:48:59 +00:00
Matthew N. Dodd
1aac1ed634 Provide function entry debugging messages. 2003-05-31 14:46:38 +00:00
Matthew N. Dodd
4df60d1cac Use the environment variable LD_LIBMAP_DISABLE to disable
libmap.conf(5) functionality.
2003-05-31 14:45:11 +00:00
Matthew N. Dodd
1340fc1015 Don't post-increment pointers inside a loop conditional.
While I'm here:
- Let lm_add() call strdup() on its own behalf.
- Use a temporary pointer when parsing constraints; only set the
  constraint pointer on a totally successful match.

PR:		 bin/52783
Submitted by:	 David P. Reese Jr. <daver@gomerbud.com>
Approved by:	 re (rwatson)
2003-05-30 00:49:16 +00:00
Alexander Kabaev
6d5d786f80 Allow threading libraries to register their own locking
implementation in case default one provided by rtld is
not suitable.

Consolidate various identical MD lock implementation into
a single file using appropriate machine/atomic.h.

Approved by:	re (scottl)
2003-05-29 22:58:26 +00:00
Peter Wemm
9783a12b34 Initial pass at supporting shared libraries on amd64. There are still
a few missing relocation types in amd64/reloc.c, but I have not found
any of them in use yet. :-)

Approved by:  re (amd64/* blanket)
2003-05-24 17:37:51 +00:00
Matthew N. Dodd
3467e8b8a0 - Use xmalloc() and xstrdup() instead of malloc() and strdup().
- Add a global mapping if we have a successful constrained match.

Approved by:	re
2003-05-19 07:10:12 +00:00
Robert Watson
94deb3f034 Since libmap.conf is referenced in rtld.1, include it in the references
section.

Approved by:	re (scottl)
2003-05-17 19:46:49 +00:00
Ruslan Ermilov
60cdf2f1a0 mdoc(7) police: Normalize the FILES section.
Approved by:	re (blanket)
2003-05-16 21:34:21 +00:00
Alexander Kabaev
3ddc66d863 Rethink the way we count module references. Simply following
DT_NEEDED links is not flexible enough for cases where dynamically
loaded modules form a dependency cycle.

This should fix an infinite recursion problem encountered by Yahoo.

Approved by:	re (jhb)
2003-05-08 01:31:36 +00:00
David E. O'Brien
78af18bd24 Fix signed/unsigned comparison warnings. 2003-05-04 00:56:00 +00:00
Peter Wemm
7c1622ff28 Remove 80386 bandaids from code repocopied from i386. rtld_start.S still
todo.
2003-04-30 21:09:06 +00:00
Alexander Kabaev
486089f00c Remove redundant strlen checks, do not check the same
symbol twice.
2003-04-30 19:05:53 +00:00
Matthew N. Dodd
623b6bd2f9 Code cleanups and sanity checking for config file parser. 2003-04-10 01:44:19 +00:00
Matthew N. Dodd
29ade36225 Dynamic object dependency mapping: libmap.
This is an optional feature, disabled by default.

This will be useful to people testing the various POSIX threading
libraries under -CURRENT but can easily serve other needs.
2003-04-07 16:21:26 +00:00
Arun Sharma
35522a0aa1 Fix for ia64/48024 - ensure function pointer equality across elf
objects.

Programs such as sshd depend on two pointers to the same function being
equal in a given process. However, the current ia64 implementation
ensures that they're equal when both the pointers are instantiated in
the same ELF object. The attached patch ensures that they're equal
irrespective of where they're instantiated.

Reviewed by marcel@ (mentor) and kan@
2003-03-19 21:38:27 +00:00
Alexander Kabaev
63c1e7cb8d Free obj->priv field in obj_free functions. This field is NULL
on all architectures except ia64, which uses it to keep function
description table.
2003-03-14 21:11:28 +00:00
Alexander Kabaev
605f36fc1e No need to zero fill memory, mmapped anonymously. Kernel will
return pre-zeroed pages itself.

Noticed by:     jake
2003-03-14 21:10:13 +00:00
Alexander Kabaev
fa4a502e77 Do not remove object from the lists at the unref_dag() stage.
Introduce a new unlink_object() function and call it in
unload_object() instead. Removing the object in unref_dag() is
too early, rtld calls _fini() function after that and shared
objects might fail resolve their own symbols.
2003-02-17 20:58:27 +00:00
Alexey Zelkin
d9943f166b Advertize rtld(1) as ld.so(1) in manual pages world 2003-02-13 23:07:28 +00:00
Alexander Kabaev
2542b742f1 Fix a typo in rtld_dirname. 2003-02-13 22:47:41 +00:00
Alexander Kabaev
42d206e975 Implement dlinfo() function.
Introdice RTLD_SELF special handle and properly process it within
dlsym() and dlinfo() functions.

The intention is to improve our compatibility with Solaris and
to make a Java port easier.

Partially submitted by:	phantom
2003-02-13 17:47:44 +00:00
Alexander Kabaev
92b0ec0832 Add missing include files I forgot about in previous commit. 2003-02-13 17:35:00 +00:00
Alexander Kabaev
d38a104b75 Remove /usr/lib/elf from a default search path.
Move xprintf to malloc.c, it is only used there. Make static.

Submitted by:	phantom
2003-02-13 17:05:10 +00:00
Alexander Kabaev
f8d7256a27 When unloading dependencies make sure they are removed from all the
associated lists:
   remove RTLD_GLOBAL objects from global objects list;
   remove the parent object from dldags list of its children.

Previosly we were doing that only to the top-level object OF the DAG
being unloaded and all its dependencies were ignored, leading to
mysterious crashes later.

Submitted by:	peter (partially)
2003-02-10 23:15:07 +00:00
Matthew Dillon
fa7dd9c5bc Change the way ELF coredumps are handled. Instead of unconditionally
skipping read-only pages, which can result in valuable non-text-related
data not getting dumped, the ELF loader and the dynamic loader now mark
read-only text pages NOCORE and the coredump code only checks (primarily) for
complete inaccessibility of the page or NOCORE being set.

Certain applications which map large amounts of read-only data will
produce much larger cores.  A new sysctl has been added,
debug.elf_legacy_coredump, which will revert to the old behavior.

This commit represents collaborative work by all parties involved.
The PR contains a program demonstrating the problem.

PR:		kern/45994
Submitted by:	"Peter Edwards" <pmedwards@eircom.net>, Archie Cobbs <archie@dellroad.org>
Reviewed by:	jdp, dillon
MFC after:	7 days
2002-12-16 19:24:43 +00:00
Ruslan Ermilov
8d5d039f80 Uniformly refer to a file system as "file system".
Approved by:	re
2002-12-12 17:26:04 +00:00
Alexander Kabaev
f94cc7e9ca Fix rtld to handle SPARC_R_UA{16,64} relocations correctly.
Approved by:	re (rwatson)
2002-12-05 16:58:31 +00:00
Peter Grehan
b9dea67fa8 rtld support for PowerPC. Mostly obtained from NetBSD, with mods
for binutils 2.13

Reviewed by:  benno

Approved by:  re (blanket)
2002-12-04 07:32:20 +00:00
Alexander Kabaev
999d9d2bd4 Put back a test for binaries with no PT_LOAD entries I over-jealosly
removed in r1.69.

Apploved by:	re (rwatson)
2002-11-29 16:41:31 +00:00
Thomas Moestl
a42a42e9b9 Fix the handling of high PLT entries (> 32764) on sparc64. This requires
additional arguments to reloc_jmpslot(), which is why MI code and MD code
of other platforms had to be changed.

Reviewed by:	jake
Approved by:	re
2002-11-18 22:08:50 +00:00
Alexander Kabaev
8b7f25d41d Add support for binaries with arbitrary number of PT_LOAD sections.
Reviewed by:	peter
2002-10-23 01:43:29 +00:00
Alexander Kabaev
b2ce513208 Change the symbol lookup order to search RTLD_GLOBAL objects
before referencing object's DAG. This makes it possible for
C++ exceptions to work across shared libraries and brings
us closer to the search order used by Solaris/Linux.

Reviewed by:	jdp
Approved by:	obrien
MFC after:	1 month
2002-10-19 23:03:35 +00:00
Maxim Sobolev
d1cf9ea2c4 Fix a problem with RTLD_TRACE flag to dlopen(3), which sometimes can return
even if there was no error occured (when trying to dlopen(3) object that
already linked into executable which does dlopen(3) call). This is more
proper fix for `ldd /usr/lib/libc.so' problem, because the new behaviour
conforms to documentation.

Remove workaround from ldd.c (rev.1.32).

PR:		35099
Submitted by:	Nathan Hawkins <utsl@quic.net>
MFC after:	1 week
2002-10-19 10:18:29 +00:00
David E. O'Brien
b2bced0aef Use the new freebsd output format from Binutils 2.13.1. 2002-10-12 02:30:53 +00:00
Ruslan Ermilov
2908cc64eb <machine/atomic.h> requires <sys/types.h>.
Reviewed by:	jake, mike
2002-10-09 20:20:43 +00:00
Thomas Moestl
a4823075e5 Return an error if a symbol is not found in reloc_jmpslots() instead of
crashing.
2002-09-14 12:14:24 +00:00
Marcel Moolenaar
708bc7c7b4 Fix a nasty memory corruption bug caused by having a bogus pointer
for the DT_IA64_PLT_RESERVE dynamic table entry. When a shared object
does not have any PLT relocations, the linker apparently doesn't find
it necessary to actually reserve the space for the BOR (Bind On
Reference) entries as pointed to by the DTE. As a result, relocatable
data in the PLT was overwritten, causing some unexpected control flow
with annoyingly predictable outcome: coredump.
To reproduce:
	% echo 'int main() { return 0; }' > foo.c
	% cc -o foo foo.c -lxpg4
2002-08-22 03:56:57 +00:00
Warner Losh
7b5564b2ee Include stddef.h for NULL definition, rather than rolling our own here.
Reviewed by: jdp
2002-08-21 19:03:26 +00:00
Marcel Moolenaar
ecfdc2e0cd Add support for the R_IA64_IPLTLSB relocation in non-PLT context.
This relocation creates a function descriptor at the specified
address and is commonly used for C++ to create virtual function
tables.
2002-08-20 00:24:33 +00:00
John Polstra
0df23e4bd5 Don't acquire the writer lock in rtld_exit when clearing the shared
objects' reference counts.  This function is called by the atexit
mechanism at program shutdown.  I don't think the locking is necessary
here.  It caused OpenOffice builds to hang more often than not.
Credit to Martin Blapp and Matt Dillon for helping to diagnose this
problem and for testing the fix.
2002-08-08 15:53:23 +00:00
Jake Burkholder
b1d6ef2ee9 Add END markers to asm functions so that debuggers can find their size. 2002-07-17 22:20:41 +00:00
John Polstra
e6f0183bff Remove the nanosleep calls from the spin loops in the locking code.
They provided little benefit (if any) and they caused some problems
in OpenOffice, at least in post-KSE -current and perhaps in other
environments too.  The nanosleep calls prevented the profiling timer
from advancing during the spinloops, thereby preventing the thread
scheduler from ever pre-empting the spinning thread.  Alexander
Kabaev diagnosed this problem, Martin Blapp helped with testing,
and Matt Dillon provided some helpful suggestions.

This is a short-term fix for a larger problem.  The use of spinlocking
isn't guaranteed to work in all cases.  For example, if the spinning
thread has higher priority than all other threads, it may never be
pre-empted, and the thread holding the lock may never progress far
enough to release the lock.  On the other hand, spinlocking is the
only locking that can work with an arbitrary unknown threads package.

I have some ideas for a much better fix in the longer term.  It
would eliminate all locking inside the dynamic linker by making it
safe for symbol lookups and lazy binding to proceed in parallel
with a call to dlopen or dlclose.  This means that the only mutual
exclusion needed would be to prevent multiple simultaneous calls
to dlopen and/or dlclose.  That mutual exclusion could be put into
the native pthreads library.  Applications using foreign threads
packages would have to make their own arrangements to ensure that
they did not have multiple threads in dlopen and/or dlclose -- a
reasonable requirement in my opinion.

MFC after:	3 days
2002-07-06 20:25:56 +00:00
Philippe Charnier
3f162cb85d The .Nm utility 2002-07-06 19:19:48 +00:00
John Polstra
d1c02bccdc Update the asm statements to use the "+" modifier instead of
matching constraints where appropriate.  This makes the dynamic
linker buildable at -O0 again.

Thanks to Bruce Evans for identifying the cause of the build
problem.

MFC after:	1 week
2002-06-24 23:19:18 +00:00
Jake Burkholder
cf85da5c68 Add needed include of mman.h to fix sparc64 buildworld. 2002-06-24 05:23:46 +00:00
Matthew Dillon
b6801e6b54 The last bits of the alloca -> mmap fix. IA64 and SPARC64 (current only).
Untested (testing request went unanswered), but sparc64 is not expected to
cause problems.  IA64 is not expected to cause problems but the patch was
slightly more complex so the possibility exists.

Approved by:    jdp
2002-06-22 18:36:21 +00:00
Matthew Dillon
eebf98659e This is the same alloca() fix as was committed for i386. David O'Brien
tested the patch on -stable.

Reviewed by:	obrien
Approved by:	jdp
MFC after:	3 days
2002-06-18 05:42:33 +00:00
John Polstra
5f8aa32e1b Dillon's recent commits to the dynamic linker without running them
by me first have given me a good excuse to drop my MAINTAINERship.

MFC after:	1 week
2002-06-10 21:51:16 +00:00
Matthew Dillon
b08440e568 Correct a bug in the last commit. The whole point of creating a 'done:'
goto target was so the cache could be freed.  So free the cache after
done: rather then before done: (!)

Submitted by:	Gavin Atkinson <gavin@ury.york.ac.uk>
2002-06-10 21:15:50 +00:00
Matthew Dillon
b603db3019 In tracking down an installation seg fault with then openoffice port
Martin Blapp determined that the elf dynamic loader was at fault.  In
particular, the loader uses alloca() to allocate a symbol cache on the
stack.  Normally this would work just fine, but if the loader is called
from a threaded program and the object being loaded is fairly large the
alloca() can blow away the thread stack and effect other nearby thread
stacks as well.  My testing showed that the symbol cache can be as large
as 250KBytes during the openoffice port build and install sequence.  Martin
was able to work around the problem by disabling the symbol cache
(cache = NULL;).  However, this solution is not adequate for commit because
it can cause an enormous cpu burden for applications which do a lot of
dynamic loading (e.g. like konqueror).

The solution is to use anonymous mmap() to temporarily allocate space to
hold the symbol cache.  In testing I found that replacing the alloca()
with mmap() has no observable degredation in performance.

It should be noted that this bug does not necessarily cause an immediate
crash but can instead result in long term corruption and instability in
applications that load modules from threads.  The bug is almost certainly
responsible for some of the instabilities found in konqueror, for example,
and possibly netscape too.

Sleuthing work by: Martin Blapp <mb@imp.ch>
X-MFC after:	Before or after the 4.6 release depending on the release engineers
2002-06-10 18:52:31 +00:00
Marcel Moolenaar
5c8e25383a Include machine/ia64_cpu.h because we use ia64_mf().
Submitted by: ru
2002-05-21 00:04:08 +00:00
Marcel Moolenaar
2aba02382e Fix handling of weak references to undefined symbols on ia64:
o  Set st_shndx for sym_zero to SHN_UNDEF instead of SHN_ABS.
   This gives us something to reliably test against.
o  For weak references to undefined sysmbols (as indicated by
   having st_shndx equals SHN_UNDEF) in the context of OPDs,
   the address of the OPD is to be zero, not the address of
   the function it contains.
o  For weak references to undefined symbols in all other cases
   (only DIR64LSB at this time), the actual relocated value is
   to be zero, not the value prior to relocating.

Roughly speaking, weak references to undefined symbols are no-ops.

Tested on: i386, ia64
2002-04-27 05:32:51 +00:00
Marcel Moolenaar
c7e3bd1ce6 Now that local symbols aren't looked up with the symbol hash table,
binding works for local symbols. Remove the workaround...
2002-04-27 02:53:31 +00:00
Marcel Moolenaar
9d4f27148f Don't do symbol lookups for local symbols. The symbol index in the
relocation identifies the symbol to which we need to bind. This
solves a problem seen on ia64 where the symbol hash table does not
contain local symbols and thus resulted in unresolved symbols.

Tested on: alpha, i386, ia64
2002-04-27 02:48:29 +00:00
Peter Wemm
968253905e Fix a relocation bug in the ia64 ld.so. Weak function pointers in shared
objects were not being correctly set to zero.  Instead, the function
descriptor pointer was set to the load address of the .so object.  This
caused gcc generated binaries to segfault on exit when crtbegin.asm's
_fini code tested the __cxa_finalize() function pointer for zero.

This is a bit of a hack because of a problem nearby workaround for
find_symdef and its quirks (failures) for local symbols.  This still
needs to be fixed.
2002-04-07 04:16:35 +00:00
Jake Burkholder
2da08e795e Minor changes to make this work on sparc64.
Approved by:	jdp
Tested on:	alpha, i386, sparc64
2002-04-02 02:19:02 +00:00
Jake Burkholder
e4c9dc6770 rtld support for sparc64.
Largely obtained from:	netbsd
Submitted by:	jake, tmm
2002-03-13 02:40:39 +00:00
Dag-Erling Smørgrav
e211585c77 When searching an object that was opened with RTLD_GLOBAL, search its DAG too.
PR:		bin/25059
Approved by:	jdp
MFC after:	3 weeks
2002-02-27 23:44:50 +00:00
Peter Wemm
939bc65715 ld-elf.so.1 assumed a few too many things about the ordering of sections
produced by ld(8) (ie: that _DYNAMIC immediately follows the _GOT).
The new binutils import changed that, and the intial GOT relocation
broke.  Use a custom linker script to provide a real end-of-GOT symbol.

Update ld.so to deal with the new (faster) PLT format that gcc-3.1 and
binutils can produce.

This is probably incomplete, but appears to be working again.

Obtained from:  NetBSD
(And a fix to a silly mistake that I made by:  gallatin)
2002-02-18 02:24:10 +00:00
David E. O'Brien
2024994319 Add support such that if LD_TRACE_LOADED_OBJECTS_ALL is defined to a
non-empty string in the environment; we indicate which objects caused
each object to be loaded.

PR:		30908
Submitted-by:	Mike Meyer <mwm@mired.org>
2002-02-17 07:04:32 +00:00
Maxim Sobolev
c6de4ce791 Allow ldd(1) be used on shared libraries in addition to executables. 2002-02-04 10:33:48 +00:00
Kris Kennaway
8f23d50652 Mark a function as __printflike()
MFC after:	1 week
2002-02-04 01:41:35 +00:00
John Polstra
a7dcaa3441 Change the library search order so that LD_LIBRARY_PATH overrides
all others.

PR:		bin/28191
MFC after:	2 weeks
2002-01-25 16:35:43 +00:00
David Malone
98d1592458 Change brk's prototype from char *brk(const char *) to int brk(const void *)
and sbrk's prototype from char *sbrk(int) to void *sbrk(intptr_t).

This makes us more consistant with NetBSD and standards which include
these functions. Bruce pointed out that ptrdiff_t would probably
have been better than intptr_t, but this doesn't match other
implimentations.

Also remove local declarations of sbrk and unnecessary casting.

PR:		32296
Tested by:	Harti Brandt <brandt@fokus.gmd.de>
MFC after:	1 month
2002-01-24 12:11:31 +00:00
Ruslan Ermilov
bcf2b1b312 mdoc(7) police: tidy up. 2002-01-10 17:49:57 +00:00
Peter Wemm
14a55adf36 Update rtld for the "new" ia64 ABI. In the old toolchain, the
DT_INIT and DT_FINI tags pointed to fptr records.  In 2.11.2, it points
to the actuall address of the function.  On IA64 you cannot just take
an address of a function, store it in a function pointer variable and
call it.. the function pointers point to a fptr data block that has the
target gp and address in it.  This is absolutely necessary for using
the in-tree binutils toolchain, but (unfortunately) will not work with
old shared libraries.  Save your old ld-elf.so.1 if you want to use
old ones still.  Do not mix-and-match.

This is a no-op change for i386 and alpha.

Reviewed by:	dfr
2001-10-29 10:10:10 +00:00
Peter Wemm
d4cf88ddc4 Fix a dependency violation (branch after alloc) 2001-10-29 10:05:32 +00:00
Doug Rabson
b5393d9f78 Add ia64 support. Various adjustments were made to existing targets to
cope with a few interface changes required by the ia64. In particular,
function pointers on ia64 need special treatment in rtld.
2001-10-15 18:48:42 +00:00
Doug Rabson
97571220e2 The support for accelerating find_symdef() with a cache was broken. This
fixes the problem and improves startup times for large applications such
as KDE2 considerably.

Reviewed by:	jdp
MFC after:	1 week
2001-10-10 07:15:01 +00:00
Ruslan Ermilov
c4d9468ea0 mdoc(7) police:
Avoid using parenthesis enclosure macros (.Pq and .Po/.Pc) with plain text.
Not only this slows down the mdoc(7) processing significantly, but it also
has an undesired (in this case) effect of disabling hyphenation within the
entire enclosed block.
2001-08-07 15:48:51 +00:00
Sheldon Hearn
e1b4d8d074 Use STD{ERR,IN,OUT}_FILENO instead of their numeric values. The
definitions are more readable, and it's possible that they're
more portable to pathalogical platforms.

Submitted by:   David Hill <david@phobia.ms>
2001-07-26 11:02:39 +00:00
Ruslan Ermilov
0efe23d669 mdoc(7) police: removed HISTORY info from the .Os call. 2001-07-10 10:49:54 +00:00
Dima Dorfman
70d51341bf mdoc(7) police: remove extraneous .Pp before and/or after .Sh. 2001-07-09 09:54:33 +00:00
Ruslan Ermilov
5521ff5a4d mdoc(7) police: sort SEE ALSO xrefs (sort -b -f +2 -3 +1 -2). 2001-07-06 16:46:48 +00:00
Ruslan Ermilov
4cf39050cc Use new backup feature of install(1). 2001-05-28 16:58:35 +00:00
John Polstra
c15e7faad5 Performance improvements for the ELF dynamic linker. These
particularly help programs which load many shared libraries with
a lot of relocations.  Large C++ programs such as are found in KDE
are a prime example.

While relocating a shared object, maintain a vector of symbols
which have already been looked up, directly indexed by symbol
number.  Typically, symbols which are referenced by a relocation
entry are referenced by many of them.  This is the same optimization
I made to the a.out dynamic linker in 1995 (rtld.c revision 1.30).

Also, compare the first character of a sought-after symbol with its
symbol table entry before calling strcmp().

On a PII/400 these changes reduce the start-up time of a typical
KDE program from 833 msec (elapsed) to 370 msec.

MFC after:	5 days
2001-05-05 23:21:05 +00:00
David E. O'Brien
5e6220d9d0 * include/elf.h has been repo copied to include/elf-hints.h, and it no
longer includes machine/elf.h.
* consumers of elf.h now use the minimalist elf header possible.

This change is motivated by Binutils 2.11.0 and too much clashing over
our base elf headers and the Binutils elf headers.
2001-05-02 23:56:21 +00:00
Ruslan Ermilov
e5b5c66bca - Backout botched attempt to intoduce MANSECT feature.
- MAN[1-9] -> MAN.
2001-03-26 14:22:12 +00:00
Ruslan Ermilov
896eb7d10c Prepare for mdoc(7)NG. 2001-01-16 09:15:57 +00:00
John Polstra
27e2c03506 Fix a bug in which a program called dlclose from a destructor and
got an assert failure in the dynamic linker.
2001-01-05 04:36:17 +00:00
Ruslan Ermilov
58eaff2332 Prepare for mdoc(7)NG. 2000-12-20 13:26:01 +00:00