mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-15 13:48:26 +08:00
get_stab_string_offset currently creates the stabstr section if not already present, in the process keeping a reference to the malloc'd section name string. Really, the name belongs in bfd_alloc'd memory or some obstack so that it doesn't show as a memory leak on exit. s_stab_generic at least does allocate the name for the stab section on an obstack, but doesn't tidy that as well as it could. Return paths after issuing a warning don't release the memory, nor the memory for the "string" copy. This patch fixes these problems. s_stab_generic is rearranged so that creation of the sections occurs earlier, before any potential uses of the note obstack during expression parsing. That makes it possible to always free the section name strings unless used to create new sections. I've also avoided get_absolute_expression_and_terminator as I see that function might skip over end-of-line, and lack of a --input_line_pointer might have caused the following source line to be ignored. (Other uses of this function in gas are OK.) * config/obj-coff.c (obj_coff_init_stab_section): Add stabstr param. Pass to get_stab_string_offset rather than name of section. * config/obj-som.c (obj_som_init_stab_section): Likewise. * config/obj-elf.c (obj_elf_init_stab_section): Likewise. (elf_init_stab_section): Adjust. * config/obj-coff.h (INIT_STAB_SECTION): Update. (obj_coff_init_stab_section): Update prototype. * config/obj-som.h: Similarly. * config/obj-elf.h: Similarly. * config/obj-multi.h (INIT_STAB_SECTION): Update. * obj.h (struct format_ops <init_stab_section>): Update. * read.h (get_stab_string_offset): Update prototype. * stabs.c (cached_sec): Delete. (stabs_begin): Adjust to suit. (get_stab_string_offset): Add stabstr param, delete stabstr_name and free_stabstr_secname params. Don't make stabstr section here. (eat_comma): New function. (s_stab_generic): Replace stab_secname_obstack_end param with bool freenames. Move creation of stab and stabstr sections earlier, so the names can be freed earlier before possible use of notes obstack during expression parsing. Tidy error paths ensuring "string" is freed. Use get_absolute_expression in place of get_absolute_expression_and_terminator. (s_stab): Adjust. (s_xstab): Use notes_concat to make stabstr section name.
182 lines
4.6 KiB
C
182 lines
4.6 KiB
C
/* Multiple object format emulation.
|
|
Copyright (C) 1995-2023 Free Software Foundation, Inc.
|
|
|
|
This file is part of GAS, the GNU Assembler.
|
|
|
|
GAS is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
any later version.
|
|
|
|
GAS is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GAS; see the file COPYING. If not, write to the Free
|
|
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
|
|
02110-1301, USA. */
|
|
|
|
#ifndef _OBJ_MULTI_H
|
|
#define _OBJ_MULTI_H
|
|
|
|
#ifdef OBJ_HEADER
|
|
#include OBJ_HEADER
|
|
#else
|
|
|
|
#include "emul.h"
|
|
#include "targ-cpu.h"
|
|
|
|
#define OUTPUT_FLAVOR \
|
|
(this_format->flavor)
|
|
|
|
#define obj_begin() \
|
|
(this_format->begin \
|
|
? (*this_format->begin) () \
|
|
: (void) 0)
|
|
|
|
#define obj_end() \
|
|
(this_format->end \
|
|
? (*this_format->end) () \
|
|
: (void) 0)
|
|
|
|
#define obj_app_file(NAME) \
|
|
(this_format->app_file \
|
|
? (*this_format->app_file) (NAME) \
|
|
: (void) 0)
|
|
|
|
#define obj_frob_symbol(S,P) \
|
|
(*this_format->frob_symbol) (S, &(P))
|
|
|
|
#define obj_frob_file() \
|
|
(this_format->frob_file \
|
|
? (*this_format->frob_file) () \
|
|
: (void) 0)
|
|
|
|
#define obj_frob_file_before_adjust() \
|
|
(this_format->frob_file_before_adjust \
|
|
? (*this_format->frob_file_before_adjust) () \
|
|
: (void) 0)
|
|
|
|
#define obj_frob_file_before_fix() \
|
|
(this_format->frob_file_before_fix \
|
|
? (*this_format->frob_file_before_fix) () \
|
|
: (void) 0)
|
|
|
|
#define obj_frob_file_after_relocs() \
|
|
(this_format->frob_file_after_relocs \
|
|
? (*this_format->frob_file_after_relocs) () \
|
|
: (void) 0)
|
|
|
|
#define obj_ecoff_set_ext \
|
|
(*this_format->ecoff_set_ext)
|
|
|
|
#define obj_pop_insert \
|
|
(*this_format->pop_insert)
|
|
|
|
#define obj_read_begin_hook() \
|
|
(this_format->read_begin_hook \
|
|
? (*this_format->read_begin_hook) () \
|
|
: (void) 0)
|
|
|
|
#define obj_symbol_new_hook(S) \
|
|
(this_format->symbol_new_hook \
|
|
? (*this_format->symbol_new_hook) (S) \
|
|
: (void) 0)
|
|
|
|
#define obj_symbol_clone_hook(N, O) \
|
|
(this_format->symbol_clone_hook \
|
|
? (*this_format->symbol_clone_hook) (N, O) \
|
|
: (void) 0)
|
|
|
|
#define obj_sec_sym_ok_for_reloc(A) \
|
|
(this_format->sec_sym_ok_for_reloc \
|
|
? (*this_format->sec_sym_ok_for_reloc) (A) \
|
|
: 0)
|
|
|
|
#define obj_adjust_symtab() \
|
|
(this_format->adjust_symtab \
|
|
? (*this_format->adjust_symtab) () \
|
|
: (void) 0)
|
|
|
|
#define S_GET_SIZE \
|
|
(*this_format->s_get_size)
|
|
|
|
#define S_SET_SIZE(S, N) \
|
|
(this_format->s_set_size \
|
|
? (*this_format->s_set_size) (S, N) \
|
|
: (void) 0)
|
|
|
|
#define S_GET_ALIGN \
|
|
(*this_format->s_get_align)
|
|
|
|
#define S_SET_ALIGN(S, N) \
|
|
(this_format->s_set_align \
|
|
? (*this_format->s_set_align) (S, N) \
|
|
: (void) 0)
|
|
|
|
#define S_GET_OTHER \
|
|
(*this_format->s_get_other)
|
|
|
|
#define S_SET_OTHER(S, O) \
|
|
(this_format->s_set_other \
|
|
? (*this_format->s_set_other) (S, O) \
|
|
: (void) 0)
|
|
|
|
#define S_GET_DESC \
|
|
(*this_format->s_get_desc)
|
|
|
|
#define S_SET_DESC(S, D) \
|
|
(this_format->s_set_desc \
|
|
? (*this_format->s_set_desc) (S, D) \
|
|
: (void) 0)
|
|
|
|
#define S_GET_TYPE \
|
|
(*this_format->s_get_desc)
|
|
|
|
#define S_SET_TYPE(S, T) \
|
|
(this_format->s_set_type \
|
|
? (*this_format->s_set_type) (S, T) \
|
|
: (void) 0)
|
|
|
|
#define OBJ_COPY_SYMBOL_ATTRIBUTES(d,s) \
|
|
(this_format->copy_symbol_attributes \
|
|
? (*this_format->copy_symbol_attributes) (d, s) \
|
|
: (void) 0)
|
|
|
|
#define OBJ_PROCESS_STAB(W,S,T,O,D) \
|
|
(this_format->process_stab \
|
|
? (*this_format->process_stab) (W,S,T,O,D) \
|
|
: (void) 0)
|
|
|
|
#define SEPARATE_STAB_SECTIONS \
|
|
((*this_format->separate_stab_sections) ())
|
|
|
|
#define INIT_STAB_SECTION(STAB, STR) \
|
|
(this_format->init_stab_section \
|
|
? (*this_format->init_stab_section) (STAB, STR) \
|
|
: (void) 0)
|
|
|
|
#define EMIT_SECTION_SYMBOLS (this_format->emit_section_symbols)
|
|
|
|
#ifndef INITIALIZING_EMULS
|
|
/* We want to use the default FAKE_LABEL_NAME in as.c. */
|
|
#define FAKE_LABEL_NAME (this_emulation->fake_label_name)
|
|
#endif
|
|
|
|
#ifdef OBJ_MAYBE_ELF
|
|
/* We need OBJ_SYMFIELD_TYPE so that symbol_get_obj is defined in symbol.c
|
|
We also need various STAB defines for stab.c */
|
|
#include "obj-elf.h"
|
|
#endif
|
|
|
|
#ifdef OBJ_MAYBE_AOUT
|
|
/* We want aout_process_stab in stabs.c for the aout table. Defining this
|
|
macro will have no other effect. */
|
|
#define AOUT_STABS
|
|
#endif
|
|
|
|
#endif /* !OBJ_HEADER */
|
|
#endif /* _OBJ_MULTI_H */
|