From fdc93e12a77866cafd1aae4463d89cef2c01d9b1 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 17 Jan 2009 11:47:10 -0800 Subject: [PATCH] Move argp_program_version_hook and argp_program_bug_address variables in all programs into the .rodata section. --- lib/ChangeLog | 5 +++++ lib/system.h | 14 +++++++++++++- src/ChangeLog | 18 ++++++++++++++++++ src/addr2line.c | 6 ++++-- src/ar.c | 5 +++-- src/elfcmp.c | 5 +++-- src/elflint.c | 5 ++--- src/findtextrel.c | 6 ++++-- src/ld.c | 4 ++-- src/nm.c | 4 ++-- src/objdump.c | 4 ++-- src/ranlib.c | 4 ++-- src/readelf.c | 4 ++-- src/size.c | 4 ++-- src/strings.c | 4 ++-- src/strip.c | 4 ++-- src/unstrip.c | 5 ++--- 17 files changed, 70 insertions(+), 31 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 8791640b1..0774524c5 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2009-01-17 Ulrich Drepper + + * system.h (ARGP_PROGRAM_VERSION_HOOK_DEF): Define. + (ARGP_PROGRAM_BUG_ADDRESS_DEF): Define. + 2009-01-10 Ulrich Drepper * eu-config.h: Remove tls_key_t, key_create, getspecific, setspecific, diff --git a/lib/system.h b/lib/system.h index 23c666ad8..10b4734a4 100644 --- a/lib/system.h +++ b/lib/system.h @@ -1,5 +1,5 @@ /* Declarations for common convenience functions. - Copyright (C) 2006 Red Hat, Inc. + Copyright (C) 2006, 2009 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -78,4 +78,16 @@ extern int crc32_file (int fd, uint32_t *resp); #define pread_retry(fd, buf, len, off) \ TEMP_FAILURE_RETRY (pread (fd, buf, len, off)) + +/* We need define two variables, argp_program_version_hook and + argp_program_bug_address, in all programs. argp.h declares these + variables as non-const (which is correct in general). But we can + do better, it is not going to change. So we want to move them into + the .rodata section. Define macros to do the trick. */ +#define ARGP_PROGRAM_VERSION_HOOK_DEF \ + void (*const apvh) (FILE *, struct argp_state *) \ + __asm ("argp_program_version_hook") +#define ARGP_PROGRAM_BUG_ADDRESS_DEF \ + const char *const apba__ __asm ("argp_program_bug_address") + #endif /* system.h */ diff --git a/src/ChangeLog b/src/ChangeLog index 4a9b63162..97fd4495a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,21 @@ +2009-01-17 Ulrich Drepper + + * addr2line.c: Use ARGP_PROGRAM_VERSION_HOOK_DEF and + ARGP_PROGRAM_BUG_ADDRESS_DEF. + * ar.c: Likewise. + * elfcmp.c: Likewise. + * elflint.c: Likewise. + * findtextrel.c: Likewise. + * ld.c: Likewise. + * nm.c: Likewise. + * objdump.c: Likewise. + * ranlib.c: Likewise. + * readelf.c: Likewise. + * size.c: Likewise. + * strings.c: Likewise. + * strip.c: Likewise. + * unstrip.c: Likewise. + 2009-01-16 Ulrich Drepper * elflint.c (check_program_header): Check that PT_GNU_EH_FRAME entry diff --git a/src/addr2line.c b/src/addr2line.c index 7141e2696..5a7b0456b 100644 --- a/src/addr2line.c +++ b/src/addr2line.c @@ -46,13 +46,15 @@ #include #include +#include + /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Values for the parameters which have no short form. */ diff --git a/src/ar.c b/src/ar.c index 961db241d..a7a12329c 100644 --- a/src/ar.c +++ b/src/ar.c @@ -55,7 +55,8 @@ /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; + /* Prototypes for local functions. */ static int do_oper_extract (int oper, const char *arfname, char **argv, int argc, long int instance); @@ -66,7 +67,7 @@ static int do_oper_insert (int oper, const char *arfname, char **argv, /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Definitions of arguments for argp functions. */ diff --git a/src/elfcmp.c b/src/elfcmp.c index 8903efb1f..a15963652 100644 --- a/src/elfcmp.c +++ b/src/elfcmp.c @@ -41,6 +41,7 @@ #include #include +#include #include "../libelf/elf-knowledge.h" #include "../libebl/libeblP.h" @@ -53,10 +54,10 @@ static int regioncompare (const void *p1, const void *p2); /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Values for the parameters which have no short form. */ #define OPT_GAPS 0x100 diff --git a/src/elflint.c b/src/elflint.c index 35368a5ef..1c508c47b 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -56,10 +56,10 @@ /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; #define ARGP_strict 300 #define ARGP_gnuld 301 @@ -67,7 +67,6 @@ const char *argp_program_bug_address = PACKAGE_BUGREPORT; /* Definitions of arguments for argp functions. */ static const struct argp_option options[] = { - { "strict", ARGP_strict, NULL, 0, N_("Be extremely strict, flag level 2 features."), 0 }, { "quiet", 'q', NULL, 0, N_("Do not print anything if successful"), 0 }, diff --git a/src/findtextrel.c b/src/findtextrel.c index 2fd99c960..9d10982f1 100644 --- a/src/findtextrel.c +++ b/src/findtextrel.c @@ -44,6 +44,8 @@ #include #include +#include + struct segments { @@ -54,10 +56,10 @@ struct segments /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Values for the parameters which have no short form. */ #define OPT_DEBUGINFO 0x100 diff --git a/src/ld.c b/src/ld.c index b4cc6cc74..989bfabaf 100644 --- a/src/ld.c +++ b/src/ld.c @@ -48,10 +48,10 @@ /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Values for the various options. */ diff --git a/src/nm.c b/src/nm.c index 8b8f547f3..8833948a7 100644 --- a/src/nm.c +++ b/src/nm.c @@ -58,10 +58,10 @@ /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Values for the parameters which have no short form. */ diff --git a/src/objdump.c b/src/objdump.c index 55d3ae2e2..7f6394100 100644 --- a/src/objdump.c +++ b/src/objdump.c @@ -49,10 +49,10 @@ /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Definitions of arguments for argp functions. */ diff --git a/src/ranlib.c b/src/ranlib.c index f456b997f..e92dc89b4 100644 --- a/src/ranlib.c +++ b/src/ranlib.c @@ -58,10 +58,10 @@ static int handle_file (const char *fname); /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Definitions of arguments for argp functions. */ diff --git a/src/readelf.c b/src/readelf.c index 5d74cb56f..a3223eb40 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -61,10 +61,10 @@ /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Definitions of arguments for argp functions. */ static const struct argp_option options[] = diff --git a/src/size.c b/src/size.c index 9f59cceb9..f6f23d55f 100644 --- a/src/size.c +++ b/src/size.c @@ -50,10 +50,10 @@ /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Values for the parameters which have no short form. */ diff --git a/src/strings.c b/src/strings.c index aebf07bdf..b69f2ad2f 100644 --- a/src/strings.c +++ b/src/strings.c @@ -59,10 +59,10 @@ static int read_elf (Elf *elf, int fd, const char *fname, off64_t fdlen); /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Definitions of arguments for argp functions. */ static const struct argp_option options[] = diff --git a/src/strip.c b/src/strip.c index 3ca047afe..1958bb511 100644 --- a/src/strip.c +++ b/src/strip.c @@ -55,10 +55,10 @@ /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Values for the parameters which have no short form. */ diff --git a/src/unstrip.c b/src/unstrip.c index 4a6fd197a..97b73c6f2 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -64,11 +64,10 @@ /* Name and version of program. */ static void print_version (FILE *stream, struct argp_state *state); -void (*argp_program_version_hook) (FILE *, struct argp_state *) - = print_version; +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; /* Bug report address. */ -const char *argp_program_bug_address = PACKAGE_BUGREPORT; +ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Definitions of arguments for argp functions. */ static const struct argp_option options[] = -- 2.47.2