+1998-03-06 17:04 Ulrich Drepper <drepper@cygnus.com>
+
+ * libc.map: Add _dl_debug_impcalls, _dl_debug_fd, _dl_sysdep_output,
+ __libc_start_main.
+ * csu/Makefile (routines): Add libc-start.
+ * elf/dl-error.c: Remove declaration of _dl_argv. Include <unitsd.h>.
+ * elf/dl-lookup.c: Likewise.
+ * elf/dl-version.c: Likewise.
+ * sysdeps/i386/dl-machine.h: Likewise.
+ * elf/link.h: Declare _dl_argv, _dl_debug_fd.
+ Declare _dl_sysdep_output. Make _dl_sysdep_fatal, _dl_sysdep_error and
+ _dl_sysdep_message macros which use _dl_sysdep_output.
+ * elf/dl-fini.c: Write out which destructor is called while debugging.
+ * elf/dl-init.c: Likewise for constructor.
+ * elf/dl-load.c: Use _dl_debug_message instead of _dl_sysdep_message.
+ * elf/dl-misc.c: Remove _dl_sysdep_fatal, _dl_sysdep_error and
+ _dl_sysdep_message. Add _dl_sysdep_output.
+ * elf/rtld.c: Recognize LD_DEBUG_OUTPUT. Set _dl_debug_fd if
+ this file can be opened.
+ For LD_DEBUG=libs also set _dl_debug_impcalls.
+ * sysdeps/generic/dl-cache.c: Include unistd.h.
+ * sysdeps/generic/libc-start.c: New file.
+ * sysdeps/i386/elf/start.S: Don't call main directly, call
+ * sysdeps/unix/sysv/linux/libc-start.c: New file.
+ __libc_start_main instead.
+
+ * elf/Makefile ($(objpfx)ld.so): Add $(load-map-file) as dependency.
+
1998-03-06 Ulrich Drepper <drepper@cygnus.com>
* nss/nsswitch.c (__nss_nscd_not_available): Removed.
subdir := csu
-routines = init-first
+routines = init-first libc-start
csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
extra-objs = start.o gmon-start.o \
$(start-installed-name) g$(start-installed-name) \
-e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
endif
-$(objpfx)ld.so: $(objpfx)librtld.os $(addprefix $(objpfx),$(rtld-ldscript))
+$(objpfx)ld.so: $(objpfx)librtld.os $(addprefix $(objpfx),$(rtld-ldscript)) $(load-map-file)
$(rtld-link) -Wl,-soname=$(rtld-installed-name)
define rtld-link
/* Error handling for runtime dynamic linker.
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998 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
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <stddef.h>
#include <link.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
/* This is the internal function we use to generate the error string. */
extern char *_strerror_internal __P ((int, char *, size_t));
else
{
/* Lossage while resolving the program's own symbols is always fatal. */
- extern char **_dl_argv; /* Set in rtld.c at startup. */
char buffer[1024];
_dl_sysdep_fatal (_dl_argv[0] ?: "<program name unknown>",
": error in loading shared libraries: ",
/* Call the termination functions of loaded shared objects.
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1998 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
{
if (l->l_info[DT_FINI] &&
!(l->l_name[0] == '\0' && l->l_type == lt_executable))
- (*(void (*) (void)) (l->l_addr + l->l_info[DT_FINI]->d_un.d_ptr)) ();
+ {
+ /* When debugging print a message first. */
+ if (_dl_debug_impcalls)
+ _dl_debug_message ("\n\tcalling fini: ",
+ l->l_name[0] ? l->l_name : _dl_argv[0],
+ "\n", NULL);
+
+ (*(void (*) (void)) (l->l_addr + l->l_info[DT_FINI]->d_un.d_ptr)) ();
+ }
/* Make sure nothing happens if we are called twice. */
l->l_init_called = 0;
}
/* Return the next shared object initializer function not yet run.
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1998 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
{
/* Run this object's initializer. */
l->l_init_running = 1;
+
+ /* Print a debug message if wanted. */
+ if (_dl_debug_impcalls)
+ _dl_debug_message ("\tcalling init: ",
+ l->l_name[0] ? l->l_name : _dl_argv[0],
+ "\n\n", NULL);
+
return l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr;
}
size_t _dl_pagesize;
-/* Arguments passed to the dynamic linker. */
-extern char **_dl_argv;
-
extern const char *_dl_platform;
extern size_t _dl_platformlen;
/* Print name we try if this is wanted. */
if (_dl_debug_libs)
- _dl_sysdep_message ("\t trying file=", buf, "\n", NULL);
+ _dl_debug_message ("\t trying file=", buf, "\n", NULL);
fd = __open (buf, O_RDONLY);
if (this_dir->machdirstatus == unknown)
/* Print name we try if this is wanted. */
if (_dl_debug_libs)
- _dl_sysdep_message ("\t trying file=", buf, "\n", NULL);
+ _dl_debug_message ("\t trying file=", buf, "\n", NULL);
fd = __open (buf, O_RDONLY);
if (this_dir->dirstatus == unknown)
size_t namelen = strlen (name) + 1;
if (_dl_debug_libs)
- _dl_sysdep_message ("\tfind library=", name, "; searching\n", NULL);
+ _dl_debug_message ("\tfind library=", name, "; searching\n", NULL);
fd = -1;
/* Add another newline when we a tracing the library loading. */
if (_dl_debug_libs)
- _dl_sysdep_message ("\n", NULL);
+ _dl_debug_message ("\n", NULL);
}
else
{
const struct r_found_version *version,
int reloc_type)
{
- extern char **_dl_argv;
const unsigned long int hash = _dl_elf_hash (undef_name);
struct sym_val current_value = { 0, NULL };
struct link_map **scope;
}
-void
-_dl_sysdep_fatal (const char *msg, ...)
-{
- va_list ap;
-
- va_start (ap, msg);
- do
- {
- size_t len = strlen (msg);
- __write (STDERR_FILENO, msg, len);
- msg = va_arg (ap, const char *);
- } while (msg);
- va_end (ap);
-
- _exit (127);
-}
-
-
-void
-_dl_sysdep_error (const char *msg, ...)
-{
- va_list ap;
-
- va_start (ap, msg);
- do
- {
- size_t len = strlen (msg);
- __write (STDERR_FILENO, msg, len);
- msg = va_arg (ap, const char *);
- } while (msg);
- va_end (ap);
-}
+/* Descriptor to write debug messages to. */
+int _dl_debug_fd;
void
-_dl_sysdep_message (const char *msg, ...)
+_dl_sysdep_output (int fd, const char *msg, ...)
{
va_list ap;
do
{
size_t len = strlen (msg);
- __write (STDOUT_FILENO, msg, len);
+ __write (fd, msg, len);
msg = va_arg (ap, const char *);
} while (msg);
va_end (ap);
/* Handle symbol and library versioning.
- Copyright (C) 1997 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
#include <stdio-common/_itoa.h>
-/* Set in rtld.c at startup. */
-extern char **_dl_argv;
-
#define VERSTAG(tag) (DT_NUM + DT_PROCNUM + DT_VERSIONTAGIDX (tag))
user interface to run-time dynamic linking. */
+/* Parameters passed to te dynamic linker. */
+extern char **_dl_argv;
+
/* Cached value of `getpagesize ()'. */
extern size_t _dl_pagesize;
/* If nonzero the appropriate debug information if printed. */
extern int _dl_debug_libs;
+extern int _dl_debug_impcalls;
+
+/* File deccriptor to write debug messages to. */
+extern int _dl_debug_fd;
/* OS-dependent function to open the zero-fill device. */
extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
+/* OS-dependent function to write a message on the specified
+ descriptor FD. All arguments are `const char *'; args until a null
+ pointer are concatenated to form the message to print. */
+extern void _dl_sysdep_output (int fd, const char *string, ...);
+
+/* OS-dependent function to write a debug message on the specified
+ descriptor for this. All arguments are `const char *'; args until
+ a null pointer are concatenated to form the message to print. */
+#define _dl_debug_message(string, args...) \
+ _dl_sysdep_output (_dl_debug_fd, string, ##args)
+
/* OS-dependent function to write a message on the standard output.
All arguments are `const char *'; args until a null pointer
are concatenated to form the message to print. */
-extern void _dl_sysdep_message (const char *string, ...);
+#define _dl_sysdep_message(string, args...) \
+ _dl_sysdep_output (STDOUT_FILENO, string, ##args)
/* OS-dependent function to write a message on the standard error.
All arguments are `const char *'; args until a null pointer
are concatenated to form the message to print. */
-extern void _dl_sysdep_error (const char *string, ...);
+#define _dl_sysdep_error(string, args...) \
+ _dl_sysdep_output (STDERR_FILENO, string, ##args)
/* OS-dependent function to give a fatal error message and exit
when the dynamic linker fails before the program is fully linked.
All arguments are `const char *'; args until a null pointer
are concatenated to form the message to print. */
-extern void _dl_sysdep_fatal (const char *string, ...)
- __attribute__ ((__noreturn__));
+#define _dl_sysdep_fatal(string, args...) \
+ do \
+ { \
+ _dl_sysdep_output (STDERR_FILENO, string, ##args); \
+ _exit (127); \
+ } \
+ while (1)
/* Nonzero if the program should be "secure" (i.e. it's setuid or somesuch).
This tells the dynamic linker to ignore environment variables. */
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <fcntl.h>
#include <link.h>
#include <stddef.h>
#include <stdlib.h>
const char *_dl_profile_output;
struct link_map *_dl_profile_map;
int _dl_debug_libs;
+int _dl_debug_impcalls;
/* Set nonzero during loading and initialization of executable and
libraries, cleared before the executable's entry point runs. This
objname, ": ", errstring, "\n", NULL);
}
\f
+/* Nonzero if any of the debugging options is enabled. */
+static int any_debug;
+
/* Process the string given as the parameter which explains which debugging
options are enabled. */
static void
&& (issep (dl_debug[4]) || dl_debug[4] == '\0'))
{
_dl_debug_libs = 1;
+ _dl_debug_impcalls = 1;
+ any_debug = 1;
dl_debug += 4;
}
else if (strncmp (dl_debug, "help", 4) == 0
char *envline;
enum mode mode = normal;
int bind_now = 0;
+ char *debug_output = NULL;
/* This is the default place for profiling data file. */
_dl_profile_output = "/var/tmp";
if (result < 0)
continue;
+ /* Where to place the profiling data file. */
+ result = strncmp (&envline[3], "DEBUG_OUTPUT=", 13);
+ if (result == 0)
+ {
+ debug_output = &envline[16];
+ continue;
+ }
+ if (result < 0)
+ continue;
+
/* Which shared object shall be profiled. */
result = strncmp (&envline[3], "PROFILE=", 8);
if (result == 0)
}
}
+ /* If we have to run the dynamic linker in debugging mode and the
+ LD_DEBUG_OUTPUT environment variable is given, we write the debug
+ messages to this file. */
+ if (any_debug && debug_output != NULL)
+ {
+ _dl_debug_fd = __open (debug_output, O_WRONLY | O_APPEND | O_CREAT,
+ 0666);
+ if (_dl_debug_fd == -1)
+ /* We use standard output if opening the file failed. */
+ _dl_debug_fd = STDOUT_FILENO;
+ }
+
/* LAZY is determined by the environment variable LD_WARN and
LD_BIND_NOW if we trace the binary. */
if (mode == trace)
__collate_element_strings; __collate_symbol_classes;
__collate_symbol_hash; __collate_symbol_strings;
_obstack;
- __progname_full; __progname;
+ __progname_full; __progname; _dl_debug_impcalls; _dl_debug_fd;
_IO_list_all; _IO_stderr_; _IO_stdin_; _IO_stdout_;
.div; .mul; .rem; .udiv; .umul; .urem;
# helper functions
- __errno_location; __libc_init_first; __h_errno_location;
+ __errno_location; __libc_init_first; __h_errno_location; __libc_start_main;
# functions with special/multiple interfaces
__sigsetjmp; _setjmp; __sigaddset; __sigdelset; __sigismember;
__vsscanf; __vfscanf; __vsnprintf;
_rpc_dtablesize; _null_auth; _seterr_reply;
__res_randomid; __getpid;
- __strcasecmp; __write; _strerror_internal;
+ __strcasecmp; __write; _strerror_internal; _dl_sysdep_output;
# Exception handling support functions from libgcc
__register_frame; __register_frame_table; __deregister_frame;
Boston, MA 02111-1307, USA. */
#include <link.h>
-#include <stddef.h>
+#include <unistd.h>
#include <sys/mman.h>
/* System-dependent function to read a file's whole contents
--- /dev/null
+/* Copyright (C) 1998 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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+int
+__libc_start_main (int (*main) (int, char **, char **), int argc,
+ char **argv, char **envp)
+{
+ return (*main) (argc, argv, envp);
+}
/* Machine-dependent ELF dynamic relocation inline functions. i386 version.
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998 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
#ifdef RESOLVE
-extern char **_dl_argv;
-
/* Perform the relocation specified by RELOC and SYM (which is fully resolved).
MAP is the object containing the reloc. */
/* Startup code compliant to the ELF i386 ABI.
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998 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
call atexit
popl %eax
- /* Call the user's main function, and exit with its value. */
- call main
+ /* Call the user's main function, and exit with its value.
+ But let the libc call main. */
+ movl $main, %eax
pushl %eax
+ call __libc_start_main
call exit
hlt /* Crash if somehow `exit' does return. */
--- /dev/null
+/* Copyright (C) 1998 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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <link.h>
+
+int
+__libc_start_main (int (*main) (int, char **, char **), int argc,
+ char **argv, char **envp)
+{
+#ifdef PIC
+ if (_dl_debug_impcalls)
+ _dl_debug_message ("\ttransferring control: ", argv[0], "\n\n", NULL);
+#endif
+
+ return (*main) (argc, argv, envp);
+}