gas: rename md_end to md_finish

Currently md_end is typically used for some final actions rather than
freeing memory like other *_end functions.  Rename it to md_finish,
and rename target implementation.  The renaming of target functions
makes it possible to find them all with "grep md_finish",
eg. md_mips_end is renamed to mips_md_finish, not md_mips_finish.
This patch leaves a number of md_end functions unchanged, those that
either do nothing or deallocate memory, and calls them late.

The idea here is that target maintainers implement md_end functions to
tidy memory, if anyone cares.  Freeing persistent memory in gas is
not at all important, except that it can hide more important memory
leaks, those that happen once per some frequent gas operation, amongst
these unimportant memory leaks.

	* as.c (main): Rename md_end to md_finish.
	* config/tc-alpha.c, * config/tc-alpha.h,
	* config/tc-arc.c, * config/tc-arc.h,
	* config/tc-arm.c, * config/tc-arm.h,
	* config/tc-csky.c, * config/tc-csky.h,
	* config/tc-ia64.c, * config/tc-ia64.h,
	* config/tc-mcore.c, * config/tc-mcore.h,
	* config/tc-mips.c, * config/tc-mips.h,
	* config/tc-mmix.c, * config/tc-mmix.h,
	* config/tc-msp430.c, * config/tc-msp430.h,
	* config/tc-nds32.c, * config/tc-nds32.h,
	* config/tc-ppc.c, * config/tc-ppc.h,
	* config/tc-pru.c, * config/tc-pru.h,
	* config/tc-riscv.c, * config/tc-riscv.h,
	* config/tc-s390.c, * config/tc-s390.h,
	* config/tc-sparc.c, * config/tc-sparc.h,
	* config/tc-tic4x.c, * config/tc-tic4x.h,
	* config/tc-tic6x.c, * config/tc-tic6x.h,
	* config/tc-v850.c, * config/tc-v850.h,
	* config/tc-xtensa.c, * config/tc-xtensa.h,
	* config/tc-z80.c, * config/tc-z80.h: Similarly.
	* output-file.c (output_file_close): Call md_end.
This commit is contained in:
Alan Modra 2022-07-05 13:26:38 +09:30
parent af3d7ab74f
commit ed2917de68
42 changed files with 84 additions and 80 deletions

View file

@ -1398,8 +1398,8 @@ main (int argc, char ** argv)
cond_finish_check (-1);
#ifdef md_end
md_end ();
#ifdef md_finish
md_finish ();
#endif
#if defined OBJ_ELF || defined OBJ_MAYBE_ELF

View file

@ -4030,7 +4030,7 @@ s_alpha_coff_wrapper (int which)
unless the compiler has done it for us. */
void
alpha_elf_md_end (void)
alpha_elf_md_finish (void)
{
struct alpha_elf_frame_data *p;

View file

@ -149,8 +149,8 @@ extern void alpha_before_fix (void);
#endif
#ifdef OBJ_ELF
#define md_end alpha_elf_md_end
extern void alpha_elf_md_end (void);
#define md_finish alpha_elf_md_finish
extern void alpha_elf_md_finish (void);
#endif
/* New fields for supporting explicit relocations (such as !literal to mark

View file

@ -5055,7 +5055,7 @@ arc_set_public_attributes (void)
/* Add the default contents for the .ARC.attributes section. */
void
arc_md_end (void)
arc_md_finish (void)
{
arc_set_public_attributes ();

View file

@ -190,7 +190,7 @@ extern const char *arc_target_format;
#define obj_adjust_symtab() arc_adjust_symtab ()
/* Object attribute hooks. */
#define md_end arc_md_end
#define md_finish arc_md_finish
#define CONVERT_SYMBOLIC_ATTRIBUTE(name) arc_convert_symbolic_attribute (name)
#ifndef TC_COPY_SYMBOL_ATTRIBUTES
#define TC_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \
@ -199,7 +199,7 @@ extern const char *arc_target_format;
extern void arc_copy_symbol_attributes (symbolS *, symbolS *);
extern int arc_convert_symbolic_attribute (const char *);
extern void arc_md_end (void);
extern void arc_md_finish (void);
extern void arc_adjust_symtab (void);
extern int arc_pcrel_adjust (fragS *);
extern bool arc_parse_name (const char *, struct expressionS *);

View file

@ -33317,7 +33317,7 @@ arm_md_post_relax (void)
/* Add the default contents for the .ARM.attributes section. */
void
arm_md_end (void)
arm_md_finish (void)
{
if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
return;

View file

@ -98,8 +98,8 @@ extern bool tc_start_label_without_colon (void);
#define tc_frob_fake_label(S) arm_frob_label (S)
#ifdef OBJ_ELF
#define md_end arm_md_end
extern void arm_md_end (void);
#define md_finish arm_md_finish
extern void arm_md_finish (void);
bool arm_is_eabi (void);
#define md_post_relax_hook arm_md_post_relax ()

View file

@ -5216,7 +5216,7 @@ md_section_align (segT segment ATTRIBUTE_UNUSED,
/* MD interface: Symbol and relocation handling. */
void md_csky_end (void)
void csky_md_finish (void)
{
dump_literals (0);
}

View file

@ -38,7 +38,7 @@
#define TC_GENERIC_RELAX_TABLE csky_relax_table
#define md_end md_csky_end
#define md_finish csky_md_finish
#define md_relax_frag csky_relax_frag
#define DOUBLESLASH_LINE_COMMENTS
#define LOCAL_LABELS_FB 1
@ -90,7 +90,7 @@ struct tls_addend
#include "write.h"
extern const relax_typeS csky_relax_table [];
extern void md_csky_end (void);
extern void csky_md_finish (void);
extern void csky_cons_fix_new (fragS *,
unsigned int off,
unsigned int len,

View file

@ -7566,7 +7566,7 @@ ia64_target_format (void)
}
void
ia64_end_of_source (void)
ia64_md_finish (void)
{
/* terminate insn group upon reaching end of file: */
insn_group_break (1, 0, 0);

View file

@ -92,7 +92,7 @@ struct ia64_fix
enum ia64_opnd opnd;
};
extern void ia64_end_of_source (void);
extern void ia64_md_finish (void);
extern void ia64_start_line (void);
extern int ia64_unrecognized_line (int);
extern void ia64_frob_label (struct symbol *);
@ -122,7 +122,7 @@ extern void ia64_check_label (symbolS *);
extern int ia64_estimate_size_before_relax (fragS *, asection *);
extern void ia64_convert_frag (fragS *);
#define md_end() ia64_end_of_source ()
#define md_finish() ia64_md_finish ()
#define md_start_line_hook() ia64_start_line ()
#define tc_unrecognized_line(ch) ia64_unrecognized_line (ch)
#define tc_frob_label(s) ia64_frob_label (s)

View file

@ -1615,7 +1615,7 @@ md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
}
void
md_mcore_end (void)
mcore_md_finish (void)
{
dump_literals (0);
subseg_set (text_section, 0);

View file

@ -39,7 +39,7 @@
extern const struct relax_type md_relax_table[];
#define TC_GENERIC_RELAX_TABLE md_relax_table
#define md_end md_mcore_end
#define md_finish mcore_md_finish
/* Want the section information too... */
#define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from_section (FIX, SEC)
@ -86,7 +86,7 @@ struct mcore_tc_sy
#include "write.h" /* For definition of fixS */
extern void md_mcore_end (void);
extern void mcore_md_finish (void);
extern arelent *tc_gen_reloc (asection *, fixS *);
extern int mcore_force_relocation (fixS *);
extern bool mcore_fix_adjustable (fixS *);

View file

@ -20573,7 +20573,7 @@ mips_convert_symbolic_attribute (const char *name)
}
void
md_mips_end (void)
mips_md_finish (void)
{
int fpabi = Val_GNU_MIPS_ABI_FP_ANY;

View file

@ -163,8 +163,8 @@ extern void mips_elf_final_processing (void);
#endif
extern void md_mips_end (void);
#define md_end() md_mips_end()
extern void mips_md_finish (void);
#define md_finish() mips_md_finish()
extern void mips_pop_insert (void);
#define md_pop_insert() mips_pop_insert()

View file

@ -3368,7 +3368,7 @@ mmix_md_relax_frag (segT seg, fragS *fragP, long stretch)
{
switch (fragP->fr_subtype)
{
/* Growth for this type has been handled by mmix_md_end and
/* Growth for this type has been handled by mmix_md_finish and
correctly estimated, so there's nothing more to do here. */
case STATE_GREG_DEF:
return 0;
@ -3490,7 +3490,7 @@ mmix_md_relax_frag (segT seg, fragS *fragP, long stretch)
/* Various things we punt until all input is seen. */
void
mmix_md_end (void)
mmix_md_finish (void)
{
fragS *fragP;
symbolS *mainsym;

View file

@ -48,8 +48,8 @@ extern void mmix_handle_mmixal (void);
extern void mmix_md_begin (void);
#define md_begin mmix_md_begin
extern void mmix_md_end (void);
#define md_end mmix_md_end
extern void mmix_md_finish (void);
#define md_finish mmix_md_finish
extern int mmix_current_location \
(void (*fn) (expressionS *), expressionS *);

View file

@ -1613,7 +1613,7 @@ msp430_refsym (int arg ATTRIBUTE_UNUSED)
This is only used for validating the attributes in the assembly file against
the options gas has been invoked with. If the attributes and options are
compatible then we add the attributes to the assembly file in
msp430_md_end. */
msp430_md_finish. */
static void
msp430_object_attribute (int attr_type)
{
@ -5107,7 +5107,7 @@ msp430_insert_uleb128_fixes (bfd *abfd ATTRIBUTE_UNUSED,
/* Called after all assembly has been done. */
void
msp430_md_end (void)
msp430_md_finish (void)
{
if (check_for_nop)
{

View file

@ -135,8 +135,8 @@ extern bool msp430_fix_adjustable (struct fix *);
is A5A5h... */
#define NUMBERS_WITH_SUFFIX 1
#define md_end msp430_md_end
extern void msp430_md_end (void);
#define md_finish msp430_md_finish
extern void msp430_md_finish (void);
/* Do not allow call frame debug info optimization as otherwise we could
generate the DWARF directives without the relocs necessary to patch

View file

@ -7519,7 +7519,7 @@ nds32_elf_insert_final_frag (void)
}
void
md_end (void)
md_finish (void)
{
nds32_elf_insert_final_frag ();
nds32_elf_analysis_relax_hint ();

View file

@ -133,7 +133,7 @@ extern void nds32_macro_info (void *);
extern void nds32_start_line_hook (void);
extern void nds32_elf_section_change_hook (void);
extern void md_begin (void);
extern void md_end (void);
extern void md_finish (void);
extern int nds32_start_label (int, int);
extern void nds32_cleanup (void);
extern void nds32_flush_pending_output (void);
@ -150,7 +150,7 @@ extern void nds32_do_align (int);
(NEXT_CHAR == ':' && nds32_start_label (0, 0))
#define tc_check_label(label) nds32_check_label (label)
#define tc_frob_label(label) nds32_frob_label (label)
#define md_end md_end
#define md_finish md_finish
#define md_start_line_hook() nds32_start_line_hook ()
#define md_cons_align(n) nds32_cons_align (n)
/* COLE: TODO: Review md_do_align. */

View file

@ -2534,7 +2534,7 @@ ppc_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
/* Set ABI version in output file. */
void
ppc_elf_end (void)
ppc_elf_md_finish (void)
{
if (ppc_obj64 && ppc_abiversion != 0)
{
@ -5666,7 +5666,7 @@ ppc_vbyte (int dummy ATTRIBUTE_UNUSED)
}
void
ppc_xcoff_end (void)
ppc_xcoff_md_finish (void)
{
int i;

View file

@ -187,8 +187,8 @@ do { \
symbol_get_tc (dest)->within = symbol_get_tc (src)->within; \
} while (0)
extern void ppc_xcoff_end (void);
#define md_end ppc_xcoff_end
extern void ppc_xcoff_md_finish (void);
#define md_finish ppc_xcoff_md_finish
#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
ppc_xcoff_parse_cons (EXP, NBYTES)
@ -251,8 +251,8 @@ extern void ppc_frob_file_before_adjust (void);
#define tc_adjust_symtab() ppc_elf_adjust_symtab ()
extern void ppc_elf_adjust_symtab (void);
extern void ppc_elf_end (void);
#define md_end ppc_elf_end
extern void ppc_elf_md_finish (void);
#define md_finish ppc_elf_md_finish
#endif /* OBJ_ELF */

View file

@ -1787,7 +1787,7 @@ md_pcrel_from (fixS *fixP ATTRIBUTE_UNUSED)
/* Called just before the assembler exits. */
void
md_end (void)
pru_md_end (void)
{
htab_delete (pru_opcode_hash);
htab_delete (pru_reg_hash);

View file

@ -47,7 +47,8 @@ extern const char *pru_target_format (void);
/* Function prototypes exported to rest of GAS. */
extern void md_assemble (char *op_str);
extern void md_end (void);
extern void pru_md_end (void);
#define md_end pru_md_end
extern void md_begin (void);
#define tc_fix_adjustable(fixp) pru_fix_adjustable (fixp)

View file

@ -4462,7 +4462,7 @@ riscv_set_public_attributes (void)
/* Called after all assembly has been done. */
void
riscv_md_end (void)
riscv_md_finish (void)
{
riscv_set_public_attributes ();
}

View file

@ -123,10 +123,10 @@ extern void riscv_elf_final_processing (void);
/* Adjust debug_line after relaxation. */
#define DWARF2_USE_FIXED_ADVANCE_PC 1
#define md_end riscv_md_end
#define md_finish riscv_md_finish
#define CONVERT_SYMBOLIC_ATTRIBUTE riscv_convert_symbolic_attribute
extern void riscv_md_end (void);
extern void riscv_md_finish (void);
extern int riscv_convert_symbolic_attribute (const char *);
/* Set mapping symbol states. */

View file

@ -584,7 +584,7 @@ md_begin (void)
/* Called after all assembly has been done. */
void
s390_md_end (void)
s390_md_finish (void)
{
if (s390_arch_size == 64)
bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64);

View file

@ -78,8 +78,8 @@ extern int target_big_endian;
#define md_operand(x)
extern void s390_md_end (void);
#define md_end() s390_md_end ()
extern void s390_md_finish (void);
#define md_finish() s390_md_finish ()
#define TARGET_USE_CFIPOP 1

View file

@ -1081,7 +1081,7 @@ md_begin (void)
/* Called after all assembly has been done. */
void
sparc_md_end (void)
sparc_md_finish (void)
{
unsigned long mach;
#ifndef TE_SOLARIS

View file

@ -125,8 +125,8 @@ extern void sparc_elf_final_processing (void);
#define md_operand(x)
extern void sparc_md_end (void);
#define md_end() sparc_md_end ()
extern void sparc_md_finish (void);
#define md_finish() sparc_md_finish ()
#define TC_PARSE_CONS_RETURN_TYPE const char *
#define TC_PARSE_CONS_RETURN_NONE NULL

View file

@ -1371,7 +1371,7 @@ md_begin (void)
}
void
tic4x_end (void)
tic4x_md_finish (void)
{
bfd_set_arch_mach (stdoutput, bfd_arch_tic4x,
IS_CPU_TIC4X (tic4x_cpu) ? bfd_mach_tic4x : bfd_mach_tic3x);

View file

@ -88,6 +88,6 @@ extern void tic4x_start_line (void);
extern void tic4x_cleanup (void);
#define md_cleanup() tic4x_cleanup()
extern void tic4x_end (void);
#define md_end() tic4x_end()
extern void tic4x_md_finish (void);
#define md_finish() tic4x_md_finish()

View file

@ -1037,7 +1037,7 @@ bool
tic6x_do_align (int n, char *fill, int len ATTRIBUTE_UNUSED, int max)
{
/* Given code alignments of 4, 8, 16 or 32 bytes, we try to handle
them in the md_end pass by inserting NOPs in parallel with
them in the md_finish pass by inserting NOPs in parallel with
previous instructions. We only do this in sections containing
nothing but instructions. Code alignments of 1 or 2 bytes have
no effect in such sections (but we record them with
@ -4078,7 +4078,7 @@ md_atof (int type, char *litP, int *sizeP)
return ieee_md_atof (type, litP, sizeP, target_big_endian);
}
/* Adjust the frags in SECTION (see tic6x_end). */
/* Adjust the frags in SECTION (see tic6x_md_finish). */
static void
tic6x_adjust_section (bfd *abfd ATTRIBUTE_UNUSED, segT section,
@ -4403,7 +4403,7 @@ tic6x_set_attributes (void)
relaxing. */
void
tic6x_end (void)
tic6x_md_finish (void)
{
/* Set object attributes at this point if not explicitly set. */
tic6x_set_attributes ();
@ -4419,7 +4419,7 @@ tic6x_end (void)
}
/* No machine-dependent frags at this stage; all converted in
tic6x_end. */
tic6x_md_finish. */
void
md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec ATTRIBUTE_UNUSED,
@ -4429,7 +4429,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec ATTRIBUTE_UNUSED,
}
/* No machine-dependent frags at this stage; all converted in
tic6x_end. */
tic6x_md_finish. */
int
md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,

View file

@ -170,8 +170,8 @@ extern bool tic6x_do_align (int n, char *fill, int len, int max);
tic6x_convert_symbolic_attribute (name)
extern int tic6x_convert_symbolic_attribute (const char *);
#define md_end() tic6x_end ();
extern void tic6x_end (void);
#define md_finish() tic6x_md_finish ();
extern void tic6x_md_finish (void);
#define md_parse_name(name, exprP, mode, nextcharP) \
tic6x_parse_name (name, exprP, mode, nextcharP)

View file

@ -3728,7 +3728,7 @@ v850_force_relocation (struct fix *fixP)
/* Create a v850 note section. */
void
v850_md_end (void)
v850_md_finish (void)
{
segT note_sec;
segT orig_seg = now_seg;

View file

@ -85,5 +85,5 @@ extern long v850_pcrel_from_section (struct fix *, asection *);
#define TC_FIX_TYPE void *
#define TC_INIT_FIX_DATA(fixP) (fixP)->tc_fix_data = NULL
#define md_end v850_md_end
extern void v850_md_end (void);
#define md_finish v850_md_finish
extern void v850_md_finish (void);

View file

@ -94,7 +94,7 @@ static enum debug_info_type xt_saved_debug_type = DEBUG_NONE;
/* Some functions are only valid in the front end. This variable
allows us to assert that we haven't crossed over into the
back end. */
static bool past_xtensa_end = false;
static bool past_xtensa_md_finish = false;
/* Flags for properties of the last instruction in a segment. */
#define FLAG_IS_A0_WRITER 0x1
@ -1189,9 +1189,9 @@ const pseudo_typeS md_pseudo_table[] =
static bool
use_transform (void)
{
/* After md_end, you should be checking frag by frag, rather
/* After md_finish, you should be checking frag by frag, rather
than state directives. */
gas_assert (!past_xtensa_end);
gas_assert (!past_xtensa_md_finish);
return directive_state[directive_transform];
}
@ -1199,10 +1199,10 @@ use_transform (void)
static bool
do_align_targets (void)
{
/* Do not use this function after md_end; just look at align_targets
/* Do not use this function after md_finish; just look at align_targets
instead. There is no target-align directive, so alignment is either
enabled for all frags or not done at all. */
gas_assert (!past_xtensa_end);
gas_assert (!past_xtensa_md_finish);
return align_targets && use_transform ();
}
@ -4980,7 +4980,7 @@ xtensa_set_frag_assembly_state (fragS *fragP)
fragP->tc_frag_data.is_no_density = true;
/* This function is called from subsegs_finish, which is called
after xtensa_end, so we can't use "use_transform" or
after xtensa_md_finish, so we can't use "use_transform" or
"use_schedule" here. */
if (!directive_state[directive_transform])
fragP->tc_frag_data.is_no_transform = true;
@ -6600,7 +6600,7 @@ find_vinsn_conflicts (vliw_insn *vinsn)
int branches = 0;
xtensa_isa isa = xtensa_default_isa;
gas_assert (!past_xtensa_end);
gas_assert (!past_xtensa_md_finish);
for (i = 0 ; i < vinsn->num_slots; i++)
{
@ -7369,7 +7369,7 @@ xg_assemble_vliw_tokens (vliw_insn *vinsn)
}
/* xtensa_end and helper functions. */
/* xtensa_md_finish and helper functions. */
static void xtensa_cleanup_align_frags (void);
static void xtensa_fix_target_frags (void);
@ -7384,12 +7384,12 @@ static void xtensa_sanity_check (void);
static void xtensa_add_config_info (void);
void
xtensa_end (void)
xtensa_md_finish (void)
{
directive_balance ();
xtensa_flush_pending_output ();
past_xtensa_end = true;
past_xtensa_md_finish = true;
xtensa_move_literals ();
@ -7927,7 +7927,7 @@ xtensa_maybe_create_literal_pool_frag (bool create, bool only_if_needed)
{
if (only_if_needed)
{
if (past_xtensa_end || !use_transform() ||
if (past_xtensa_md_finish || !use_transform() ||
frag_now->tc_frag_data.is_no_transform)
{
return;

View file

@ -329,7 +329,7 @@ extern void xtensa_frag_init (fragS *);
extern int xtensa_force_relocation (struct fix *);
extern int xtensa_validate_fix_sub (struct fix *);
extern void xtensa_frob_label (struct symbol *);
extern void xtensa_end (void);
extern void xtensa_md_finish (void);
extern void xtensa_post_relax_hook (void);
extern void xtensa_file_arch_init (bfd *);
extern void xtensa_flush_pending_output (void);
@ -372,7 +372,7 @@ extern void xtensa_init (int, char **);
#define tc_symbol_new_hook(sym) xtensa_symbol_new_hook (sym)
#define md_do_align(a,b,c,d,e) xtensa_flush_pending_output ()
#define md_elf_section_change_hook xtensa_elf_section_change_hook
#define md_end xtensa_end
#define md_finish xtensa_md_finish
#define md_flush_pending_output() xtensa_flush_pending_output ()
#define md_operand(x)
#define TEXT_SECTION_NAME xtensa_section_rename (".text")

View file

@ -538,7 +538,7 @@ md_begin (void)
}
void
z80_md_end (void)
z80_md_finish (void)
{
int mach_type;

View file

@ -55,11 +55,11 @@
(as_fatal (_("estimate_size_before_relax called")), 1)
/* Define some functions to be called by generic code. */
#define md_end z80_md_end
#define md_finish z80_md_finish
#define md_start_line_hook() { if (z80_start_line_hook ()) continue; }
#define TC_CONS_FIX_NEW(f,w,s,e,r) z80_cons_fix_new ((f), (w), (s), (e))
extern void z80_md_end (void);
extern void z80_md_finish (void);
extern int z80_start_line_hook (void);
extern void z80_cons_fix_new (fragS *, int, int, expressionS *);

View file

@ -105,6 +105,9 @@ output_file_close (void)
if (!keep_it && filename)
unlink_if_ordinary (filename);
#ifdef md_end
md_end ();
#endif
macro_end ();
read_end ();
symbol_end ();