From 879bf2e65a9ddaea34fe0428ab0f71caca4b4d00 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 30 Sep 1995 21:18:30 +0000 Subject: * 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. --- elf/dl-init.c | 2 +- elf/dl-load.c | 29 ++++++++++++++++------------- elf/link.h | 8 +++----- elf/rtld.c | 6 ++++-- 4 files changed, 24 insertions(+), 21 deletions(-) (limited to 'elf') 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; } -- cgit 1.4.1