From patchwork Wed Feb 1 22:45:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 51590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp550904wrn; Wed, 1 Feb 2023 14:45:36 -0800 (PST) X-Google-Smtp-Source: AK7set+Bo8loidZfvNk5ltV/ZLggh3U0u2KNu5AU/ObimOXfF82bTzV+yIKgeq0d3MZybHOCZ7vz X-Received: by 2002:a05:6402:31fc:b0:4a2:223d:3bfa with SMTP id dy28-20020a05640231fc00b004a2223d3bfamr4008655edb.3.1675291536224; Wed, 01 Feb 2023 14:45:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675291536; cv=none; d=google.com; s=arc-20160816; b=r3+BilbTrOm32xylMS8qWiIRZTWsSWxs3JFZR2fLOIx1BEM2mK5ZSsBGfBk30ZXn0E HFRI+wNcaAvjbDujV7ArJ88/QKp/qmgOwP6/RnjUl/kJZpBiAK06X37B7H66GE2lsUYQ t8PJveAYAwUeumWZDJ4Y1xRjmgCDc2/RoczL8M10Br+AVUFLQenU9JWnnBGLwiI76naE qQvDci1lcNODPF53GAVUWwQwKXklWQlCSDS7LJbCyILbLjekgVq47PcGvPOpY5y29QNd jau6pVPqtaFWJ7GZbMU2mDJ0KgCEml8AfE0U1qem4Qu4pAUBhsLWJJWKAeXTZ3HMz0uY 2+Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=0pjw77tWC7FZsp8AqZXattA7mAnIvwlBoIKH9IKwCzU=; b=fndm5Gh7KkHMkBpdoA4oDfpUGWU5/XDkW4NnBjeZCMdb4sMKRBHB7sBPbqBu7D25nq QDo77zfojrQBMmHL52hfEv6B/lF+DH1Wm0EFXiYI8IM9Kb6+9ItP10cXZ3gIpJFnvWjK NxKhvXOkni0DfuUz0vwGvcAz+8sVtdrPUUyC8BwVHokX19iUM5g7pQgZWV5HPhTHpvXY jV90lmBnAiFCrXApPkNbEvhv0dwqEpB3cKPSWuUX2BWqCmLC9sr76H+NBIJWS3x1wJwh oe60E0Mq3UKVaP0ifdZ+nl3NI/E5tnnTejLoq4q6u8AE+kSKEa5Lrb/Z/cbM5lbGeYuT Fmcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=w8Hjmb5U; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ay14-20020a056402202e00b004a246b0e915si11188740edb.83.2023.02.01.14.45.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 14:45:36 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=w8Hjmb5U; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6144A38582BD for ; Wed, 1 Feb 2023 22:45:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6144A38582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675291534; bh=0pjw77tWC7FZsp8AqZXattA7mAnIvwlBoIKH9IKwCzU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=w8Hjmb5UgiwWG6do9WISCyhgnlDCB05WE0178emjmxmeHvSQjdDsxGt9tn4GlgCDr TQVrOa817hAv0XeiAnCQbblRK5S3pMh/gkLqXA4izfgy15Y6egM7iby+NgGM7pNvNU mu2okggJVli2COL7vrVrthzo2W5Kf5SGYHzM4+eM= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 Received: by mail-pj1-x102b.google.com with SMTP id cq16-20020a17090af99000b0022c9791ac39so3779086pjb.4 for ; Wed, 01 Feb 2023 14:45:23 -0800 (PST) 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-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 To: binutils@sourceware.org Subject: gas obj_end Message-ID: MIME-Version: 1.0 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756670497756226373?= X-GMAIL-MSGID: =?utf-8?q?1756670497756226373?= 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 ();