Commit Graph

49 Commits

Author SHA1 Message Date
kamil f3656ffa1a Upgrade the SVR4 RTLD r_debug protocol to version 1
Changes:
 - Add a new field r_ldbase in the r_debug struct.
 - Set r_version to 1.

This harmonizes the support with OpenBSD and Linux.
FreeBSD uses version 0 (or no version).
Solaris uses version 2 that is not implemented elsewhere and relies on
SVR4 specific design and interfaces.

Update the code comments as r_debug and link_map is used by other software
than GDB, namely: sanitizers, rump, LLDB.
2020-09-21 16:08:57 +00:00
christos a80110f6b6 need <sys/stat.h> 2017-01-10 21:08:48 +00:00
christos 5fbbc292aa CID 1132773: Fix file descriptor leak 2013-11-27 18:01:33 +00:00
skrll 03ee7fc3bc If dlopen of the dynamic linker is requested, e.g. by rump in
rumpuser_dl_bootstrap, then return &_rtld_objself as the handle and do
not create a duplicate mapping.

The handle is mostly useless as _rtld_objself doesn't appear on
_rtld_objlist.

This fixes a problem on earm platforms where ld.elf_so (currently) has
an init_array section.  Calling this caused binaries to segv.
2013-11-20 07:18:23 +00:00
christos a3f195d87d Fix refcount of the object we found in our list by name. 2013-05-09 15:37:58 +00:00
christos a3fedff4d1 Fixed handling of DT_SONAME:
- add function to add name aliases for shared libraries loaded
	  XXX[1]: we don't add a name during load time, only when DT_SONAME
	  is present.
	- search already loaded objects in load_by_name for an already
	  loaded object that matches our name and return it.
	- add missing initialization and cleanup for obj->names
	  XXX[2]: should we make them SIMPLEQ?
	- Add XXX in rtld.c about getting the name of an object.

NB: This makes the jdk work again without resorting to a hack of putting
    the build path of libjvm.so into the run path (which is a security
    problem).
XXX: Pullup-6?
2013-05-06 19:59:29 +00:00
skrll b49eab8ee4 Trailing whitespace 2013-05-06 08:02:20 +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 126c589398 s/rdbg/dbg/ in a few places. 2010-12-16 19:59:39 +00:00
skrll 76d5f138f4 Remove incorrect comment. 2010-12-16 19:35:38 +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 b02ec7e9f8 Implement negative cache checks for symbol lookups.
Uses the Donelist idea from FreeBSD.
2010-02-27 11:16:38 +00:00
christos fa64a5bf9b warns=4 2009-05-19 20:44:52 +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
cube f7779133cd Don't remove the last component of filename before calling
_rtld_digest_dynamic:  it is done in expand(), and doing it twice is once
too much.  This fixes $ORIGIN expansion for dependencies.
2007-09-20 07:50:32 +00:00
christos 04ee85ad50 Support Solaris-like $ORIGIN etc. expansions in paths. 2007-05-18 21:44:08 +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
matt ba8a81077b Fix some double frees / missing frees / use after freed all
relating to _rtld_load_object.  Fix Coverity CID 2601, 2600.
2006-03-18 02:34:30 +00:00
skrll 2728318e3c Add __RCSIDs.
OK'd by mycroft.
2004-10-22 05:39:56 +00:00
cube d1b3d841ee Make ld.elf_so use the new sysctl API. That allows the user to give any
sysctl variable name in /etc/ld.so.conf.  It also makes the ld.elf_so
binary slightly smaller (at least on i386), and has no impact on
performance.

Fixes PR 26100.
2004-07-05 11:50:07 +00:00
christos 1a2b5965a9 Don't try to preload an empty string. 2003-11-25 14:36:49 +00:00
skrll 5f573ab68d ANSIfy and de-__P(). 2003-07-24 10:12:25 +00:00
junyoung fd1f5e8f1b A bit speedup: in _rtld_load_object(), save the number of calls to
strcmp() by performing path name length comparison first. In the test
with Mozilla, the number was reduced to 1068 from 7182 (yes, we saved
6114 strcmp()!).
2002-12-05 04:56:56 +00:00
mycroft ad8ccd6290 Minor cleanup. 2002-10-05 11:59:03 +00:00
mycroft 0a519951b5 Pull out some objlist functions in ldd. 2002-10-04 04:04:26 +00:00
mycroft 3c57a33db5 Don't actually bother maintaining _rtld_list_main and _rtld_list_global in
ldd.
2002-10-04 04:01:13 +00:00
mycroft dfaba15604 Move the definition of _rtld_list_main so ldd builds again. 2002-10-04 03:59:40 +00:00
mycroft 7a48cdb883 As seen on tech-userlevel...
There are several optimizations here:

1) Objects on _rtld_list_main do not participate in the DAG structures
   at all.  This is okay because all symbols must be resolvable at
   link/load time, and _rtld_list_main is always searched first, so
   any references from those objects must necessarily be resolved to
   other objects on _rtld_list_main.

   (Making this work completely required setting obj->main a bit
   earlier; hence the RTLD_MAIN hack.)

2) Objects on _rtld_list_main are not put on _rtld_list_global,
   preventing an extra search.

3) A bit is used to keep track of whether an object is on
   _rtld_list_global, so we don't have to do a silly linear search.

4) A small attempt is made to prevent objects being put on the DAG
   lists multiple times (using a silly linear search).

The sum of this appears to be a ~10% (.3s) reduction in Mozilla's
startup time on my 800MHz box.

Also, make sure _rtld_objmain->path is always set, just to make the
debug output nicer.
2002-10-03 20:35:19 +00:00
mycroft 86103e2f0e Several small changes that shave 7-8% off the simple-exec-loop test:
* Rename _rtld_find_library() to _rtld_load_library().  It now calls
  _rtld_load_object() if necessary to actually load the object, rather
  than having the caller do it.  To do this, it also takes the `mode'
  argument that gets passed to _rtld_load_object().

* On a related note, remove _rtld_check_library(), and instead call
  _rtld_load_object() to instead try actually loading the object.  We
  save two extra namei's and a bunch of redundant work (almost
  literally the same code) this way.

* In _rtld_map_object(), mmap(2) the first page read-only, rather than
  read(2)ing it.

* In _rtld_symlook_obj(), compare the *second* character of the symbol
  name before calling strcmp().  (This first character is too
  frequently `_', and turns out to not be helpful, in libc.)

* Also in _rtld_symlook_obj(), remove the bogus STT_FUNC special case
  -- this also allows removing the `in_plt' argument to
  _rtld_symlook_list() and _rtld_symlook_obj().

Also:

* In _rtld_obj_from_addr(), rather than trying to look up `_end' in
  the each object, instead use obj->mapsize as the upper bound.
2002-09-23 23:56:46 +00:00
mycroft a3b892d178 Nuke -DRTLD_RELOCATE_SELF and `dodebug' from orbit. 2002-09-12 22:56:28 +00:00
abs c2fcad8607 If /etc/ld.so.conf contains an invalid sysctl name any dynamically
executable that uses the library on that line has the rather cryptic
"sysctl" printed when it starts executing.

Switch to (_PATH_LD_HINTS": unknown sysctl for %s", name);

Discovered after someone copied /etc from an i386 to a sparc64 box.
2002-07-18 14:46:11 +00:00
lukem 06de426449 SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field).  whilst it's O(n),
  this mirrors the functionality of SLIST_REMOVE() (the other
  singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
  this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
  singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
2002-06-01 23:50:52 +00:00
skrll aabfabf3e7 Allow both space and colon as a separator in LD_PRELOAD. Document this and
the fact that space may be retired in the future.

Closes misc/11961

Reviewed by christos
2001-11-02 15:28:36 +00:00
christos 7ddeec7d69 s/warn/xwarnx/ cuts down size by 50% by not pulling in stdio. 2001-05-27 23:26:47 +00:00
mycroft 0581ae5bad Make ldd(1) build again. 2000-11-10 23:53:04 +00:00
mycroft 2d376bed2b When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL. 2000-11-10 21:31:30 +00:00
christos 3856850e36 don't stutter when printing error messages. 1999-12-27 15:36:36 +00:00
christos 4374b52ab0 make a debugging formatting statement work portably 1999-12-15 20:13:31 +00:00
christos f0e72d450d Do what the people want. Support full sysctl names. 1999-12-15 05:22:37 +00:00
christos 75bdf8c379 indent properly a debugging statement and fix grammar. 1999-12-13 10:47:38 +00:00
christos aa594cf123 For the benefit of ldd and debuggers, append more Needed_Entry elements
if the library transformation attached more than one element.
1999-12-13 09:22:52 +00:00
christos ea816c78b2 Enable parsing and mapping of hardware dependent libraries in ld.so.conf
To be documented in the man page.
1999-12-13 09:09:34 +00:00
mycroft 305c949781 Changes from msaitoh to fix local/global symbol confusion, and to fix weak
symbol support -- updated by me for elf.h changes.
1999-11-07 00:21:12 +00:00
kleink 8b74e6d78e Implement LD_PRELOAD support. 1999-05-31 14:48:16 +00:00
christos 26475619ed KNF 1999-03-01 16:40:07 +00:00
christos 84cb65780e Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.
1999-02-24 18:31:00 +00:00
cgd 41fe218b25 First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.).  This runs, but it's
in serious need of cleaning and/or a fair bit of reworking.  See the README
file for more information, and a list of things to do.
1996-12-16 20:37:55 +00:00