From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id D9CF93858D3C for ; Wed, 1 Feb 2023 22:45:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9CF93858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102b.google.com with SMTP id cq16-20020a17090af99000b0022c9791ac39so3779086pjb.4 for ; Wed, 01 Feb 2023 14:45:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=0pjw77tWC7FZsp8AqZXattA7mAnIvwlBoIKH9IKwCzU=; b=X8JKFuXtamOovkt0OuwLNmveZ+GvHpsM6+9Py4J5RAX/3sL6dSoUYGr2xTVrh05Wdp ko13t2Qwg5Ez++Y3XwM+TVreLfPOi5rJbUFfvAsR6pWFU9HrOQ/hPfnwen58aZ986uty BRzzFlJXayNdCpd0ijfuInMvOoo9ocWRz+gsNdAX6B7Z/ZeNlZMvcN9tRaBEdCMCCduw UnkhET5x7yQgYjrZE/bd99JDXrEMdq/XzII2/Kini4aYQPCKXIb31Rf//KgrT9rVWe4Z kHYjheirjzNJkCR3huH7Z2UNlR4/d53jQaF/90dj/iFrNDHSQXGA9de85I+zamosSDI5 YCcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0pjw77tWC7FZsp8AqZXattA7mAnIvwlBoIKH9IKwCzU=; b=bZAy2OB9d377PD7RE0Zyl84IerrWyS1ot+CLy0dFMPCii9hgAYdWiEDulUQlgxipVm +gDrJhSq9hj49tNy+JWr6H+iyhWQLWOMEoaQWAVkIcLscCA7kFpT80cIoz4VMT+O+5lC B2GieKIc10Jzmvcp6TRGvxdDSfKnh5zO2B+gvbfYLRs3xhTndYRm9RbLrkriIWLLjRzr qqSZzGr4/DERn2s390mnn81/2Qs3Wr5jHAYmgQaUZ/qTsxdgJRqLWv410W9INfHHmJ0q wkmkpYAbU7kflzEv8q28PkpvSEDJ/uwzYmzmYVaKQeLBdGKe+gZGEwnRz5ITWinGiOHu x5qw== X-Gm-Message-State: AO0yUKWsJF0ug08nwmon9Sp2RVUeOhGpI66zGmiYWGwZA/rEyGs2bP7D yseLfZFfeQh+rvQ9HSCvrfx6IMM8hvY= X-Google-Smtp-Source: AK7set98Hh8WhqTl1PJRmhq+sELmiP6Li0mU/rJymOITDYm4q6dQjQNSxTfBhjM+DuhXtDR5S0RJBA== X-Received: by 2002:a05:6a20:8ba4:b0:b9:817e:2ff2 with SMTP id m36-20020a056a208ba400b000b9817e2ff2mr3655453pzh.57.1675291522220; Wed, 01 Feb 2023 14:45:22 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id 144-20020a621496000000b0058d9428e482sm11939111pfu.85.2023.02.01.14.45.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 14:45:21 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 1BB7A114266E; Thu, 2 Feb 2023 09:15:19 +1030 (ACDT) Date: Thu, 2 Feb 2023 09:15:19 +1030 From: Alan Modra To: binutils@sourceware.org Subject: gas obj_end Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3035.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Provide a way for config/obj-* to clean up at end of assembly, and do so for ELF. * obj.h (struct format_ops): Add "end". * config/obj-aout.c (aout_format_ops): Init new field. * config/obj-coff.c (coff_format_ops): Likewise. * config/obj-ecoff.c (ecoff_format_ops): Likewise. * config/obj-elf.c (elf_format_ops): Likewise. (elf_begin): Move later in file. Clear some more variables. (comment_section): Make file scope. (free_section_idx): Rewrite. (elf_adjust_symtab): Expand str_htab_create call and use free_section_idx as delete function. (elf_frob_file_after_relocs): Don't clean up groups.indexes here. (elf_end): New function. * config/obj-elf.h (obj_end): Define. * config/obj-multi.h (obj_end): Define. * output-file.c (output_file_close): Call obj_end. diff --git a/gas/config/obj-aout.c b/gas/config/obj-aout.c index f413e9139bb..14eb9f96aa6 100644 --- a/gas/config/obj-aout.c +++ b/gas/config/obj-aout.c @@ -297,6 +297,7 @@ const struct format_ops aout_format_ops = 1, /* dfl_leading_underscore. */ 0, /* emit_section_symbols. */ 0, /* begin. */ + 0, /* end. */ 0, /* app_file. */ obj_aout_frob_symbol, 0, /* frob_file. */ diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c index 5446beffb2e..465a990ec88 100644 --- a/gas/config/obj-coff.c +++ b/gas/config/obj-coff.c @@ -1910,6 +1910,7 @@ const struct format_ops coff_format_ops = 0, /* dfl_leading_underscore */ 1, /* emit_section_symbols */ 0, /* begin */ + 0, /* end. */ c_dot_file_symbol, coff_frob_symbol, 0, /* frob_file */ diff --git a/gas/config/obj-ecoff.c b/gas/config/obj-ecoff.c index f30e8c74d00..092f6f2c927 100644 --- a/gas/config/obj-ecoff.c +++ b/gas/config/obj-ecoff.c @@ -290,6 +290,7 @@ const struct format_ops ecoff_format_ops = the single-format definition (0) would be in order. */ 1, /* emit_section_symbols. */ 0, /* begin. */ + 0, /* end. */ ecoff_new_file, obj_ecoff_frob_symbol, ecoff_frob_file, diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index d3a54e8659f..a4cf12b144a 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -188,25 +188,8 @@ static const pseudo_typeS ecoff_debug_pseudo_table[] = #undef NO_RELOC #include "aout/aout64.h" -/* This is called when the assembler starts. */ - asection *elf_com_section_ptr; -void -elf_begin (void) -{ - asection *s; - - /* Add symbols for the known sections to the symbol table. */ - s = bfd_get_section_by_name (stdoutput, TEXT_SECTION_NAME); - symbol_table_insert (section_symbol (s)); - s = bfd_get_section_by_name (stdoutput, DATA_SECTION_NAME); - symbol_table_insert (section_symbol (s)); - s = bfd_get_section_by_name (stdoutput, BSS_SECTION_NAME); - symbol_table_insert (section_symbol (s)); - elf_com_section_ptr = bfd_com_section_ptr; -} - void elf_pop_insert (void) { @@ -2462,10 +2445,11 @@ obj_elf_type (int ignore ATTRIBUTE_UNUSED) demand_empty_rest_of_line (); } +static segT comment_section; + static void obj_elf_ident (int ignore ATTRIBUTE_UNUSED) { - static segT comment_section; segT old_section = now_seg; int old_subsection = now_subseg; @@ -2813,12 +2797,11 @@ build_additional_section_info (bfd *abfd ATTRIBUTE_UNUSED, str_hash_insert (list->indexes, group_name, idx_ptr, 0); } -static int -free_section_idx (void **slot, void *arg ATTRIBUTE_UNUSED) +static void +free_section_idx (void *ent) { - string_tuple_t *tuple = *((string_tuple_t **) slot); - free ((char *)tuple->value); - return 1; + string_tuple_t *tuple = ent; + free ((char *) tuple->value); } /* Create symbols for group signature. */ @@ -2831,7 +2814,8 @@ elf_adjust_symtab (void) /* Go find section groups. */ groups.num_group = 0; groups.head = NULL; - groups.indexes = str_htab_create (); + groups.indexes = htab_create_alloc (16, hash_string_tuple, eq_string_tuple, + free_section_idx, notes_calloc, NULL); bfd_map_over_sections (stdoutput, build_additional_section_info, &groups); @@ -3005,10 +2989,6 @@ elf_frob_file_after_relocs (void) frag_wane (frag_now); } - /* Cleanup hash. */ - htab_traverse_noresize (groups.indexes, free_section_idx, NULL); - htab_delete (groups.indexes); - #ifdef NEED_ECOFF_DEBUG if (ECOFF_DEBUGGING) /* Generate the ECOFF debugging information. */ @@ -3121,12 +3101,56 @@ elf_init_stab_section (segT seg) obj_elf_init_stab_section (seg); } +/* This is called when the assembler starts. */ + +void +elf_begin (void) +{ + asection *s; + + /* Add symbols for the known sections to the symbol table. */ + s = bfd_get_section_by_name (stdoutput, TEXT_SECTION_NAME); + symbol_table_insert (section_symbol (s)); + s = bfd_get_section_by_name (stdoutput, DATA_SECTION_NAME); + symbol_table_insert (section_symbol (s)); + s = bfd_get_section_by_name (stdoutput, BSS_SECTION_NAME); + symbol_table_insert (section_symbol (s)); + elf_com_section_ptr = bfd_com_section_ptr; + previous_section = NULL; + previous_subsection = 0; + comment_section = NULL; + memset (&groups, 0, sizeof (groups)); +} + +void +elf_end (void) +{ + while (section_stack) + { + struct section_stack *top = section_stack; + section_stack = top->next; + free (top); + } + while (recorded_attributes) + { + struct recorded_attribute_info *rai = recorded_attributes; + recorded_attributes = rai->next; + free (rai); + } + if (groups.indexes) + { + htab_delete (groups.indexes); + free (groups.head); + } +} + const struct format_ops elf_format_ops = { bfd_target_elf_flavour, 0, /* dfl_leading_underscore */ 1, /* emit_section_symbols */ elf_begin, + elf_end, elf_file_symbol, elf_frob_symbol, elf_frob_file, diff --git a/gas/config/obj-elf.h b/gas/config/obj-elf.h index c97d4fd04dd..727924ce234 100644 --- a/gas/config/obj-elf.h +++ b/gas/config/obj-elf.h @@ -119,6 +119,11 @@ struct elf_section_match #endif extern void elf_begin (void); +#ifndef obj_end +#define obj_end() elf_end () +#endif +extern void elf_end (void); + #ifndef LOCAL_LABEL_PREFIX #define LOCAL_LABEL_PREFIX '.' #endif diff --git a/gas/config/obj-multi.h b/gas/config/obj-multi.h index b88f81bc3eb..d4c94799edf 100644 --- a/gas/config/obj-multi.h +++ b/gas/config/obj-multi.h @@ -36,6 +36,11 @@ ? (*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) \ diff --git a/gas/obj.h b/gas/obj.h index 586ed2622c1..e1036928cc2 100644 --- a/gas/obj.h +++ b/gas/obj.h @@ -42,6 +42,7 @@ struct format_ops { unsigned dfl_leading_underscore : 1; unsigned emit_section_symbols : 1; void (*begin) (void); + void (*end) (void); void (*app_file) (const char *); void (*frob_symbol) (symbolS *, int *); void (*frob_file) (void); diff --git a/gas/output-file.c b/gas/output-file.c index 88f40116513..664bc88e9c1 100644 --- a/gas/output-file.c +++ b/gas/output-file.c @@ -109,6 +109,9 @@ output_file_close (void) #ifdef md_end md_end (); +#endif +#ifdef obj_end + obj_end (); #endif macro_end (); expr_end (); -- Alan Modra Australia Development Lab, IBM