Commit Graph

139 Commits

Author SHA1 Message Date
joerg aad599979d Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
2011-03-09 23:10:05 +00:00
pooka 33ee52c7dc make DEBUG compile without RTLD_DEBUG 2011-02-24 10:58:54 +00:00
skrll f1d73a2c94 Add support for DF_1_BIND_NOW, DF_1_NODELETE and DF_1_NOOPEN marked
objects, and the RTLD_NODELETE and RTLD_NOLOAD flags to dlopen(3).

Mark libpthread as DF_1_NOOPEN and use it to test the functionality.

Somewhat taken from FreeBSD.

Fixes PR 42029.

OK from christos and joerg.
2010-12-24 12:41:42 +00:00
skrll 1f45aab781 Sprinkle some KNF. 2010-12-19 17:26:51 +00:00
skrll ad7786ec8b Remove unnecessary #ifdef RTLD_DEBUG 2010-12-19 17:17:50 +00:00
joerg 67cc8c0871 Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.
2010-12-16 22:47:27 +00:00
skrll 126c589398 s/rdbg/dbg/ in a few places. 2010-12-16 19:59:39 +00:00
christos acfd35dad9 PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.
2010-10-29 15:08:17 +00:00
skrll e6cdac9c4b Implement dl_iterate_phdr.
Somewhat taken from FreeBSD. Manual page from OpenBSD.
2010-10-16 10:27:06 +00:00
roy d5e8f757b8 Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.
2010-03-18 22:17:55 +00:00
roy b02ec7e9f8 Implement negative cache checks for symbol lookups.
Uses the Donelist idea from FreeBSD.
2010-02-27 11:16:38 +00:00
skrll fa7832d0b1 Fixup comment. 2010-01-10 06:37:32 +00:00
christos 1dc0b61eca If the environment is corrupt, die. From FreeBSD. 2009-12-02 15:50:13 +00:00
skrll 77fd7698f3 Make _rtld_pagesz of type size_t.
Fixes round_down for alpha which made ldd(1) break.
2009-11-17 18:44:33 +00:00
pooka 4c1e54d82b Add Solarisa-like dlinfo() interface to the ELF dynamic linker.
Implement RTLD_DI_LINKMAP which returns a pointer to the linkmap
chain at the given object.  Other Solaris queries are currently
unimplemented.
2009-09-24 21:21:33 +00:00
christos fa64a5bf9b warns=4 2009-05-19 20:44:52 +00:00
mrg 8679e33545 if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
  builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.
2008-10-26 07:11:54 +00:00
skrll 8c9056ada8 lib/39649: dlsym(3) does not follow dependencies
Pull across code from FreeBSD to do a search of the passed object and it's
NEEDED objects (dependencies).

Reviewed by gimpy.
2008-10-04 09:37:12 +00:00
macallan 982ae38f15 avoid usind __builtin_return_address(0) on PowerPC because it fails in
Xorg's module loader.
Should fix PR37812
2008-09-27 03:52:05 +00:00
matt 38bdc8954f Refactor common code to _rtld_relocate_plt_object to i386 and arm so they
act like the other versions.
In _rtld_bind, if the result is 0, call _rtld_die.
Initialize _rtld_sym_zero.st_value to -_rtld_objself.maprelocbase.  Now when
the symbol is resolved, st_value + maprelocbase will equal 0 and the above
check in _rtld_bind will fire and a call to NULL will be avoided.
2008-07-24 04:39:25 +00:00
christos d3b459e727 abort() if we are trying to use an undefined weak symbol from the plt. Remove
check from relocate_plt_object() since we cannot return _rtld_sym_zero anymore.
Code from gimpy.
2008-07-23 18:16:42 +00:00
ad 53c5ea5da9 Don't bother unmapping the ELF header unless it overlaps the first load
section.
2008-06-03 19:32:32 +00:00
ad 558a5ffd0f rtld changes for PR bin/37347:
- Apply patch from J.T. Conklin to execute .init/.fini functions in order.
- Support DF_1_INITFIRST and mark libc with DF_1_INITFIRST. Shared libs
  should be recording a dependency on libc, but it's too late to do that.

Ok christos@.
2007-12-07 20:34:04 +00:00
ad bf4b000d16 - Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
  error again (from joerg@).

Ok christos@.
2007-10-05 22:21:07 +00:00
christos 6f875d32e2 Don't trust AT_SUN_EXECNAME, if we are set{u,g}id. 2007-09-21 13:57:09 +00:00
christos 40cfdb5e3a Use AT_SUN_EXECPATH instead of argv[0] for the executable name. This needs
kernel support, which is not there yet, thus $ORIGIN is broken at this time.
This is ok, nothing uses it yet.
2007-09-20 14:14:25 +00:00
christos 04ee85ad50 Support Solaris-like $ORIGIN etc. expansions in paths. 2007-05-18 21:44:08 +00:00
scw 596a371d09 Remove a test for defined(__SH5__). 2007-04-08 10:02:35 +00:00
christos aac134252a From defend dot the dot world at gmail dot com: Sanitize environment variables
for set{u,g}id binaries, so that in case they are playing with set{u,g}id
and exec'ing other binaries they don't get affected by the
LD_{PRELOAD,DEBUG,LIBRARY_PATH} environment setup. We leave LD_BIND_NOW alone.
There are no binaries affected in the base system.
2006-11-22 21:46:36 +00:00
christos 0339fe6614 Coverity CID 2749: Fix another double free. Instead of removing that last
free() call, change the allocation policy to leave the responsibility for
allocation/freeing the pathname to _rtld_map_object(), instead of having
the caller allocate it and _rtld_map_object() free it. This simplifies the
code a lot and it is more efficient.
2006-03-21 17:48:10 +00:00
skrll 39aae79d93 Bring across a change from FreeBSD from back in 1998:
"Fix a bug that showed up when debugging dynamically linked programs.
References from GDB to "printf" and various other functions would
find the versions in the dynamic linker itself, rather than the
versions in the program's libc.  This fix moves the GDB link map
entry for the dynamic linker to the end of the search list, where
its symbols will be found only if they are not found anywhere else."

"printf" isn't true for us, but various libc symbols are, e.g. "malloc".

Fixes PR 32074 as noted by uwe@

OK'd by christos@
2006-01-12 22:40:17 +00:00
uwe b98cf46363 _GLOBAL_OFFSET_TABLE_ is only used if RTLD_DEBUG, so wrap its
declaration too.

32-bit SuperH can not pretend that _GLOBAL_OFFSET_TABLE_ is a normal
variable, because of the way PIC variable references is generated, but
as compiler arranges for _GLOBAL_OFFSET_TABLE_ address to be in r12
anyway, just use that value by declaring it as a global register
variable.  Makes sh3 compile with RTLD_DEBUG.
2006-01-11 21:40:12 +00:00
skrll 2728318e3c Add __RCSIDs.
OK'd by mycroft.
2004-10-22 05:39:56 +00:00
thorpej 2a63e04007 - Change the strong dlfcn names in libc to ___name, and make the __name
versions used by others in libc weak, so that we have:
	name: weak
	__name: weak
	___name: strong
- Add __name strong aliases of the dlfcn names in ld.elf_so, so that we have:
	name: strong
	__name: strong

This allows ld.elf_so to self-resolve both the name and __name variants
of the dlfcn functions, the former being required for dlfcn support in
applications, the latter being required for dlfcn support in libc.

Fixes the problem described in:

    http://mail-index.netbsd.org/tech-toolchain/2004/07/17/0000.html

Reviewed by Nick.
2004-07-18 17:26:19 +00:00
skrll 701ae47cdf Fix the dynamic linker for hppa using ELF.
Lazy binding doesn't work 100% of the time so force immediate binding.
One possible reason is that the PLT stub blows away r20 which the
compiler might not take into account.
2004-05-17 13:16:02 +00:00
skrll e88c851d08 Test before commit. 2004-05-17 11:00:01 +00:00
skrll 0556cd7d3c Re-arrange/correct some asserts. 2004-05-17 10:23:58 +00:00
skrll 212b905081 Garbage collect the RTLD_RELOCATE_SELF error. 2004-05-12 20:23:29 +00:00
mycroft 5bd33bcad6 Back out revision 1.100. There is something screwier going on. 2003-09-07 22:17:43 +00:00
mycroft 323a574dc3 dlsym() should not leave an error set. It confuses programs that check
dlerror() (such as pkgsrc/graphics/transcode).
2003-08-31 21:52:01 +00:00
skrll d900731978 Resolve dlsym(3) and friends directly so that dlsym(RTLD_NEXT,...) works.
Previously dlsym resolved to the version in crt0.o or libc which would
mean that the caller's shared object couldn't be determined correctly
using __builtin_return_address(0).

Mainly from FreeBSD, but adapted by me. Benefits of this solutions are:

	- backward comptibility maintained
	- existing broken binaries are fixed with a new ld.elf_so
	- __mainprog_obj can be removed from crt0.o
	- we do the same thing as FreeBSD

Fixes PR 22067.

OKed by Jason and Christos.
2003-08-12 09:18:38 +00:00
skrll 5f573ab68d ANSIfy and de-__P(). 2003-07-24 10:12:25 +00:00
skrll b2695e5a1f arm and sh5 also have bogus DT_TEXTRELs. sh5 was already covered so just
update the comment.
2003-07-21 15:17:55 +00:00
skrll 619dee76f6 Correct the in_plt parameter of a couple of _rtld_find_symdef calls.
The mips_reloc.c case is a no-op as _rtld_symlook_obj ignores in_plt for
MIPS.

OK'ed by Charles.
2003-07-17 13:56:32 +00:00
marcus 5404577abf SH also has a bogus DT_TEXTREL, it seems. 2003-06-30 00:49:25 +00:00
simonb a9f5b3f871 KNF- blank lines before code at start of functions. 2003-06-05 10:41:32 +00:00
christos 683092605c Add RTLD_FIRST, RTLD_NEXT, RTLD_DEFAULT, from FreeBSD 2003-05-30 15:43:33 +00:00
mycroft f57f7ac072 Back out previous change for now -- it needs more work. 2003-04-24 16:55:29 +00:00
mycroft 8826c5e475 Attempt to give dlsym() the same symbol-searching semantics as _rtld_bind().
Tested in a handful of cases.
Reviewed by: a dead silence
2003-04-23 17:40:25 +00:00
junyoung 8707cd2a36 Gracefully exit when invoked directly. Use of assert() here caused a segfault.
Address PR#11785.
2002-12-14 15:37:57 +00:00