diff options
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | elf/dl-init.c | 2 | ||||
-rw-r--r-- | elf/dl-load.c | 29 | ||||
-rw-r--r-- | elf/link.h | 8 | ||||
-rw-r--r-- | elf/rtld.c | 6 | ||||
-rw-r--r-- | posix/getopt.c | 27 | ||||
-rw-r--r-- | sysdeps/mach/hurd/dl-sysdep.c | 73 |
7 files changed, 125 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog index 406263271e..fa55087b00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 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. * sysdeps/unix/sysv/linux/i386/init-first.c (init): Save, set, and diff --git a/elf/dl-init.c b/elf/dl-init.c index 36eb32aa78..c44a73f29b 100644 --- a/elf/dl-init.c +++ b/elf/dl-init.c @@ -53,7 +53,7 @@ _dl_init_next (void) if (d->d_tag == DT_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; --needed->l_opencount; init = next_init (needed); /* Recurse on this dependency. */ diff --git a/elf/dl-load.c b/elf/dl-load.c index 7319602d81..12b945a185 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -104,8 +104,7 @@ open_path (const char *name, size_t namelen, /* Map in the shared object file NAME. */ struct link_map * -_dl_map_object (struct link_map *loader, const char *name, - Elf32_Addr *entry_point) +_dl_map_object (struct link_map *loader, const char *name) { int fd; char *realname; @@ -152,7 +151,7 @@ _dl_map_object (struct link_map *loader, const char *name, if (fd == -1) _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. */ struct link_map * -_dl_map_object_from_fd (const char *name, int fd, char *realname, - Elf32_Addr *entry_point) +_dl_map_object_from_fd (const char *name, int fd, char *realname) { struct link_map *l = NULL; const size_t pagesize = getpagesize (); @@ -249,17 +247,16 @@ _dl_map_object_from_fd (const char *name, int fd, char *realname, the headers. */ Elf32_Phdr phdr[header->e_phnum]; 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)); memcpy (phdr, ph, sizeof phdr); 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. */ 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) - 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) l->l_phdr = (void *) ((const Elf32_Ehdr *) l->l_addr)->e_phoff; (Elf32_Addr) l->l_phdr += l->l_addr; + + l->l_entry += l->l_addr; } elf_get_dynamic_info (l->l_ld, l->l_info); diff --git a/elf/link.h b/elf/link.h index aacb3f1630..0388c02202 100644 --- a/elf/link.h +++ b/elf/link.h @@ -85,6 +85,7 @@ struct link_map Elf32_Dyn *l_info[DT_NUM]; /* Indexed pointers to dynamic section. */ const Elf32_Phdr *l_phdr; /* Pointer to program header table in core. */ Elf32_Word l_phnum; /* Number of program header entries. */ + Elf32_Addr l_entry; /* Entry point location. */ /* Symbol hash table. */ 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. 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. */ extern struct link_map *_dl_map_object (struct link_map *loader, - const char *name, - Elf32_Addr *entry_point); + const char *name); /* Similar, but file found at REALNAME and opened on FD. REALNAME must malloc'd storage and is used in internal data structures. */ extern struct link_map *_dl_map_object_from_fd (const char *name, - int fd, char *realname, - Elf32_Addr *entry_point); + int fd, char *realname); /* Cache the locations of MAP's hash table. */ extern void _dl_setup_hash (struct link_map *map); diff --git a/elf/rtld.c b/elf/rtld.c index df91573ad1..276ff51e57 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -151,11 +151,12 @@ of this helper program; chances are you did not intend to run this program.\n", interpreter_name = _dl_argv[0]; --_dl_argc; ++_dl_argv; - l = _dl_map_object (NULL, _dl_argv[0], user_entry); + l = _dl_map_object (NULL, _dl_argv[0]); phdr = l->l_phdr; phent = l->l_phnum; l->l_type = lt_executable; l->l_libname = (char *) ""; + *user_entry = l->l_entry; } 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_phnum = phent; interpreter_name = 0; + l->l_entry = *user_entry; } 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; for (d = l->l_ld; d->d_tag != DT_NULL; ++d) 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; } diff --git a/posix/getopt.c b/posix/getopt.c index 85647e2d36..371b6f10f9 100644 --- a/posix/getopt.c +++ b/posix/getopt.c @@ -63,12 +63,15 @@ Cambridge, MA 02139, USA. */ #include <stdlib.h> #endif /* GNU C library. */ +#ifndef _ /* This is for other GNU distributions with internationalized messages. - The GNU C Library itself does not yet support such messages. */ -#if HAVE_LIBINTL_H + When compiling libc, the _ macro is predefined. */ +#ifdef HAVE_LIBINTL_H # include <libintl.h> +# define _(msgid) gettext (msgid) #else -# define gettext(msgid) (msgid) +# define _(msgid) (msgid) +#endif #endif /* 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 (opterr) - fprintf (stderr, gettext ("%s: option `%s' is ambiguous\n"), + fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen (nextchar); optind++; @@ -543,12 +546,12 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) if (argv[optind - 1][1] == '-') /* --option */ 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); else /* +option or -option */ 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); nextchar += strlen (nextchar); @@ -563,7 +566,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { if (opterr) fprintf (stderr, - gettext ("%s: option `%s' requires an argument\n"), + _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); nextchar += strlen (nextchar); return optstring[0] == ':' ? ':' : '?'; @@ -591,11 +594,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { if (argv[optind][1] == '-') /* --option */ - fprintf (stderr, gettext ("%s: unrecognized option `--%s'\n"), + fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0], nextchar); else /* +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); } nextchar = (char *) ""; @@ -620,10 +623,10 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { if (posixly_correct) /* 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); else - fprintf (stderr, gettext ("%s: invalid option -- %c\n"), + fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); } optopt = c; @@ -659,7 +662,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { /* 1003.2 specifies the format of this message. */ fprintf (stderr, - gettext ("%s: option requires an argument -- %c\n"), + _("%s: option requires an argument -- %c\n"), argv[0], c); } optopt = c; diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index e55a615287..2daf74957c 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -80,20 +80,75 @@ _dl_sysdep_start (void **start_argptr, void (*dl_main) (const Elf32_Phdr *phdr, Elf32_Word phent, Elf32_Addr *user_entry)) { + extern void _start (); + void go (int *argdata) { + extern unsigned int _dl_skip_args; /* rtld.c */ char **p; /* Cache the information in various global variables. */ _dl_argc = *argdata; - _dl_argv = (void *) &argdata[1]; + _dl_argv = 1 + (char **) argdata; _environ = &_dl_argv[_dl_argc + 1]; - for (p = _environ; *p; ++p); - _dl_hurd_data = (void *) ++p; + for (p = _environ; *p++;); /* Skip environ pointers and terminator. */ + + 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; 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 up and leave us to transfer control to USER_ENTRY. */ (*dl_main) ((const Elf32_Phdr *) _dl_hurd_data->phdr, @@ -106,6 +161,18 @@ unfmh(); /* XXX */ __mig_dealloc_reply_port (MACH_PORT_NULL); __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); /* Unwind the stack to ARGDATA and simulate a return from _dl_start |