aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-09-20 07:43:16 +0000
committerUlrich Drepper <drepper@redhat.com>2004-09-20 07:43:16 +0000
commitefec50797a13f527967ec8e0113fd9405ec7e7bc (patch)
tree3ae11273787feef364349f30865b06aba89664b6
parent2edb61e3f955bfcc9dd3cb6b3b1acfe4806234a6 (diff)
downloadglibc-efec50797a13f527967ec8e0113fd9405ec7e7bc.tar
glibc-efec50797a13f527967ec8e0113fd9405ec7e7bc.tar.gz
glibc-efec50797a13f527967ec8e0113fd9405ec7e7bc.tar.bz2
glibc-efec50797a13f527967ec8e0113fd9405ec7e7bc.zip
Update.
2004-09-20 Ulrich Drepper <drepper@redhat.com> * elf/dl-load.c (_dl_map_object_from_fd): Add some error checking. Reorder code slightly. * elf/rtld.c (dl_main): No need to check whether l_info[DT_HASH] is non-null, _dl_setup_hash will do that.
-rw-r--r--ChangeLog7
-rw-r--r--elf/dl-load.c139
-rw-r--r--elf/rtld.c5
3 files changed, 80 insertions, 71 deletions
diff --git a/ChangeLog b/ChangeLog
index 768ae143c3..cc17efe616 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-09-20 Ulrich Drepper <drepper@redhat.com>
+
+ * elf/dl-load.c (_dl_map_object_from_fd): Add some error checking.
+ Reorder code slightly.
+ * elf/rtld.c (dl_main): No need to check whether l_info[DT_HASH]
+ is non-null, _dl_setup_hash will do that.
+
2004-09-19 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/setegid.c [HAVE_PTR__NPTL_SETXID]: Call
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 059be4eacf..8a5aa21402 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1126,21 +1126,20 @@ cannot allocate TLS data structures for initial thread");
goto postmap;
}
- else
- {
- /* This object is loaded at a fixed address. This must never
- happen for objects loaded with dlopen(). */
- if (__builtin_expect ((mode & __RTLD_OPENEXEC) == 0, 0))
- {
- errstring = N_("cannot dynamically load executable");
- goto call_lose;
- }
- /* Notify ELF_PREFERRED_ADDRESS that we have to load this one
- fixed. */
- ELF_FIXED_ADDRESS (loader, c->mapstart);
+ /* This object is loaded at a fixed address. This must never
+ happen for objects loaded with dlopen(). */
+ if (__builtin_expect ((mode & __RTLD_OPENEXEC) == 0, 0))
+ {
+ errstring = N_("cannot dynamically load executable");
+ goto call_lose;
}
+ /* Notify ELF_PREFERRED_ADDRESS that we have to load this one
+ fixed. */
+ ELF_FIXED_ADDRESS (loader, c->mapstart);
+
+
/* Remember which part of the address space this object uses. */
l->l_map_start = c->mapstart + l->l_addr;
l->l_map_end = l->l_map_start + maplength;
@@ -1220,43 +1219,8 @@ cannot allocate TLS data structures for initial thread");
++c;
}
-
- if (l->l_phdr == NULL)
- {
- /* The program header is not contained in any of the segments.
- We have to allocate memory ourself and copy it over from
- out temporary place. */
- ElfW(Phdr) *newp = (ElfW(Phdr) *) malloc (header->e_phnum
- * sizeof (ElfW(Phdr)));
- if (newp == NULL)
- {
- errstring = N_("cannot allocate memory for program header");
- goto call_lose_errno;
- }
-
- l->l_phdr = memcpy (newp, phdr,
- (header->e_phnum * sizeof (ElfW(Phdr))));
- l->l_phdr_allocated = 1;
- }
- else
- /* Adjust the PT_PHDR value by the runtime load address. */
- l->l_phdr = (ElfW(Phdr) *) ((ElfW(Addr)) l->l_phdr + l->l_addr);
}
-#ifdef USE_TLS
- /* Adjust the address of the TLS initialization image. */
- if (l->l_tls_initimage != NULL)
- l->l_tls_initimage = (char *) l->l_tls_initimage + l->l_addr;
-#endif
-
- /* We are done mapping in the file. We no longer need the descriptor. */
- __close (fd);
- /* Signal that we closed the file. */
- fd = -1;
-
- if (l->l_type == lt_library && type == ET_EXEC)
- l->l_type = lt_executable;
-
if (l->l_ld == 0)
{
if (__builtin_expect (type == ET_DYN, 0))
@@ -1268,27 +1232,10 @@ cannot allocate TLS data structures for initial thread");
else
l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr);
- l->l_entry += l->l_addr;
-
- if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0))
- _dl_debug_printf ("\
- dynamic: 0x%0*lx base: 0x%0*lx size: 0x%0*Zx\n\
- entry: 0x%0*lx phdr: 0x%0*lx phnum: %*u\n\n",
- (int) sizeof (void *) * 2,
- (unsigned long int) l->l_ld,
- (int) sizeof (void *) * 2,
- (unsigned long int) l->l_addr,
- (int) sizeof (void *) * 2, maplength,
- (int) sizeof (void *) * 2,
- (unsigned long int) l->l_entry,
- (int) sizeof (void *) * 2,
- (unsigned long int) l->l_phdr,
- (int) sizeof (void *) * 2, l->l_phnum);
-
elf_get_dynamic_info (l, NULL);
- /* Make sure we are not dlopen'ing an object
- that has the DF_1_NOOPEN flag set. */
+ /* Make sure we are not dlopen'ing an object that has the
+ DF_1_NOOPEN flag set. */
if (__builtin_expect (l->l_flags_1 & DF_1_NOOPEN, 0)
&& (mode & __RTLD_DLOPEN))
{
@@ -1305,6 +1252,27 @@ cannot allocate TLS data structures for initial thread");
goto call_lose;
}
+ if (l->l_phdr == NULL)
+ {
+ /* The program header is not contained in any of the segments.
+ We have to allocate memory ourself and copy it over from out
+ temporary place. */
+ ElfW(Phdr) *newp = (ElfW(Phdr) *) malloc (header->e_phnum
+ * sizeof (ElfW(Phdr)));
+ if (newp == NULL)
+ {
+ errstring = N_("cannot allocate memory for program header");
+ goto call_lose_errno;
+ }
+
+ l->l_phdr = memcpy (newp, phdr,
+ (header->e_phnum * sizeof (ElfW(Phdr))));
+ l->l_phdr_allocated = 1;
+ }
+ else
+ /* Adjust the PT_PHDR value by the runtime load address. */
+ l->l_phdr = (ElfW(Phdr) *) ((ElfW(Addr)) l->l_phdr + l->l_addr);
+
if (__builtin_expect ((stack_flags &~ GL(dl_stack_flags)) & PF_X, 0))
{
/* The stack is presently not executable, but this module
@@ -1334,8 +1302,43 @@ cannot enable executable stack as shared object requires");
}
}
- if (l->l_info[DT_HASH])
- _dl_setup_hash (l);
+#ifdef USE_TLS
+ /* Adjust the address of the TLS initialization image. */
+ if (l->l_tls_initimage != NULL)
+ l->l_tls_initimage = (char *) l->l_tls_initimage + l->l_addr;
+#endif
+
+ /* We are done mapping in the file. We no longer need the descriptor. */
+ if (__builtin_expect (__close (fd) != 0, 0))
+ {
+ errstring = N_("cannot close file descriptor");
+ goto call_lose_errno;
+ }
+ /* Signal that we closed the file. */
+ fd = -1;
+
+ if (l->l_type == lt_library && type == ET_EXEC)
+ l->l_type = lt_executable;
+
+ l->l_entry += l->l_addr;
+
+ if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0))
+ _dl_debug_printf ("\
+ dynamic: 0x%0*lx base: 0x%0*lx size: 0x%0*Zx\n\
+ entry: 0x%0*lx phdr: 0x%0*lx phnum: %*u\n\n",
+ (int) sizeof (void *) * 2,
+ (unsigned long int) l->l_ld,
+ (int) sizeof (void *) * 2,
+ (unsigned long int) l->l_addr,
+ (int) sizeof (void *) * 2, maplength,
+ (int) sizeof (void *) * 2,
+ (unsigned long int) l->l_entry,
+ (int) sizeof (void *) * 2,
+ (unsigned long int) l->l_phdr,
+ (int) sizeof (void *) * 2, l->l_phnum);
+
+ /* Set up the symbol hash table. */
+ _dl_setup_hash (l);
/* If this object has DT_SYMBOLIC set modify now its scope. We don't
have to do this for the main map. */
diff --git a/elf/rtld.c b/elf/rtld.c
index 93c45311d4..2daf05a6d6 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1039,9 +1039,8 @@ of this helper program; chances are you did not intend to run this program.\n\
{
/* Extract the contents of the dynamic section for easy access. */
elf_get_dynamic_info (GL(dl_loaded), NULL);
- if (GL(dl_loaded)->l_info[DT_HASH])
- /* Set up our cache of pointers into the hash table. */
- _dl_setup_hash (GL(dl_loaded));
+ /* Set up our cache of pointers into the hash table. */
+ _dl_setup_hash (GL(dl_loaded));
}
if (__builtin_expect (mode, normal) == verify)