diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2018-09-17 08:50:42 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2018-09-17 08:53:29 -0700 |
commit | d839b9149957d9a8842c368caf97ef378d8c97af (patch) | |
tree | cf0716e5ff6f430baafb13d4f31744ba93e0b2cc | |
parent | e6cd1dc1e6c0d081382ee21c156b205204efc75b (diff) | |
download | gdb-d839b9149957d9a8842c368caf97ef378d8c97af.zip gdb-d839b9149957d9a8842c368caf97ef378d8c97af.tar.gz gdb-d839b9149957d9a8842c368caf97ef378d8c97af.tar.bz2 |
Free symbol buffers if they are no longer in use
add_specific_symbols allocates a buffer to hold symbols. It should be
freed only if it is no longer in use.
PR binutils/23633
* objcopy.c (strip_specific_buffer): New.
(strip_unneeded_buffer): Likewise.
(keep_specific_buffer): Likewise.
(localize_specific_buffer): Likewise.
(globalize_specific_buffer): Likewise.
(keepglobal_specific_buffer): Likewise.
(weaken_specific_buffer): Likewise.
(add_specific_symbols): Add an argument to return pointer to
allocated buffer.
(copy_main): Update add_specific_symbols to update pointers to
allocated buffer. Free pointers to allocated buffer before
return.
-rw-r--r-- | binutils/ChangeLog | 15 | ||||
-rw-r--r-- | binutils/objcopy.c | 53 |
2 files changed, 60 insertions, 8 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 5207db8..8c7a9e6 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,18 @@ +2018-09-17 H.J. Lu <hongjiu.lu@intel.com> + + * objcopy.c (strip_specific_buffer): New. + (strip_unneeded_buffer): Likewise. + (keep_specific_buffer): Likewise. + (localize_specific_buffer): Likewise. + (globalize_specific_buffer): Likewise. + (keepglobal_specific_buffer): Likewise. + (weaken_specific_buffer): Likewise. + (add_specific_symbols): Add an argument to return pointer to + allocated buffer. + (copy_main): Update add_specific_symbols to update pointers to + allocated buffer. Free pointers to allocated buffer before + return. + 2018-09-17 Alan Modra <amodra@gmail.com> * objcopy.c (handle_remove_section_option): Don't require a dot diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 2e40b42..9af3c1e 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -253,6 +253,14 @@ static htab_t redefine_specific_reverse_htab = NULL; static struct addsym_node *add_sym_list = NULL, **add_sym_tail = &add_sym_list; static int add_symbols = 0; +static char *strip_specific_buffer = NULL; +static char *strip_unneeded_buffer = NULL; +static char *keep_specific_buffer = NULL; +static char *localize_specific_buffer = NULL; +static char *globalize_specific_buffer = NULL; +static char *keepglobal_specific_buffer = NULL; +static char *weaken_specific_buffer = NULL; + /* If this is TRUE, we weaken global symbols (set BSF_WEAK). */ static bfd_boolean weaken = FALSE; @@ -1034,7 +1042,7 @@ add_specific_symbol_node (const void *node, htab_t htab) #define IS_LINE_TERMINATOR(c) ((c) == '\n' || (c) == '\r' || (c) == '\0') static void -add_specific_symbols (const char *filename, htab_t htab) +add_specific_symbols (const char *filename, htab_t htab, char **buffer_p) { off_t size; FILE * f; @@ -1145,6 +1153,7 @@ add_specific_symbols (const char *filename, htab_t htab) /* Do not free the buffer. Parts of it will have been referenced in the calls to add_specific_symbol. */ + *buffer_p = buffer; } /* See whether a symbol should be stripped or kept @@ -5262,15 +5271,18 @@ copy_main (int argc, char *argv[]) break; case OPTION_STRIP_SYMBOLS: - add_specific_symbols (optarg, strip_specific_htab); + add_specific_symbols (optarg, strip_specific_htab, + &strip_specific_buffer); break; case OPTION_STRIP_UNNEEDED_SYMBOLS: - add_specific_symbols (optarg, strip_unneeded_htab); + add_specific_symbols (optarg, strip_unneeded_htab, + &strip_unneeded_buffer); break; case OPTION_KEEP_SYMBOLS: - add_specific_symbols (optarg, keep_specific_htab); + add_specific_symbols (optarg, keep_specific_htab, + &keep_specific_buffer); break; case OPTION_LOCALIZE_HIDDEN: @@ -5278,7 +5290,8 @@ copy_main (int argc, char *argv[]) break; case OPTION_LOCALIZE_SYMBOLS: - add_specific_symbols (optarg, localize_specific_htab); + add_specific_symbols (optarg, localize_specific_htab, + &localize_specific_buffer); break; case OPTION_LONG_SECTION_NAMES: @@ -5293,15 +5306,18 @@ copy_main (int argc, char *argv[]) break; case OPTION_GLOBALIZE_SYMBOLS: - add_specific_symbols (optarg, globalize_specific_htab); + add_specific_symbols (optarg, globalize_specific_htab, + &globalize_specific_buffer); break; case OPTION_KEEPGLOBAL_SYMBOLS: - add_specific_symbols (optarg, keepglobal_specific_htab); + add_specific_symbols (optarg, keepglobal_specific_htab, + &keepglobal_specific_buffer); break; case OPTION_WEAKEN_SYMBOLS: - add_specific_symbols (optarg, weaken_specific_htab); + add_specific_symbols (optarg, weaken_specific_htab, + &weaken_specific_buffer); break; case OPTION_ALT_MACH_CODE: @@ -5588,6 +5604,27 @@ copy_main (int argc, char *argv[]) } } + if (strip_specific_buffer) + free (strip_specific_buffer); + + if (strip_unneeded_buffer) + free (strip_unneeded_buffer); + + if (keep_specific_buffer) + free (keep_specific_buffer); + + if (localize_specific_buffer) + free (globalize_specific_buffer); + + if (globalize_specific_buffer) + free (globalize_specific_buffer); + + if (keepglobal_specific_buffer) + free (keepglobal_specific_buffer); + + if (weaken_specific_buffer) + free (weaken_specific_buffer); + return 0; } |