diff options
author | Ulrich Drepper <drepper@redhat.com> | 2004-01-13 08:36:54 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2004-01-13 08:36:54 +0000 |
commit | ed20b3d9cc5ce78fd71f32c47b2eb7a897c7a25d (patch) | |
tree | c4ea660173f2c8cc138e8f0f1c64055a156c5036 /elf/rtld.c | |
parent | 1c563add69af03557ba47a4a13790d821133478c (diff) | |
download | glibc-ed20b3d9cc5ce78fd71f32c47b2eb7a897c7a25d.zip glibc-ed20b3d9cc5ce78fd71f32c47b2eb7a897c7a25d.tar.gz glibc-ed20b3d9cc5ce78fd71f32c47b2eb7a897c7a25d.tar.bz2 |
Update.
2004-01-13 Ulrich Drepper <drepper@redhat.com>
* Makeconfig: Define relro-LDFLAGS if have-z-relro==yes. Add it to
LDFLAGS.so and LDFLAGS-rtld.
(+link): Add relro-LDFLAGS.
* Makeconfig (shlib.lds): Place __libc_subfreeres, __libc_atexit, and
__libc_thread_subfreeres sections after .jcr section.
* config.make.in: Add have-z-relro.
* configure.in: Add check for -z relro option.
* include/link.h (struct link_map): Add relro_addr and relro_size
members.
* elf/dl-load.c (_dl_map_object_from_fd): Recognize PT_GNU_RELRO.
* elf/dl-reloc.c (_dl_relocate_object): At the end, make relro
part of loaded segments read-only.
* elf/elf.h: Define PT_GNU_RELRO.
* elf/rtld.c (_dl_start): Recognize PT_GNU_RELRO of ld.so.
(dl_main): Recognize PT_GNU_RELRO of the application. Call
_dl_debug_initialize and initialize l_info[DT_DEBUG] before
relocations.
Diffstat (limited to 'elf/rtld.c')
-rw-r--r-- | elf/rtld.c | 84 |
1 files changed, 47 insertions, 37 deletions
@@ -1,5 +1,5 @@ /* Run time dynamic linker. - Copyright (C) 1995-2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1995-2002, 2003, 2004 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 @@ -332,13 +332,14 @@ _dl_start (void *arg) bootstrap_map.l_tls_offset = NO_TLS_OFFSET; #endif -#if USE___THREAD /* Get the dynamic linker's own program header. First we need the ELF file header. The `_begin' symbol created by the linker script points to it. When we have something like GOTOFF relocs, we can use a plain reference to find the runtime address. Without that, we have to rely on the `l_addr' value, which is not the value we want when prelinked. */ +#if USE___THREAD dtv_t initdtv[3]; +#endif /* USE___THREAD */ ElfW(Ehdr) *ehdr # ifdef DONT_USE_BOOTSTRAP_MAP = (ElfW(Ehdr) *) &_begin; @@ -348,6 +349,7 @@ _dl_start (void *arg) ElfW(Phdr) *phdr = (ElfW(Phdr) *) ((void *) ehdr + ehdr->e_phoff); size_t cnt = ehdr->e_phnum; /* PT_TLS is usually the last phdr. */ while (cnt-- > 0) +#if USE___THREAD if (phdr[cnt].p_type == PT_TLS) { void *tlsblock; @@ -442,11 +444,14 @@ _dl_start (void *arg) /* So far this is module number one. */ bootstrap_map.l_tls_modid = 1; - - /* There can only be one PT_TLS entry. */ - break; } + else #endif /* USE___THREAD */ + if (phdr[cnt].p_type == PT_GNU_RELRO) + { + bootstrap_map.l_relro_addr = phdr[cnt].p_vaddr; + bootstrap_map.l_relro_size = phdr[cnt].p_memsz; + } #ifdef ELF_MACHINE_BEFORE_RTLD_RELOC ELF_MACHINE_BEFORE_RTLD_RELOC (bootstrap_map.l_info); @@ -777,6 +782,11 @@ of this helper program; chances are you did not intend to run this program.\n\ GL(dl_stack_flags) = ph->p_flags; break; } + else if (ph->p_type == PT_GNU_RELRO) + { + GL(dl_loaded)->l_relro_addr = ph->p_vaddr; + GL(dl_loaded)->l_relro_size = ph->p_memsz; + } if (__builtin_expect (mode, normal) == verify) { @@ -1598,6 +1608,35 @@ cannot allocate TLS data structures for initial thread"); _dl_printf ("\nprelink checking: %s\n", prelinked ? "ok" : "failed"); } + + /* Initialize _r_debug. */ + struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_addr); + { + struct link_map *l; + + l = GL(dl_loaded); + +#ifdef ELF_MACHINE_DEBUG_SETUP + + /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way. */ + + ELF_MACHINE_DEBUG_SETUP (l, r); + ELF_MACHINE_DEBUG_SETUP (&GL(dl_rtld_map), r); + +#else + + if (l->l_info[DT_DEBUG] != NULL) + /* There is a DT_DEBUG entry in the dynamic section. Fill it in + with the run-time address of the r_debug structure */ + l->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r; + + /* Fill in the pointer in the dynamic linker's own dynamic section, in + case you run gdb on the dynamic linker directly. */ + if (GL(dl_rtld_map).l_info[DT_DEBUG] != NULL) + GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r; +#endif + } + if (prelinked) { struct link_map *l; @@ -1738,38 +1777,9 @@ cannot allocate TLS data structures for initial thread"); #endif NONTLS_INIT_TP; - { - /* Initialize _r_debug. */ - struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_addr); - struct link_map *l; - - l = GL(dl_loaded); - -#ifdef ELF_MACHINE_DEBUG_SETUP - - /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way. */ - - ELF_MACHINE_DEBUG_SETUP (l, r); - ELF_MACHINE_DEBUG_SETUP (&GL(dl_rtld_map), r); - -#else - - if (l->l_info[DT_DEBUG] != NULL) - /* There is a DT_DEBUG entry in the dynamic section. Fill it in - with the run-time address of the r_debug structure */ - l->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r; - - /* Fill in the pointer in the dynamic linker's own dynamic section, in - case you run gdb on the dynamic linker directly. */ - if (GL(dl_rtld_map).l_info[DT_DEBUG] != NULL) - GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r; - -#endif - - /* Notify the debugger that all objects are now mapped in. */ - r->r_state = RT_ADD; - INTUSE(_dl_debug_state) (); - } + /* Notify the debugger that all objects are now mapped in. */ + r->r_state = RT_ADD; + INTUSE(_dl_debug_state) (); #ifndef MAP_COPY /* We must munmap() the cache file. */ |