glibc/elf/dl-open.c
Ulrich Drepper 57ba7bb471 update from main archive 960904
Thu Sep  5 03:20:42 1996  Ulrich Drepper  <drepper@cygnus.com>

	Change configuration and Makefiles to allow add-ons to have a
	sysdeps/ directory hierachy.
	* configure.in: Test for sysdeps/ directory in add-ons.  Before
	all test and searches in these hierachies, too.
	* Makeconfig (full-config-subdirs): Define based on $(config-sysdirs).
	Extend with $(..) if not absolute path.
	Use $(full-config-subdirs) where $(config-sysdirs) was used.
	* Makefile ($(objpfx)sysd-dirs): Use config-sysdirs.
	* MakeTAGS: Use $(full-config-subdirs).
	* Makerules: Change comment to libc.so link script.
	(sysdirs): Define based on $(full-config-subdirs).
	(sysd-Makefile): Define using config-sysdirs.
	(sysd-rules): Likewise.
	* sysdeps/unix/Makefile (sysd-syscalls): Define based on +sysdep-dirs.
	* sysdeps/unix/make-syscalls.sh: Remove basedir argument.

Wed Sep  4 01:32:21 1996  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* sysdeps/m68k/fpu/k_cos.c: Rewritten for better accuracy.
	* sysdeps/m68k/fpu/k_sin.c: Likewise.
	* sysdeps/m68k/fpu/k_tan.c: Likewise.

Thu Sep  5 01:06:09 1996  Richard Henderson  <rth@tamu.edu>

	* malloc/free.c (free): Protect by using __libc_malloc_lock.
	* malloc/malloc-find.c (malloc_find_object_address): Likewise.
	* malloc/malloc-size.c (malloc_usable_size): Likewise.
	* malloc/malloc-walk.c (malloc_walk): Likewise.
	* malloc/memalign.c (memalign): Likewise.
	* malloc/realloc.c (realloc): Likewise.
	* malloc/malloc.c: Define __libc_malloc_lock.
	(_malloc_internal): Don't use `malloc'.  Instead look for
	`__malloc_hook' or call `_malloc_internal'.
	(malloc): Protect by using `__libc_malloc_lock'.
	* malloc/malloc.h: Declare `__libc_malloc_lock'.

Mon Sep  2 22:42:59 1996  Richard Henderson  <rth@tamu.edu>

	* sysdeps/alpha/elf/start.S: Use weak_alias for __start
	instead of the hard definition.

	* sysdeps/alpha/dl-machine.h (RTLD_START): Add type info for
	_start and _dl_start_user.

	* sysdeps/unix/sysv/linux/alpha/init-first.h (SYSDEP_CALL_INIT):
	Make _dl_starting_up weak.  Add type info for NAME.

Mon Sep  2 22:15:14 1996  Richard Henderson  <rth@tamu.edu>

	* Makefile (all): Add extra_solibs pass.
	(+subdir_targets): Same.
	* Rules (extra_solibs): New phony empty target for subdirs without
	extra libs.
	* extra-lib.mk: Build lib*.so* in extra_solibs not lib-noranlib.
	* manual/Makefile: Add dummy extra_solibs target.

Sun Sep  1 15:41:22 1996  Richard Henderson  <rth@tamu.edu>

	* Makeconfig (+link): Add $(link-extra-libs).
	(link-extra-libs): New variable which expands to the full paths of
	the other libraries needed by a program, as controled by LDLIBS-$(@F).
	* db/Makefile: Use LDLIBS-makedb to link libdb not a dependency, as
	the later attempts to install the library before linking it.

	* sysdeps/unix/alpha/sysdep.S: Align errno.

	* sysdeps/unix/sysv/linux/alpha/ioperm.c (struct platform): Add
	hae_shift entry.
	(io): Move bus_memory_base and sparse_bus_memory_base into struct.
	(_hae_shift): New function.
	* sysdeps/unix/sysv/linux/alpha/sys/io.h: New file.  Prototypes
	for the bus query functions.

Sat Aug 31 18:14:54 1996  Richard Henderson  <rth@tamu.edu>

	* elf/dl-close.c (_dl_close): In static executables, map->l_prev
	can be NULL when unloading a library.

	* elf/dl-open.c (_dl_open): Pass __environ instead of __libc_envp
	to the library .init function.

	* sysdeps/alpha/dl-machine.h (elf_machine_rela):  Since we omitted
	part of the COPY reloc processing earlier, omit the rest now --
	we'll get into less trouble later when some fool does use a COPY.

	* sysdeps/unix/sysv/linux/init-first.c (init): Accept argc et al as
	parameters.  Move all argc and __libc_multiple_libcs calculation out
	to init-first.h.  Use __environ not __libc_envp.
	* sysdeps/unix/sysv/linux/alpha/init-first.h: Rewrite.
	* sysdeps/unix/sysv/linux/i386/init-first.h: Rewrite.

Thu Aug 29 20:26:40 1996  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

	* sysdeps/posix/profil.c (profil): Don't clobber saved timer and
	signal settings when profiling was already turned on.

	* csu/gmon-start.c (__gmon_start__) [HAVE_INITFINI]: Protect from
	being called twice.

Wed Sep  4 01:31:50 1996  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/linux/i386/mmap.S: Test for
	0 < return value < -4096 and not < 0 to decide about failure.
	Reported by Andreas Jaeger.

Tue Sep  3 19:04:05 1996  Ulrich Drepper  <drepper@cygnus.com>

	* stdio-common/vfscanf.c (__vfscanf): Don't count EOF char
	in %c format.

Sat Aug 31 18:10:51 1996  Ulrich Drepper  <drepper@cygnus.com>

	* wcsmbs/wchar.h: Define prototypes for wcstoq and wcstouq only
	#ifdef __USE_GNU.

Sat Aug 31 12:34:29 1996  Ulrich Drepper  <drepper@cygnus.com>

	* version.c: Add missing newline character in banner.

	* sysdeps/unix/sysv/linux/alpha/Dist: Correct typo.
	* sysdeps/unix/sysv/linux/i386/Dist: Likewise.

Sat Aug 31 03:07:39 1996  Ulrich Drepper  <drepper@cygnus.com>

	* intl/l10nflist.c (_nl_normalize_codeset): We convert to lower
 	case, so don't prepend uppercase `ISO' for only numeric arg.
1996-09-05 02:49:18 +00:00

155 lines
4.8 KiB
C

/* Load a shared object at runtime, relocate it, and run its initializer.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <link.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <errno.h>
extern void _dl_start (void); weak_extern (_dl_start)
extern int __libc_multiple_libcs; /* Defined in init-first.c. */
extern int __libc_argc;
extern char **__libc_argv;
extern char **__environ;
size_t _dl_global_scope_alloc;
struct link_map *
_dl_open (const char *file, int mode)
{
struct link_map *new, *l;
ElfW(Addr) init;
struct r_debug *r;
/* To decide whether we are the static libc or not. We must use
this variable since gcc would otherwise optimize the test away. */
void (*dl_start_ptr) (void) = &_dl_start;
/* Load the named object. */
new = _dl_map_object (NULL, file, lt_loaded);
if (new->l_searchlist)
/* It was already open. */
return new;
/* Load that object's dependencies. */
_dl_map_object_deps (new, NULL, 0);
/* Relocate the objects loaded. We do this in reverse order so that copy
relocs of earlier objects overwrite the data written by later objects. */
l = new;
while (l->l_next)
l = l->l_next;
while (1)
{
if (! l->l_relocated)
{
/* We use an indirect call call for _dl_relocate_object because
we must avoid using the PLT in the call. If our PLT entry for
_dl_relocate_object hasn't been used yet, then the dynamic
linker fixup routine will clobber _dl_global_scope during its
work. We must be sure that nothing will require a PLT fixup
between when _dl_object_relocation_scope returns and when we
enter the dynamic linker's code (_dl_relocate_object). */
__typeof (_dl_relocate_object) *reloc = &_dl_relocate_object;
(*reloc) (l, _dl_object_relocation_scope (l),
(mode & RTLD_BINDING_MASK) == RTLD_LAZY);
*_dl_global_scope_end = NULL;
}
if (l == new)
break;
l = l->l_prev;
}
new->l_global = (mode & RTLD_GLOBAL);
if (new->l_global)
{
/* The symbols of the new object and its dependencies are to be
introduced into the global scope that will be used to resolve
references from other dynamically-loaded objects. */
if (_dl_global_scope_alloc == 0)
{
/* This is the first dynamic object given global scope. */
_dl_global_scope_alloc = 8;
_dl_global_scope = malloc (8 * sizeof (struct link_map *));
if (! _dl_global_scope)
{
_dl_global_scope = _dl_default_scope;
nomem:
_dl_close (new);
_dl_signal_error (ENOMEM, file, "cannot extend global scope");
}
_dl_global_scope[2] = _dl_default_scope[2];
_dl_global_scope[3] = new;
_dl_global_scope[4] = NULL;
_dl_global_scope[5] = NULL;
}
else
{
if (_dl_global_scope_alloc <
(size_t) (_dl_global_scope_end - _dl_global_scope + 2))
{
/* Must extend the list. */
struct link_map **new = realloc (_dl_global_scope,
_dl_global_scope_alloc * 2);
if (! new)
goto nomem;
_dl_global_scope_end = new + (_dl_global_scope_end -
_dl_global_scope);
_dl_global_scope = new;
_dl_global_scope_alloc *= 2;
}
/* Append the new object and re-terminate the list. */
*_dl_global_scope_end++ = new;
/* We keep the list double-terminated so the last element
can be filled in for symbol lookups. */
_dl_global_scope_end[0] = NULL;
_dl_global_scope_end[1] = NULL;
}
}
/* Notify the debugger we have added some objects. We need to call
_dl_debug_initialize in a static program in case dynamic linking has
not been used before. */
r = _dl_debug_initialize (0);
r->r_state = RT_ADD;
_dl_debug_state ();
/* Run the initializer functions of new objects. */
while (init = _dl_init_next (new))
(*(void (*) (int, char **, char **)) init) (__libc_argc, __libc_argv,
__environ);
if (dl_start_ptr == NULL)
/* We must be the static _dl_open in libc.a because ld.so.1 is not
in scope. A static program that has loaded a dynamic object
now has competition. */
__libc_multiple_libcs = 1;
return new;
}