From patchwork Mon Mar 3 21:50:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 107328 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E2DA3858D28 for ; Mon, 3 Mar 2025 21:53:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E2DA3858D28 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=T2DRircM X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id CB5593858C48 for ; Mon, 3 Mar 2025 21:50:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB5593858C48 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB5593858C48 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1036 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741038628; cv=none; b=BkSk1DrXFKuHlUpivddqroQ7dq0Y0oylh5nE/5WwZFw4DPhOb9Vaea8nJeoRuCUkvJO7ek/KK3ZfPaqNasrmUl3MejEDFCZV7lTRVvtX1EbMDYSVsPGGPKQ1I662vFVJHl1QnglOvJutN2mBdGc1F8pZPrI5VF5vEPMR6qDqa3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741038628; c=relaxed/simple; bh=x0o+Uzl7Jq5HpBnA8oa9Qjn0DLGCs2HgUriP+LTpPQ8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=KvR+tbrhUjBjQnKsWkSaoE0dD08DJ49Rfru+DQa75Pd9EAjoa3RG8fjvkMjpIiblnBcsQIdadhm2z2s20+gIz9UxaGrWGZfuUUyv0HzTpoUc5p0VQDrjhtJZnVA30YoGFHt9Aoswe6wT8oNa4sGWf6pHZeSPmvLXfiy18iCk1cw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB5593858C48 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2fe96dd93b4so8991579a91.0 for ; Mon, 03 Mar 2025 13:50:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741038627; x=1741643427; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=kKn99lgP01ou6fi1WRrTyRNjV/C5YGk/0TSBvN1HbSI=; b=T2DRircMj48yAfmQrxAc84O0FPf5Q/O7jbcwI6HkR7BvIQyT9cpF9p80QoTBYMSFo6 VH1z1f086dcnWnPirDqwiYVnQGOVN9E/kmiC7jySC8wyvyk+JXW3nP3UUDTHM3184Ibs wxTnmATBCeQKyDzx2uqrCijW+gow229DM2Ow6sHo6xG5EqMoft9QEtrP9DtnO77RSPsf MdBS9inRvdIymQQh+STwR2R7c3gb2jjSBZJ2tgp6LgDS8a8nVDPBORowrpRlU38j48wO 5hidB+Md9pfrRWKFQtY9NlyGKVXas20oaNgVQZ3RNXZaoPYerYHjsbFkw6HM5+GrrYrP hVpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741038627; x=1741643427; 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=kKn99lgP01ou6fi1WRrTyRNjV/C5YGk/0TSBvN1HbSI=; b=p9Pg3gFrCWEo9Gp7s9c2TpAYFehqtlA3HjmQVAa6O8LM5CuCkTxecXdmh4yJ2PWh1P yf73nKqrRaRaoDl0pD5mYpvsPKuDvMKsY4/EMkSgMkV6kbBBqAP9UjgZOgH18qbNKmt5 t5yaX/97SgJ5c/NONQPnT5g83eqAYTTRu3rMZ27gu1lICI3zGXEjIuwvum4dCfjZfxO7 dIYH0qJ7OJ//28Amhk1JazxJz2/ENFtMgDAxre4RMl+CuO2Owgv2pZaeUXLCJiiECKLD ZQDuHCuR/z/5C8Bl5LLl9GYwKZP0xOETcRS32aiZi6zHnq+JecR85GAlalOgBcz4OCo1 rtMw== X-Gm-Message-State: AOJu0YyNY+bAFl2bdE9F3lIJnPvm7H7kgEuNE16sZ+4ZMqwGTRfpRFSB pUxD4RLJYPsxGdvu3ERYO/IEX4l1GQbfP6sCBC3y2LsLErk1lBhUisjc5w== X-Gm-Gg: ASbGncswCbkH1LKHcf556BvZsjP69G6q+QjOAi6x8oUUUgrXFoHXHSWt/y/4HOKd9g6 WyRMERkuAmTP2zG332WG+p4g1RSxVYx07M5OYAd4hLB/jykkJA1Okfz66g1Jz8qbxoiAVKX/Jnt 0nNSHLXfz2bml3SrEsZyY3JlpAdR5Mothfk9pFIhOArSqceUCshhtweLjpRroL1tvOSCqQflZG8 cU4oKiEVzatcfSDQtnxHITNvN7cqNjapjkDWDjsOzQkCcMrqV2yfpqLAZCn5qmZOgpWNY/O+9jF YFR5pZhHdyaZC56P5VFR6kn+YDJX2Wude+Sdz7C9rAFiGimJTeS84kAxBA== X-Google-Smtp-Source: AGHT+IF9VWna5sGWcbB8WSwF83BYmmMylu0+qjAQKxl0T7A+t+jNgRSgdryYYzzoMRrG/+/BElxK/g== X-Received: by 2002:a17:90b:570f:b0:2fa:603e:905c with SMTP id 98e67ed59e1d1-2ff33b7b188mr1328219a91.2.1741038626374; Mon, 03 Mar 2025 13:50:26 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:4d08:cebd:d73f:b794]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2fea67a7183sm10568019a91.25.2025.03.03.13.50.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 13:50:25 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id D76721140496; Tue, 4 Mar 2025 08:20:22 +1030 (ACDT) Date: Tue, 4 Mar 2025 08:20:22 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Move BFD_FAKE_SECTION to libbfd.h Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3030.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_STOCKGEN, 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.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org BFD_FAKE_SECTION and its sidekick GLOBAL_SYM_INIT don't need to be cluttering bfd.h, and probably shouldn't be used outside bfd/. To make them internal to bfd, make the bfd ecoff small common section declaration global so it can be used instead of a duplicate in gas/ecoff.c. Oddly this needs to go in bfd/ecofflink.c rather than bfd/ecoff.c as the former is compiled for all targets needing the ecoff small common section (some via a call in gas/config/obj-elf.c to a function in gas/ecoff.c) while the latter is not. While doing this rename ecoff_scom_section to _bfd_ecoff_scom_section and remove support for traditional C from GLOBAL_SYM_INIT. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index c29ff2bbc66..7a8318e19af 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -976,57 +976,6 @@ discarded_section (const asection *sec) && sec->sec_info_type != SEC_INFO_TYPE_JUST_SYMS); } -#define BFD_FAKE_SECTION(SEC, SYM, NAME, IDX, FLAGS) \ - /* name, next, prev, id, section_id, index, flags, user_set_vma, */ \ - { NAME, NULL, NULL, IDX, 0, 0, FLAGS, 0, \ - \ - /* linker_mark, linker_has_input, gc_mark, decompress_status, */ \ - 0, 0, 1, 0, \ - \ - /* segment_mark, sec_info_type, use_rela_p, mmapped_p, alloced, */ \ - 0, 0, 0, 0, 0, \ - \ - /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5, */ \ - 0, 0, 0, 0, 0, 0, \ - \ - /* vma, lma, size, rawsize, compressed_size, */ \ - 0, 0, 0, 0, 0, \ - \ - /* output_offset, output_section, relocation, orelocation, */ \ - 0, &SEC, NULL, NULL, \ - \ - /* reloc_count, alignment_power, filepos, rel_filepos, */ \ - 0, 0, 0, 0, \ - \ - /* line_filepos, userdata, contents, lineno, lineno_count, */ \ - 0, NULL, NULL, NULL, 0, \ - \ - /* entsize, kept_section, moving_line_filepos, */ \ - 0, NULL, 0, \ - \ - /* target_index, used_by_bfd, constructor_chain, owner, */ \ - 0, NULL, NULL, NULL, \ - \ - /* symbol, */ \ - (struct bfd_symbol *) SYM, \ - \ - /* map_head, map_tail, already_assigned, type */ \ - { NULL }, { NULL }, NULL, 0 \ - \ - } - -/* We use a macro to initialize the static asymbol structures because - traditional C does not permit us to initialize a union member while - gcc warns if we don't initialize it. - the_bfd, name, value, attr, section [, udata] */ -#ifdef __STDC__ -#define GLOBAL_SYM_INIT(NAME, SECTION) \ - { 0, NAME, 0, BSF_SECTION_SYM, SECTION, { 0 }} -#else -#define GLOBAL_SYM_INIT(NAME, SECTION) \ - { 0, NAME, 0, BSF_SECTION_SYM, SECTION } -#endif - void bfd_section_list_clear (bfd *); asection *bfd_get_section_by_name (bfd *abfd, const char *name); diff --git a/bfd/ecoff-bfd.h b/bfd/ecoff-bfd.h index a1371fa6f1f..cb86960bca5 100644 --- a/bfd/ecoff-bfd.h +++ b/bfd/ecoff-bfd.h @@ -18,6 +18,8 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ +extern asection _bfd_ecoff_scom_section; + extern bool bfd_ecoff_set_gp_value (bfd *abfd, bfd_vma gp_value); extern bool bfd_ecoff_set_regmasks diff --git a/bfd/ecoff.c b/bfd/ecoff.c index 361f4887966..5f9fa43b88f 100644 --- a/bfd/ecoff.c +++ b/bfd/ecoff.c @@ -661,18 +661,6 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd, /* ECOFF symbol table routines. The ECOFF symbol table is described in gcc/mips-tfile.c. */ -/* ECOFF uses two common sections. One is the usual one, and the - other is for small objects. All the small objects are kept - together, and then referenced via the gp pointer, which yields - faster assembler code. This is what we use for the small common - section. */ -static asection ecoff_scom_section; -static const asymbol ecoff_scom_symbol = - GLOBAL_SYM_INIT (SCOMMON, &ecoff_scom_section); -static asection ecoff_scom_section = - BFD_FAKE_SECTION (ecoff_scom_section, &ecoff_scom_symbol, - SCOMMON, 0, SEC_IS_COMMON | SEC_SMALL_DATA); - /* Create an empty symbol. */ asymbol * @@ -813,7 +801,7 @@ ecoff_set_symbol_info (bfd *abfd, } /* Fall through. */ case scSCommon: - asym->section = &ecoff_scom_section; + asym->section = &_bfd_ecoff_scom_section; asym->flags = 0; break; case scVarRegister: @@ -3441,7 +3429,7 @@ ecoff_link_add_externals (bfd *abfd, } /* Fall through. */ case scSCommon: - section = &ecoff_scom_section; + section = &_bfd_ecoff_scom_section; break; case scSUndefined: section = bfd_und_section_ptr; diff --git a/bfd/ecofflink.c b/bfd/ecofflink.c index c1934919f81..ce1bd41b0fb 100644 --- a/bfd/ecofflink.c +++ b/bfd/ecofflink.c @@ -32,7 +32,18 @@ #include "coff/ecoff.h" #include "libcoff.h" #include "libecoff.h" - + +/* ECOFF uses two common sections. One is the usual one, and the + other is for small objects. All the small objects are kept + together, and then referenced via the gp pointer, which yields + faster assembler code. This is what we use for the small common + section. */ +static const asymbol ecoff_scom_symbol = + GLOBAL_SYM_INIT (SCOMMON, &_bfd_ecoff_scom_section); +asection _bfd_ecoff_scom_section = + BFD_FAKE_SECTION (_bfd_ecoff_scom_section, &ecoff_scom_symbol, + SCOMMON, 0, SEC_IS_COMMON | SEC_SMALL_DATA); + /* Routines to swap auxiliary information in and out. I am assuming that the auxiliary information format is always going to be target independent. */ diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 86f220380a8..4f6f5ea2f8a 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -3668,6 +3668,49 @@ bool _bfd_unrecognized_reloc unsigned int r_type) ATTRIBUTE_HIDDEN; /* Extracted from section.c. */ +#define BFD_FAKE_SECTION(SEC, SYM, NAME, IDX, FLAGS) \ + /* name, next, prev, id, section_id, index, flags, user_set_vma, */ \ + { NAME, NULL, NULL, IDX, 0, 0, FLAGS, 0, \ + \ + /* linker_mark, linker_has_input, gc_mark, decompress_status, */ \ + 0, 0, 1, 0, \ + \ + /* segment_mark, sec_info_type, use_rela_p, mmapped_p, alloced, */ \ + 0, 0, 0, 0, 0, \ + \ + /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5, */ \ + 0, 0, 0, 0, 0, 0, \ + \ + /* vma, lma, size, rawsize, compressed_size, */ \ + 0, 0, 0, 0, 0, \ + \ + /* output_offset, output_section, relocation, orelocation, */ \ + 0, &SEC, NULL, NULL, \ + \ + /* reloc_count, alignment_power, filepos, rel_filepos, */ \ + 0, 0, 0, 0, \ + \ + /* line_filepos, userdata, contents, lineno, lineno_count, */ \ + 0, NULL, NULL, NULL, 0, \ + \ + /* entsize, kept_section, moving_line_filepos, */ \ + 0, NULL, 0, \ + \ + /* target_index, used_by_bfd, constructor_chain, owner, */ \ + 0, NULL, NULL, NULL, \ + \ + /* symbol, */ \ + (struct bfd_symbol *) SYM, \ + \ + /* map_head, map_tail, already_assigned, type */ \ + { NULL }, { NULL }, NULL, 0 \ + \ + } + +#define GLOBAL_SYM_INIT(NAME, SECTION) \ + /* the_bfd, name, value, attr, section, udata */ \ + { 0, NAME, 0, BSF_SECTION_SYM, SECTION, { 0 } } + /* Extracted from stabs.c. */ bool _bfd_link_section_stabs (bfd *, struct stab_info *, asection *, asection *, void **, diff --git a/bfd/section.c b/bfd/section.c index b1f7564d190..9460ff916b9 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -712,6 +712,7 @@ EXTERNAL . && sec->sec_info_type != SEC_INFO_TYPE_JUST_SYMS); .} . +INTERNAL .#define BFD_FAKE_SECTION(SEC, SYM, NAME, IDX, FLAGS) \ . {* name, next, prev, id, section_id, index, flags, user_set_vma, *} \ . { NAME, NULL, NULL, IDX, 0, 0, FLAGS, 0, \ @@ -749,19 +750,11 @@ EXTERNAL . {* map_head, map_tail, already_assigned, type *} \ . { NULL }, { NULL }, NULL, 0 \ . \ -. } -. -.{* We use a macro to initialize the static asymbol structures because -. traditional C does not permit us to initialize a union member while -. gcc warns if we don't initialize it. -. the_bfd, name, value, attr, section [, udata] *} -.#ifdef __STDC__ -.#define GLOBAL_SYM_INIT(NAME, SECTION) \ -. { 0, NAME, 0, BSF_SECTION_SYM, SECTION, { 0 }} -.#else -.#define GLOBAL_SYM_INIT(NAME, SECTION) \ -. { 0, NAME, 0, BSF_SECTION_SYM, SECTION } -.#endif +. } +. +.#define GLOBAL_SYM_INIT(NAME, SECTION) \ +. {* the_bfd, name, value, attr, section, udata *} \ +. { 0, NAME, 0, BSF_SECTION_SYM, SECTION, { 0 } } . */ diff --git a/gas/ecoff.c b/gas/ecoff.c index b8c9019f2b2..f665f1158a4 100644 --- a/gas/ecoff.c +++ b/gas/ecoff.c @@ -36,6 +36,7 @@ #include "aout/stab_gnu.h" #include "filenames.h" #include "safe-ctype.h" +#include "ecoff-bfd.h" /* Why isn't this in coff/sym.h? */ #define ST_RFDESCAPE 0xfff @@ -3549,13 +3550,6 @@ ecoff_stab (int what, cur_file_ptr = save_file_ptr; } -static asection ecoff_scom_section; -static const asymbol ecoff_scom_symbol = - GLOBAL_SYM_INIT (SCOMMON, &ecoff_scom_section); -static asection ecoff_scom_section = - BFD_FAKE_SECTION (ecoff_scom_section, &ecoff_scom_symbol, - SCOMMON, 0, SEC_IS_COMMON | SEC_SMALL_DATA); - /* Frob an ECOFF symbol. Small common symbols go into a special .scommon section rather than bfd_com_section. */ @@ -3566,7 +3560,7 @@ ecoff_frob_symbol (symbolS *sym) && S_GET_VALUE (sym) > 0 && S_GET_VALUE (sym) <= bfd_get_gp_size (stdoutput)) { - S_SET_SEGMENT (sym, &ecoff_scom_section); + S_SET_SEGMENT (sym, &_bfd_ecoff_scom_section); } /* Double check weak symbols. */