1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

* sysdeps/mach/hurd/dl-sysdep.c (_dl_sysdep_start): If started by

kernel with args on stack, point _dl_hurd_data at zero data
	instead of garbage.  When ld.so run as program, grok args
	-LIB=MEMOBJ and pre-load shared object files found in memory
	objects loaded by the boot loader.

	* elf/link.h (struct link_map): New member `l_entry'.
	(_dl_map_object, _dl_map_object_from_fd): Remove last arg ENTRY_POINT.
	* elf/dl-load.c (_dl_map_object, _dl_map_object_from_fd): Remove
	last arg ENTRY_POINT.  Store the entry point location in the
	`l_entry' member of the new map.
	* elf/rtld.c (dl_main): Don't pass USER_ENTRY arg to
	_dl_map_object.  When run as program, set *USER_ENTRY to L->l_entry.
	* elf/dl-init.c (_dl_init_next): Don't pass ENTRY_POINT arg to
	_dl_map_object.
This commit is contained in:
Roland McGrath
1995-09-30 21:18:30 +00:00
parent 41cfadd63c
commit 879bf2e65a
7 changed files with 125 additions and 36 deletions

View File

@@ -1,5 +1,21 @@
Sat Sep 30 11:47:05 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> Sat Sep 30 11:47:05 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* sysdeps/mach/hurd/dl-sysdep.c (_dl_sysdep_start): If started by
kernel with args on stack, point _dl_hurd_data at zero data
instead of garbage. When ld.so run as program, grok args
-LIB=MEMOBJ and pre-load shared object files found in memory
objects loaded by the boot loader.
* elf/link.h (struct link_map): New member `l_entry'.
(_dl_map_object, _dl_map_object_from_fd): Remove last arg ENTRY_POINT.
* elf/dl-load.c (_dl_map_object, _dl_map_object_from_fd): Remove
last arg ENTRY_POINT. Store the entry point location in the
`l_entry' member of the new map.
* elf/rtld.c (dl_main): Don't pass USER_ENTRY arg to
_dl_map_object. When run as program, set *USER_ENTRY to L->l_entry.
* elf/dl-init.c (_dl_init_next): Don't pass ENTRY_POINT arg to
_dl_map_object.
* posix/tstgetopt.c, posix/tstgetopt.args: Test long options too. * posix/tstgetopt.c, posix/tstgetopt.args: Test long options too.
* sysdeps/unix/sysv/linux/i386/init-first.c (init): Save, set, and * sysdeps/unix/sysv/linux/i386/init-first.c (init): Save, set, and

View File

@@ -53,7 +53,7 @@ _dl_init_next (void)
if (d->d_tag == DT_NEEDED) if (d->d_tag == DT_NEEDED)
{ {
struct link_map *needed struct link_map *needed
= _dl_map_object (l, strtab + d->d_un.d_val, NULL); = _dl_map_object (l, strtab + d->d_un.d_val);
Elf32_Addr init; Elf32_Addr init;
--needed->l_opencount; --needed->l_opencount;
init = next_init (needed); /* Recurse on this dependency. */ init = next_init (needed); /* Recurse on this dependency. */

View File

@@ -104,8 +104,7 @@ open_path (const char *name, size_t namelen,
/* Map in the shared object file NAME. */ /* Map in the shared object file NAME. */
struct link_map * struct link_map *
_dl_map_object (struct link_map *loader, const char *name, _dl_map_object (struct link_map *loader, const char *name)
Elf32_Addr *entry_point)
{ {
int fd; int fd;
char *realname; char *realname;
@@ -152,7 +151,7 @@ _dl_map_object (struct link_map *loader, const char *name,
if (fd == -1) if (fd == -1)
_dl_signal_error (errno, name, "cannot open shared object file"); _dl_signal_error (errno, name, "cannot open shared object file");
return _dl_map_object_from_fd (name, fd, realname, entry_point); return _dl_map_object_from_fd (name, fd, realname);
} }
@@ -160,8 +159,7 @@ _dl_map_object (struct link_map *loader, const char *name,
opened on FD. */ opened on FD. */
struct link_map * struct link_map *
_dl_map_object_from_fd (const char *name, int fd, char *realname, _dl_map_object_from_fd (const char *name, int fd, char *realname)
Elf32_Addr *entry_point)
{ {
struct link_map *l = NULL; struct link_map *l = NULL;
const size_t pagesize = getpagesize (); const size_t pagesize = getpagesize ();
@@ -249,17 +247,16 @@ _dl_map_object_from_fd (const char *name, int fd, char *realname,
the headers. */ the headers. */
Elf32_Phdr phdr[header->e_phnum]; Elf32_Phdr phdr[header->e_phnum];
const Elf32_Phdr *ph; const Elf32_Phdr *ph;
int anywhere; int anywhere, type;
type = header->e_type;
anywhere = type == ET_DYN || type == ET_REL;
l->l_entry = header->e_entry;
ph = map (header->e_phoff, header->e_phnum * sizeof (Elf32_Phdr)); ph = map (header->e_phoff, header->e_phnum * sizeof (Elf32_Phdr));
memcpy (phdr, ph, sizeof phdr); memcpy (phdr, ph, sizeof phdr);
l->l_phnum = header->e_phnum; l->l_phnum = header->e_phnum;
anywhere = header->e_type == ET_DYN || header->e_type == ET_REL;
if (entry_point)
*entry_point = header->e_entry;
/* We are done reading the file's headers now. Unmap them. */ /* We are done reading the file's headers now. Unmap them. */
munmap (file_mapping, mapping_size); munmap (file_mapping, mapping_size);
@@ -375,12 +372,18 @@ _dl_map_object_from_fd (const char *name, int fd, char *realname,
} }
if (l->l_ld == 0) if (l->l_ld == 0)
LOSE ("object file has no dynamic section"); {
(Elf32_Addr) l->l_ld += l->l_addr; if (type == ET_DYN)
LOSE ("object file has no dynamic section");
}
else
(Elf32_Addr) l->l_ld += l->l_addr;
if (l->l_phdr == 0) if (l->l_phdr == 0)
l->l_phdr = (void *) ((const Elf32_Ehdr *) l->l_addr)->e_phoff; l->l_phdr = (void *) ((const Elf32_Ehdr *) l->l_addr)->e_phoff;
(Elf32_Addr) l->l_phdr += l->l_addr; (Elf32_Addr) l->l_phdr += l->l_addr;
l->l_entry += l->l_addr;
} }
elf_get_dynamic_info (l->l_ld, l->l_info); elf_get_dynamic_info (l->l_ld, l->l_info);

View File

@@ -85,6 +85,7 @@ struct link_map
Elf32_Dyn *l_info[DT_NUM]; /* Indexed pointers to dynamic section. */ Elf32_Dyn *l_info[DT_NUM]; /* Indexed pointers to dynamic section. */
const Elf32_Phdr *l_phdr; /* Pointer to program header table in core. */ const Elf32_Phdr *l_phdr; /* Pointer to program header table in core. */
Elf32_Word l_phnum; /* Number of program header entries. */ Elf32_Word l_phnum; /* Number of program header entries. */
Elf32_Addr l_entry; /* Entry point location. */
/* Symbol hash table. */ /* Symbol hash table. */
Elf32_Word l_nbuckets; Elf32_Word l_nbuckets;
@@ -158,17 +159,14 @@ extern int _dlerror_run (void (*operate) (void));
/* Open the shared object NAME and map in its segments. /* Open the shared object NAME and map in its segments.
LOADER's DT_RPATH is used in searching for NAME. LOADER's DT_RPATH is used in searching for NAME.
If ENTRY_POINT is not null, fill it in with the object's entry point.
If the object is already opened, returns its existing map. */ If the object is already opened, returns its existing map. */
extern struct link_map *_dl_map_object (struct link_map *loader, extern struct link_map *_dl_map_object (struct link_map *loader,
const char *name, const char *name);
Elf32_Addr *entry_point);
/* Similar, but file found at REALNAME and opened on FD. /* Similar, but file found at REALNAME and opened on FD.
REALNAME must malloc'd storage and is used in internal data structures. */ REALNAME must malloc'd storage and is used in internal data structures. */
extern struct link_map *_dl_map_object_from_fd (const char *name, extern struct link_map *_dl_map_object_from_fd (const char *name,
int fd, char *realname, int fd, char *realname);
Elf32_Addr *entry_point);
/* Cache the locations of MAP's hash table. */ /* Cache the locations of MAP's hash table. */
extern void _dl_setup_hash (struct link_map *map); extern void _dl_setup_hash (struct link_map *map);

View File

@@ -151,11 +151,12 @@ of this helper program; chances are you did not intend to run this program.\n",
interpreter_name = _dl_argv[0]; interpreter_name = _dl_argv[0];
--_dl_argc; --_dl_argc;
++_dl_argv; ++_dl_argv;
l = _dl_map_object (NULL, _dl_argv[0], user_entry); l = _dl_map_object (NULL, _dl_argv[0]);
phdr = l->l_phdr; phdr = l->l_phdr;
phent = l->l_phnum; phent = l->l_phnum;
l->l_type = lt_executable; l->l_type = lt_executable;
l->l_libname = (char *) ""; l->l_libname = (char *) "";
*user_entry = l->l_entry;
} }
else else
{ {
@@ -165,6 +166,7 @@ of this helper program; chances are you did not intend to run this program.\n",
l->l_phdr = phdr; l->l_phdr = phdr;
l->l_phnum = phent; l->l_phnum = phent;
interpreter_name = 0; interpreter_name = 0;
l->l_entry = *user_entry;
} }
if (l != _dl_loaded) if (l != _dl_loaded)
@@ -228,7 +230,7 @@ of this helper program; chances are you did not intend to run this program.\n",
const Elf32_Dyn *d; const Elf32_Dyn *d;
for (d = l->l_ld; d->d_tag != DT_NULL; ++d) for (d = l->l_ld; d->d_tag != DT_NULL; ++d)
if (d->d_tag == DT_NEEDED) if (d->d_tag == DT_NEEDED)
_dl_map_object (l, strtab + d->d_un.d_val, NULL); _dl_map_object (l, strtab + d->d_un.d_val);
} }
l->l_deps_loaded = 1; l->l_deps_loaded = 1;
} }

View File

@@ -63,12 +63,15 @@ Cambridge, MA 02139, USA. */
#include <stdlib.h> #include <stdlib.h>
#endif /* GNU C library. */ #endif /* GNU C library. */
#ifndef _
/* This is for other GNU distributions with internationalized messages. /* This is for other GNU distributions with internationalized messages.
The GNU C Library itself does not yet support such messages. */ When compiling libc, the _ macro is predefined. */
#if HAVE_LIBINTL_H #ifdef HAVE_LIBINTL_H
# include <libintl.h> # include <libintl.h>
# define _(msgid) gettext (msgid)
#else #else
# define gettext(msgid) (msgid) # define _(msgid) (msgid)
#endif
#endif #endif
/* This version of `getopt' appears to the caller like standard Unix `getopt' /* This version of `getopt' appears to the caller like standard Unix `getopt'
@@ -520,7 +523,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (ambig && !exact) if (ambig && !exact)
{ {
if (opterr) if (opterr)
fprintf (stderr, gettext ("%s: option `%s' is ambiguous\n"), fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
argv[0], argv[optind]); argv[0], argv[optind]);
nextchar += strlen (nextchar); nextchar += strlen (nextchar);
optind++; optind++;
@@ -543,12 +546,12 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (argv[optind - 1][1] == '-') if (argv[optind - 1][1] == '-')
/* --option */ /* --option */
fprintf (stderr, fprintf (stderr,
gettext ("%s: option `--%s' doesn't allow an argument\n"), _("%s: option `--%s' doesn't allow an argument\n"),
argv[0], pfound->name); argv[0], pfound->name);
else else
/* +option or -option */ /* +option or -option */
fprintf (stderr, fprintf (stderr,
gettext ("%s: option `%c%s' doesn't allow an argument\n"), _("%s: option `%c%s' doesn't allow an argument\n"),
argv[0], argv[optind - 1][0], pfound->name); argv[0], argv[optind - 1][0], pfound->name);
nextchar += strlen (nextchar); nextchar += strlen (nextchar);
@@ -563,7 +566,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{ {
if (opterr) if (opterr)
fprintf (stderr, fprintf (stderr,
gettext ("%s: option `%s' requires an argument\n"), _("%s: option `%s' requires an argument\n"),
argv[0], argv[optind - 1]); argv[0], argv[optind - 1]);
nextchar += strlen (nextchar); nextchar += strlen (nextchar);
return optstring[0] == ':' ? ':' : '?'; return optstring[0] == ':' ? ':' : '?';
@@ -591,11 +594,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{ {
if (argv[optind][1] == '-') if (argv[optind][1] == '-')
/* --option */ /* --option */
fprintf (stderr, gettext ("%s: unrecognized option `--%s'\n"), fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
argv[0], nextchar); argv[0], nextchar);
else else
/* +option or -option */ /* +option or -option */
fprintf (stderr, gettext ("%s: unrecognized option `%c%s'\n"), fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
argv[0], argv[optind][0], nextchar); argv[0], argv[optind][0], nextchar);
} }
nextchar = (char *) ""; nextchar = (char *) "";
@@ -620,10 +623,10 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{ {
if (posixly_correct) if (posixly_correct)
/* 1003.2 specifies the format of this message. */ /* 1003.2 specifies the format of this message. */
fprintf (stderr, gettext ("%s: illegal option -- %c\n"), fprintf (stderr, _("%s: illegal option -- %c\n"),
argv[0], c); argv[0], c);
else else
fprintf (stderr, gettext ("%s: invalid option -- %c\n"), fprintf (stderr, _("%s: invalid option -- %c\n"),
argv[0], c); argv[0], c);
} }
optopt = c; optopt = c;
@@ -659,7 +662,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{ {
/* 1003.2 specifies the format of this message. */ /* 1003.2 specifies the format of this message. */
fprintf (stderr, fprintf (stderr,
gettext ("%s: option requires an argument -- %c\n"), _("%s: option requires an argument -- %c\n"),
argv[0], c); argv[0], c);
} }
optopt = c; optopt = c;

View File

@@ -80,20 +80,75 @@ _dl_sysdep_start (void **start_argptr,
void (*dl_main) (const Elf32_Phdr *phdr, Elf32_Word phent, void (*dl_main) (const Elf32_Phdr *phdr, Elf32_Word phent,
Elf32_Addr *user_entry)) Elf32_Addr *user_entry))
{ {
extern void _start ();
void go (int *argdata) void go (int *argdata)
{ {
extern unsigned int _dl_skip_args; /* rtld.c */
char **p; char **p;
/* Cache the information in various global variables. */ /* Cache the information in various global variables. */
_dl_argc = *argdata; _dl_argc = *argdata;
_dl_argv = (void *) &argdata[1]; _dl_argv = 1 + (char **) argdata;
_environ = &_dl_argv[_dl_argc + 1]; _environ = &_dl_argv[_dl_argc + 1];
for (p = _environ; *p; ++p); for (p = _environ; *p++;); /* Skip environ pointers and terminator. */
_dl_hurd_data = (void *) ++p;
if ((void *) p == _dl_argv[0])
{
static struct hurd_startup_data nodata;
_dl_hurd_data = &nodata;
nodata.user_entry = (vm_address_t) &_start;
}
else
_dl_hurd_data = (void *) p;
_dl_secure = _dl_hurd_data->flags & EXEC_SECURE; _dl_secure = _dl_hurd_data->flags & EXEC_SECURE;
unfmh(); /* XXX */ unfmh(); /* XXX */
if (_dl_hurd_data->user_entry == (vm_address_t) &_start)
/* We were invoked as a command, not as the program interpreter.
The generic ld.so code supports this: it will parse the args
as "ld.so PROGRAM [ARGS...]". For booting the Hurd, we
support an additional special syntax:
ld.so [-LIBS...] PROGRAM [ARGS...]
Each LIBS word consists of "FILENAME=MEMOBJ";
for example "-/lib/libc.so=123" says that the contents of
/lib/libc.so are found in a memory object whose port name
in our task is 123. */
while (_dl_argc > 2 && _dl_argv[1][0] == '-')
{
char *lastslash, *memobjname, *p;
struct link_map *l;
mach_port_t memobj;
error_t err;
++_dl_skip_args;
--_dl_argc;
p = _dl_argv++[1] + 1;
memobjname = strchr (p, '=');
if (! memobjname)
_dl_sysdep_fatal ("Bogus library spec: ", p, "\n", NULL);
*memobjname++ = '\0';
memobj = (mach_port_t) atoi (memobjname);
/* Add a user reference on the memory object port, so we will
still have one after _dl_map_object_from_fd calls our
`close'. */
err = __mach_port_mod_refs (__mach_task_self (), memobj,
MACH_PORT_RIGHT_SEND, +1);
assert_perror (err);
lastslash = strrchr (p, '/');
l = _dl_map_object_from_fd (lastslash ? lastslash + 1 : p,
memobj, strdup (p));
/* Squirrel away the memory object port where it
can be retrieved by the program later. */
l->l_info[DT_NULL] = (void *) memobj;
}
/* Call elf/rtld.c's main program. It will set everything /* Call elf/rtld.c's main program. It will set everything
up and leave us to transfer control to USER_ENTRY. */ up and leave us to transfer control to USER_ENTRY. */
(*dl_main) ((const Elf32_Phdr *) _dl_hurd_data->phdr, (*dl_main) ((const Elf32_Phdr *) _dl_hurd_data->phdr,
@@ -106,6 +161,18 @@ unfmh(); /* XXX */
__mig_dealloc_reply_port (MACH_PORT_NULL); __mig_dealloc_reply_port (MACH_PORT_NULL);
__mach_port_deallocate (__mach_task_self (), __mach_task_self_); __mach_port_deallocate (__mach_task_self (), __mach_task_self_);
if (_dl_skip_args && _dl_argv[-_dl_skip_args] == (char *) p)
{
/* We are ignoring the first few arguments, but we have no Hurd
startup data. It is magical convention that ARGV[0] == P in
this case. The startup code in init-first.c will get confused
if this is not the case, so we must rearrange things to make
it so. Overwrite the original ARGV[0] at P with
ARGV[_dl_skip_args]. */
assert ((char *) p < _dl_argv[0]);
_dl_argv[0] = strcpy ((char *) p, _dl_argv[0]);
}
{ {
extern void _dl_start_user (void); extern void _dl_start_user (void);
/* Unwind the stack to ARGDATA and simulate a return from _dl_start /* Unwind the stack to ARGDATA and simulate a return from _dl_start