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.
This commit is contained in:
Ulrich Drepper 2004-01-15 06:38:27 +00:00
parent cb6ee14a12
commit 392a6b5265
8 changed files with 69 additions and 36 deletions

View File

@ -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> 2004-01-13 Segher Boessenkool <boessen@de.ibm.com>
* Makerules (gen-as-const): Don't silently continue on failure. * Makerules (gen-as-const): Don't silently continue on failure.

View File

@ -202,6 +202,9 @@
/* Defined if forced unwind support is available. */ /* Defined if forced unwind support is available. */
#undef HAVE_FORCED_UNWIND #undef HAVE_FORCED_UNWIND
/* Defined if the linker supports the -z relro option. */
#undef HAVE_Z_RELRO
/* /*
*/ */

6
configure vendored
View File

@ -5516,6 +5516,12 @@ fi
echo "$as_me:$LINENO: result: $libc_cv_z_relro" >&5 echo "$as_me:$LINENO: result: $libc_cv_z_relro" >&5
echo "${ECHO_T}$libc_cv_z_relro" >&6 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 "$as_me:$LINENO: checking for -Bgroup option" >&5
echo $ECHO_N "checking for -Bgroup option... $ECHO_C" >&6 echo $ECHO_N "checking for -Bgroup option... $ECHO_C" >&6

View File

@ -121,12 +121,12 @@ struct filebuf
}; };
/* This is the decomposed LD_LIBRARY_PATH search path. */ /* 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. */ /* List of the hardware capabilities we might end up using. */
static const struct r_strlenpair *capstr; static const struct r_strlenpair *capstr attribute_relro;
static size_t ncapstr; static size_t ncapstr attribute_relro;
static size_t max_capstrlen; static size_t max_capstrlen attribute_relro;
/* Get the generated information about the trusted directories. */ /* 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. */ /* 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 ** static struct r_search_path_elem **
fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep, fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,

View File

@ -57,7 +57,7 @@ static void print_missing_version (int errcode, const char *objname,
const char *errsting); const char *errsting);
/* Print the various times we collected. */ /* 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. */ /* This is a list of all the modes the dynamic loader can be in. */
enum mode { normal, list, verify, trace }; enum mode { normal, list, verify, trace };
@ -67,12 +67,12 @@ enum mode { normal, list, verify, trace };
all the entries. */ all the entries. */
static void process_envvars (enum mode *modep); static void process_envvars (enum mode *modep);
int _dl_argc attribute_hidden; int _dl_argc attribute_relro attribute_hidden;
char **_dl_argv = NULL; char **_dl_argv attribute_relro;
INTDEF(_dl_argv) INTDEF(_dl_argv)
/* Nonzero if we were run directly. */ /* 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 /* Set nonzero during loading and initialization of executable and
libraries, cleared before the executable's entry point runs. This 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, static void dl_main (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
ElfW(Addr) *user_entry); 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_libname;
static struct libname_list _dl_rtld_libname2; static struct libname_list _dl_rtld_libname2;
@ -126,10 +127,9 @@ static struct libname_list _dl_rtld_libname2;
/* Variable for statistics. */ /* Variable for statistics. */
#ifndef HP_TIMING_NONAVAIL #ifndef HP_TIMING_NONAVAIL
static hp_timing_t rtld_total_time;
static hp_timing_t relocate_time; static hp_timing_t relocate_time;
static hp_timing_t load_time; static hp_timing_t load_time attribute_relro;
static hp_timing_t start_time; static hp_timing_t start_time attribute_relro;
#endif #endif
/* Additional definitions needed by TLS initialization. */ /* 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); start_addr = _dl_sysdep_start (arg, &dl_main);
#ifndef HP_TIMING_NONAVAIL #ifndef HP_TIMING_NONAVAIL
hp_timing_t rtld_total_time;
if (HP_TIMING_AVAIL) if (HP_TIMING_AVAIL)
{ {
hp_timing_t end_time; hp_timing_t end_time;
@ -276,7 +277,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
#endif #endif
if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_STATISTICS, 0)) if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_STATISTICS, 0))
print_statistics (); print_statistics (&rtld_total_time);
return start_addr; return start_addr;
} }
@ -619,10 +620,12 @@ static void rtld_lock_default_unlock_recursive (void *lock)
#endif #endif
static const char *library_path; /* The library search path. */ /* The library search path. */
static const char *preloadlist; /* The list preloaded objects. */ static const char *library_path attribute_relro;
static int version_info; /* Nonzero if information about /* The list preloaded objects. */
versions has to be printed. */ static const char *preloadlist attribute_relro;
/* Nonzero if information about versions has to be printed. */
static int version_info attribute_relro;
static void static void
dl_main (const ElfW(Phdr) *phdr, 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. */ /* 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 /* Process the string given as the parameter which explains which debugging
options are enabled. */ options are enabled. */
@ -2127,7 +2130,7 @@ process_envvars (enum mode *modep)
/* Print the various times we collected. */ /* Print the various times we collected. */
static void static void
print_statistics (void) print_statistics (hp_timing_t *rtld_total_timep)
{ {
#ifndef HP_TIMING_NONAVAIL #ifndef HP_TIMING_NONAVAIL
char buf[200]; char buf[200];
@ -2137,18 +2140,15 @@ print_statistics (void)
/* Total time rtld used. */ /* Total time rtld used. */
if (HP_TIMING_AVAIL) 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" INTUSE(_dl_debug_printf) ("\nruntime linker statistics:\n"
" total startup time in dynamic loader: %s\n", " total startup time in dynamic loader: %s\n",
buf); buf);
}
/* Print relocation statistics. */ /* Print relocation statistics. */
if (HP_TIMING_AVAIL)
{
char pbuf[30]; char pbuf[30];
HP_TIMING_PRINT (buf, sizeof (buf), relocate_time); 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); pbuf + sizeof (pbuf), 10, 0);
wp = pbuf; wp = pbuf;
switch (pbuf + sizeof (pbuf) - cp) switch (pbuf + sizeof (pbuf) - cp)
@ -2198,7 +2198,7 @@ print_statistics (void)
{ {
char pbuf[30]; char pbuf[30];
HP_TIMING_PRINT (buf, sizeof (buf), load_time); 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); pbuf + sizeof (pbuf), 10, 0);
wp = pbuf; wp = pbuf;
switch (pbuf + sizeof (pbuf) - cp) switch (pbuf + sizeof (pbuf) - cp)

View File

@ -1,6 +1,6 @@
/* Support macros for making weak and strong aliases for symbols, /* Support macros for making weak and strong aliases for symbols,
and for using symbol sets and linker warnings with GNU ld. 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. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or The GNU C Library is free software; you can redistribute it and/or
@ -458,12 +458,18 @@ for linking")
# define attribute_hidden # define attribute_hidden
#endif #endif
#if defined HAVE_TLS_MODEL_ATTRIBUTE #ifdef HAVE_TLS_MODEL_ATTRIBUTE
# define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec"))) # define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
#else #else
# define attribute_tls_model_ie # define attribute_tls_model_ie
#endif #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 /* Handling on non-exported internal names. We have to do this only
for shared code. */ for shared code. */
#ifdef SHARED #ifdef SHARED

View File

@ -48,14 +48,14 @@ extern void __libc_check_standard_fds (void);
#ifdef NEED_DL_BASE_ADDR #ifdef NEED_DL_BASE_ADDR
ElfW(Addr) _dl_base_addr; ElfW(Addr) _dl_base_addr;
#endif #endif
int __libc_enable_secure __attribute__ ((section (".data.rel.ro"))) = 0; int __libc_enable_secure attribute_relro = 0;
INTVARDEF(__libc_enable_secure) INTVARDEF(__libc_enable_secure)
int __libc_multiple_libcs = 0; /* Defining this here avoids the inclusion int __libc_multiple_libcs = 0; /* Defining this here avoids the inclusion
of init-first. */ of init-first. */
/* This variable contains the lowest stack address ever used. */ /* 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) 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 #ifndef DL_FIND_ARG_COMPONENTS
# define DL_FIND_ARG_COMPONENTS(cookie, argc, argv, envp, auxp) \ # define DL_FIND_ARG_COMPONENTS(cookie, argc, argv, envp, auxp) \

View File

@ -461,14 +461,14 @@ rtld_hidden_proto (_dl_make_stack_executable)
might use the variable which results in copy relocations on some might use the variable which results in copy relocations on some
platforms. But this does not matter, ld.so can always use the local platforms. But this does not matter, ld.so can always use the local
copy. */ copy. */
extern void *__libc_stack_end; extern void *__libc_stack_end attribute_relro;
rtld_hidden_proto (__libc_stack_end) rtld_hidden_proto (__libc_stack_end)
/* Parameters passed to the dynamic linker. */ /* Parameters passed to the dynamic linker. */
extern int _dl_argc attribute_hidden; extern int _dl_argc attribute_hidden attribute_relro;
extern char **_dl_argv; extern char **_dl_argv attribute_relro;
#ifdef IS_IN_rtld #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]) # define rtld_progname (INTUSE(_dl_argv)[0])
#else #else
# define rtld_progname _dl_argv[0] # define rtld_progname _dl_argv[0]