diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | config.h.in | 3 | ||||
-rwxr-xr-x | configure | 6 | ||||
-rw-r--r-- | elf/dl-load.c | 12 | ||||
-rw-r--r-- | elf/rtld.c | 42 | ||||
-rw-r--r-- | include/libc-symbols.h | 10 | ||||
-rw-r--r-- | sysdeps/generic/dl-sysdep.c | 6 | ||||
-rw-r--r-- | sysdeps/generic/ldsodefs.h | 8 |
8 files changed, 69 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog index e82c7912c9..f28abd9eb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2004-01-14 Ulrich Drepper <drepper@redhat.com> + + * configure.in: Define HAVE_Z_RELRO if the linker supports -z relro. + * config.h.in: Add entry for HAVE_Z_RELRO. + * include/libc-symbols.h: Define attribute_relro. + * elf/dl-load.c: Add attribute_relro to env_path_list, capstr, ncapstr, + max_capstrlen, and max_dirnamelen definitions. + * elf/rtld.c: Add attribute_relro to _dl_argc, _dl_argv, _dl_skip_args, + load_time, start_time, library_path, preloadlist, version_info, + any_debug. + Remove rtld_total_time. Make it a local variable. Pass pointer to + it to print_statistics. Change print_statistics accordingly. + * sysdeps/generic/dl-sysdep.c: Add attribute_relro to _dl_auxv. Use + attribute_relro instead of explicitly assigning variable to the + .data.rel.ro section for __libc_enable_secure and __libc_stack_end. + * sysdeps/generic/ldsodefs.h: Declare __libc_stack_end, _dl_argc, + _dl_argv, _dl_argv_internal with attribute_relro. + 2004-01-13 Segher Boessenkool <boessen@de.ibm.com> * Makerules (gen-as-const): Don't silently continue on failure. diff --git a/config.h.in b/config.h.in index 636ebeff90..ed6e701df0 100644 --- a/config.h.in +++ b/config.h.in @@ -202,6 +202,9 @@ /* Defined if forced unwind support is available. */ #undef HAVE_FORCED_UNWIND +/* Defined if the linker supports the -z relro option. */ +#undef HAVE_Z_RELRO + /* */ diff --git a/configure b/configure index 8f5fa38d33..bcfe8264c8 100755 --- a/configure +++ b/configure @@ -5516,6 +5516,12 @@ fi echo "$as_me:$LINENO: result: $libc_cv_z_relro" >&5 echo "${ECHO_T}$libc_cv_z_relro" >&6 + if test $libc_cv_z_relro = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_Z_RELRO 1 +_ACEOF + + fi echo "$as_me:$LINENO: checking for -Bgroup option" >&5 echo $ECHO_N "checking for -Bgroup option... $ECHO_C" >&6 diff --git a/elf/dl-load.c b/elf/dl-load.c index 99ca6a054d..527a5f18c1 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -121,12 +121,12 @@ struct filebuf }; /* This is the decomposed LD_LIBRARY_PATH search path. */ -static struct r_search_path_struct env_path_list; +static struct r_search_path_struct env_path_list attribute_relro; /* List of the hardware capabilities we might end up using. */ -static const struct r_strlenpair *capstr; -static size_t ncapstr; -static size_t max_capstrlen; +static const struct r_strlenpair *capstr attribute_relro; +static size_t ncapstr attribute_relro; +static size_t max_capstrlen attribute_relro; /* Get the generated information about the trusted directories. */ @@ -357,9 +357,9 @@ add_name_to_object (struct link_map *l, const char *name) } /* Standard search directories. */ -static struct r_search_path_struct rtld_search_dirs; +static struct r_search_path_struct rtld_search_dirs attribute_relro; -static size_t max_dirnamelen; +static size_t max_dirnamelen attribute_relro; static struct r_search_path_elem ** fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep, diff --git a/elf/rtld.c b/elf/rtld.c index 91723ccb77..62e0dd5dec 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -57,7 +57,7 @@ static void print_missing_version (int errcode, const char *objname, const char *errsting); /* Print the various times we collected. */ -static void print_statistics (void); +static void print_statistics (hp_timing_t *total_timep); /* This is a list of all the modes the dynamic loader can be in. */ enum mode { normal, list, verify, trace }; @@ -67,12 +67,12 @@ enum mode { normal, list, verify, trace }; all the entries. */ static void process_envvars (enum mode *modep); -int _dl_argc attribute_hidden; -char **_dl_argv = NULL; +int _dl_argc attribute_relro attribute_hidden; +char **_dl_argv attribute_relro; INTDEF(_dl_argv) /* Nonzero if we were run directly. */ -unsigned int _dl_skip_args attribute_hidden; +unsigned int _dl_skip_args attribute_relro attribute_hidden; /* Set nonzero during loading and initialization of executable and libraries, cleared before the executable's entry point runs. This @@ -115,6 +115,7 @@ extern struct rtld_global _rtld_local static void dl_main (const ElfW(Phdr) *phdr, ElfW(Word) phnum, ElfW(Addr) *user_entry); +/* These two variables cannot be moved into .data.rel.ro. */ static struct libname_list _dl_rtld_libname; static struct libname_list _dl_rtld_libname2; @@ -126,10 +127,9 @@ static struct libname_list _dl_rtld_libname2; /* Variable for statistics. */ #ifndef HP_TIMING_NONAVAIL -static hp_timing_t rtld_total_time; static hp_timing_t relocate_time; -static hp_timing_t load_time; -static hp_timing_t start_time; +static hp_timing_t load_time attribute_relro; +static hp_timing_t start_time attribute_relro; #endif /* Additional definitions needed by TLS initialization. */ @@ -263,6 +263,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info) start_addr = _dl_sysdep_start (arg, &dl_main); #ifndef HP_TIMING_NONAVAIL + hp_timing_t rtld_total_time; if (HP_TIMING_AVAIL) { hp_timing_t end_time; @@ -276,7 +277,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info) #endif if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_STATISTICS, 0)) - print_statistics (); + print_statistics (&rtld_total_time); return start_addr; } @@ -619,10 +620,12 @@ static void rtld_lock_default_unlock_recursive (void *lock) #endif -static const char *library_path; /* The library search path. */ -static const char *preloadlist; /* The list preloaded objects. */ -static int version_info; /* Nonzero if information about - versions has to be printed. */ +/* The library search path. */ +static const char *library_path attribute_relro; +/* The list preloaded objects. */ +static const char *preloadlist attribute_relro; +/* Nonzero if information about versions has to be printed. */ +static int version_info attribute_relro; static void dl_main (const ElfW(Phdr) *phdr, @@ -1815,7 +1818,7 @@ print_missing_version (int errcode __attribute__ ((unused)), } /* Nonzero if any of the debugging options is enabled. */ -static int any_debug; +static int any_debug attribute_relro; /* Process the string given as the parameter which explains which debugging options are enabled. */ @@ -2127,7 +2130,7 @@ process_envvars (enum mode *modep) /* Print the various times we collected. */ static void -print_statistics (void) +print_statistics (hp_timing_t *rtld_total_timep) { #ifndef HP_TIMING_NONAVAIL char buf[200]; @@ -2137,18 +2140,15 @@ print_statistics (void) /* Total time rtld used. */ if (HP_TIMING_AVAIL) { - HP_TIMING_PRINT (buf, sizeof (buf), rtld_total_time); + HP_TIMING_PRINT (buf, sizeof (buf), *rtld_total_timep); INTUSE(_dl_debug_printf) ("\nruntime linker statistics:\n" " total startup time in dynamic loader: %s\n", buf); - } - /* Print relocation statistics. */ - if (HP_TIMING_AVAIL) - { + /* Print relocation statistics. */ char pbuf[30]; HP_TIMING_PRINT (buf, sizeof (buf), relocate_time); - cp = _itoa ((1000ULL * relocate_time) / rtld_total_time, + cp = _itoa ((1000ULL * relocate_time) / *rtld_total_timep, pbuf + sizeof (pbuf), 10, 0); wp = pbuf; switch (pbuf + sizeof (pbuf) - cp) @@ -2198,7 +2198,7 @@ print_statistics (void) { char pbuf[30]; HP_TIMING_PRINT (buf, sizeof (buf), load_time); - cp = _itoa ((1000ULL * load_time) / rtld_total_time, + cp = _itoa ((1000ULL * load_time) / *rtld_total_timep, pbuf + sizeof (pbuf), 10, 0); wp = pbuf; switch (pbuf + sizeof (pbuf) - cp) diff --git a/include/libc-symbols.h b/include/libc-symbols.h index bb4947304b..d14f26c73d 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -1,6 +1,6 @@ /* Support macros for making weak and strong aliases for symbols, and for using symbol sets and linker warnings with GNU ld. - Copyright (C) 1995-1998,2000,2001,2002,2003 Free Software Foundation, Inc. + Copyright (C) 1995-1998,2000-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 @@ -458,12 +458,18 @@ for linking") # define attribute_hidden #endif -#if defined HAVE_TLS_MODEL_ATTRIBUTE +#ifdef HAVE_TLS_MODEL_ATTRIBUTE # define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec"))) #else # define attribute_tls_model_ie #endif +#ifdef HAVE_Z_RELRO +# define attribute_relro __attribute__ ((section (".data.rel.ro"))) +#else +# define attribute_relro +#endif + /* Handling on non-exported internal names. We have to do this only for shared code. */ #ifdef SHARED diff --git a/sysdeps/generic/dl-sysdep.c b/sysdeps/generic/dl-sysdep.c index fd528eb01f..704dbdb432 100644 --- a/sysdeps/generic/dl-sysdep.c +++ b/sysdeps/generic/dl-sysdep.c @@ -48,14 +48,14 @@ extern void __libc_check_standard_fds (void); #ifdef NEED_DL_BASE_ADDR ElfW(Addr) _dl_base_addr; #endif -int __libc_enable_secure __attribute__ ((section (".data.rel.ro"))) = 0; +int __libc_enable_secure attribute_relro = 0; INTVARDEF(__libc_enable_secure) int __libc_multiple_libcs = 0; /* Defining this here avoids the inclusion of init-first. */ /* This variable contains the lowest stack address ever used. */ -void *__libc_stack_end __attribute__ ((section (".data.rel.ro"))); +void *__libc_stack_end attribute_relro; rtld_hidden_data_def(__libc_stack_end) -static ElfW(auxv_t) *_dl_auxv; +static ElfW(auxv_t) *_dl_auxv attribute_relro; #ifndef DL_FIND_ARG_COMPONENTS # define DL_FIND_ARG_COMPONENTS(cookie, argc, argv, envp, auxp) \ diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index f511c5d36f..a05e5c76d4 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -461,14 +461,14 @@ rtld_hidden_proto (_dl_make_stack_executable) might use the variable which results in copy relocations on some platforms. But this does not matter, ld.so can always use the local copy. */ -extern void *__libc_stack_end; +extern void *__libc_stack_end attribute_relro; rtld_hidden_proto (__libc_stack_end) /* Parameters passed to the dynamic linker. */ -extern int _dl_argc attribute_hidden; -extern char **_dl_argv; +extern int _dl_argc attribute_hidden attribute_relro; +extern char **_dl_argv attribute_relro; #ifdef IS_IN_rtld -extern char **_dl_argv_internal attribute_hidden; +extern char **_dl_argv_internal attribute_hidden attribute_relro; # define rtld_progname (INTUSE(_dl_argv)[0]) #else # define rtld_progname _dl_argv[0] |