From patchwork Mon Jan 9 23:18:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 41215 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2433952wrt; Mon, 9 Jan 2023 15:18:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXvC8Wgoj7f9nbI1VAyT0TvthUSX8MX0FdBtJeS6+JGwdWddQnTJdiWqAGklf8nMYH+9cACl X-Received: by 2002:a05:6402:501c:b0:48f:a9a2:29fa with SMTP id p28-20020a056402501c00b0048fa9a229famr20330293eda.2.1673306328246; Mon, 09 Jan 2023 15:18:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673306328; cv=none; d=google.com; s=arc-20160816; b=DPtGae9Vxt5OJxlEiPp/Jiut9SO8jpQBy2Fc7AgOCbzzpAVuGEOJBAKpRm9DLfNxN/ N0pEMWE3Lc7+gUH7k9tV7FmcMNJXfoKCjV66aCXAOT5zhho/vFbanGsqnt3nJeW+bcpz vA8c9nQ6R3v2h93C/tDpR6it4gijLLz8v7qafAVIJWP2fjOzpJJvyzNn9vY75KvRJPaf BVj2K30eQR0ERYHUp9LEudUrjQCm113BuwRfd6kCrBtCY7XqnraQR+5HKPp9KAsFthEw w4kqYFstAHkt5AebKmROYpfArYOUpyEY8zDvoQXWJ/Mviaq2WwRKr7OolB/qZ3T8ZkrK 8XKQ== 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=G7aaWuz8M6G+/WUKSOzo1jdmk8RRVN5k+TbS5X90Eu4=; b=nEzo62mnfVB9p37TOSFPMBvjxHLMZRBhKISTkYa4bQY+KDcYBJIKo3RK+uEupGk+x9 TZNnKWwUXuOVX5i92CWyEF/OIiFhvEd6sM6gXXieWN5HnYUaE3YhbnSgxbahZVpH44A3 sbA8alGil/0wxn+Jp3SGfd6JRDEZan1ts/se/6Kty0EJmqD5+XYgsLmJPsLgu5mIdB8U 7j1BIpdA9W7u9MN62GXICgYMuetllKqqxlIPmTKriPSl+EApq/a0fMQueN4yqJGph1pD RrZ2AG3+wmF6d9vnM5Ke0sHIQ7x/o9yMcfu9CbYv3tfKlBb6W5Jr8O1oCre1/vEOG9Zq W5Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=jSFTDOst; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f18-20020a0564021e9200b004950ee323c1si11663935edf.129.2023.01.09.15.18.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 15:18:48 -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=jSFTDOst; 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 2C032385840D for ; Mon, 9 Jan 2023 23:18:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C032385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673306327; bh=G7aaWuz8M6G+/WUKSOzo1jdmk8RRVN5k+TbS5X90Eu4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jSFTDOstyrULT/3TZDjdF4MHfrl93xaSbrkNPi/TJHshPNTpLMNMUATYKfA1bPh7a 1WeWj9S8Gl/isu5l/V1hx1lA/JpWVT5XxX53WfDfasp9B7Uk2PpdkF41xiXbYHP48k i7p3llbQzVpXu2WepZ3TyPgavaWWSl7HtChBUK24= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 665143858CDA for ; Mon, 9 Jan 2023 23:18:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 665143858CDA Received: by mail-pf1-x430.google.com with SMTP id k19so7391304pfg.11 for ; Mon, 09 Jan 2023 15:18:38 -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=G7aaWuz8M6G+/WUKSOzo1jdmk8RRVN5k+TbS5X90Eu4=; b=6+kgH7Is/DIuYU/xIVtSmKFmMolEZ6Q0gp7SI0cEjYp+AFg6RpJUxtHJ3/taCoY2KN V2dyracVdYpTpbI38uCcC2N9au+Ggkz1dx5SNiw1pR8E+vAcl/esjS48bqt56k3orB7q SGlMfUHI+9JE4beTtOqJCeNJ0Y9i1iuG2Bz9nqmoUU/jynBldvYiyoEkwYdJGB3pnaum qU0WaN0SQYFAqpQ2TiJQNT1i+Atq6Vn/Dt7EzG45wHBeeMi0pQJYfBsz9iWgerBP9TmU tMC82CccCcy6QzmJ3qpIYRyZysBzmbBkvJ/bdDVR47A1INUjeErJHYIsitwlxC7lETHE 5F8w== X-Gm-Message-State: AFqh2kriHgXo3cpmJRrUWhhVjTvJ4HvcxGrXirkYeQnaPd+xtxf31iFI lr8kz++3jgPAShb4l7eE5FKh5M5o3+8= X-Received: by 2002:aa7:99cf:0:b0:581:c741:f908 with SMTP id v15-20020aa799cf000000b00581c741f908mr40754922pfi.33.1673306317112; Mon, 09 Jan 2023 15:18:37 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:86e3:29a7:f00c:acc1]) by smtp.gmail.com with ESMTPSA id y9-20020aa78f29000000b0056b9ec7e2desm6597344pfr.125.2023.01.09.15.18.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 15:18:36 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 9160711407EA; Tue, 10 Jan 2023 09:48:33 +1030 (ACDT) Date: Tue, 10 Jan 2023 09:48:33 +1030 To: binutils@sourceware.org Subject: Move bfd_init to bfd.c Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.2 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?1754588856774330330?= X-GMAIL-MSGID: =?utf-8?q?1754588856774330330?= init.c contains just one function that doesn't do much. Move it to bfd.c and give it something to do, initialising static state. So far the only initialisation is for bfd.c static variables. The idea behind reinitialising state is to see whether some set of flaky oss-fuzz crashes go away. oss-fuzz stresses binutils in ways that can't occur in reality, feeding multiple testcases into the internals of binutils. So one testcase may affect the result of the next testcase. * init.c: Delete file. Move bfd_init to.. * bfd.c (bfd_init): ..here. Init static variables. * Makefile.am (BFD32_LIBS): Remove init.lo. (BFD32_LIBS_CFILES, BFD_H_FILES): Remove init.c. * doc/local.mk: Remove mention of init.texi and init.c. * Makefile.in: Regenerate. * bfd-in2.h: Regenerate. * po/SRC-POTFILES.in: Regenerate. diff --git a/bfd/Makefile.am b/bfd/Makefile.am index 75d21db88d1..a745372c0a4 100644 --- a/bfd/Makefile.am +++ b/bfd/Makefile.am @@ -77,7 +77,7 @@ BFD_H = bfd.h BFD32_LIBS = \ archive.lo archures.lo bfd.lo bfdio.lo bfdwin.lo cache.lo \ coff-bfd.lo compress.lo corefile.lo elf-properties.lo format.lo \ - hash.lo init.lo libbfd.lo linker.lo merge.lo opncls.lo reloc.lo \ + hash.lo libbfd.lo linker.lo merge.lo opncls.lo reloc.lo \ section.lo simple.lo stab-syms.lo stabs.lo syms.lo targets.lo \ binary.lo ihex.lo srec.lo tekhex.lo verilog.lo @@ -86,7 +86,7 @@ BFD64_LIBS = archive64.lo BFD32_LIBS_CFILES = \ archive.c archures.c bfd.c bfdio.c bfdwin.c cache.c coff-bfd.c \ compress.c corefile.c elf-properties.c format.c hash.c \ - init.c libbfd.c linker.c merge.c opncls.c reloc.c \ + libbfd.c linker.c merge.c opncls.c reloc.c \ section.c simple.c stab-syms.c stabs.c syms.c targets.c \ binary.c ihex.c srec.c tekhex.c verilog.c @@ -923,7 +923,7 @@ stmp-bfd-h: bfd-in3.h rm -f bfd-tmp.h touch stmp-bfd-h -BFD_H_FILES = bfd-in.h init.c opncls.c libbfd.c \ +BFD_H_FILES = bfd-in.h opncls.c libbfd.c \ bfdio.c bfdwin.c section.c archures.c reloc.c \ syms.c bfd.c archive.c corefile.c targets.c format.c \ linker.c simple.c compress.c diff --git a/bfd/Makefile.in b/bfd/Makefile.in index 0b0bb1a950e..1e0c2dcae1e 100644 --- a/bfd/Makefile.in +++ b/bfd/Makefile.in @@ -186,10 +186,9 @@ LTLIBRARIES = $(bfdlib_LTLIBRARIES) $(noinst_LTLIBRARIES) am__DEPENDENCIES_1 = am__objects_1 = archive.lo archures.lo bfd.lo bfdio.lo bfdwin.lo \ cache.lo coff-bfd.lo compress.lo corefile.lo elf-properties.lo \ - format.lo hash.lo init.lo libbfd.lo linker.lo merge.lo \ - opncls.lo reloc.lo section.lo simple.lo stab-syms.lo stabs.lo \ - syms.lo targets.lo binary.lo ihex.lo srec.lo tekhex.lo \ - verilog.lo + format.lo hash.lo libbfd.lo linker.lo merge.lo opncls.lo \ + reloc.lo section.lo simple.lo stab-syms.lo stabs.lo syms.lo \ + targets.lo binary.lo ihex.lo srec.lo tekhex.lo verilog.lo am_libbfd_la_OBJECTS = $(am__objects_1) libbfd_la_OBJECTS = $(am_libbfd_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) @@ -546,7 +545,7 @@ BFD_H = bfd.h BFD32_LIBS = \ archive.lo archures.lo bfd.lo bfdio.lo bfdwin.lo cache.lo \ coff-bfd.lo compress.lo corefile.lo elf-properties.lo format.lo \ - hash.lo init.lo libbfd.lo linker.lo merge.lo opncls.lo reloc.lo \ + hash.lo libbfd.lo linker.lo merge.lo opncls.lo reloc.lo \ section.lo simple.lo stab-syms.lo stabs.lo syms.lo targets.lo \ binary.lo ihex.lo srec.lo tekhex.lo verilog.lo @@ -554,7 +553,7 @@ BFD64_LIBS = archive64.lo BFD32_LIBS_CFILES = \ archive.c archures.c bfd.c bfdio.c bfdwin.c cache.c coff-bfd.c \ compress.c corefile.c elf-properties.c format.c hash.c \ - init.c libbfd.c linker.c merge.c opncls.c reloc.c \ + libbfd.c linker.c merge.c opncls.c reloc.c \ section.c simple.c stab-syms.c stabs.c syms.c targets.c \ binary.c ihex.c srec.c tekhex.c verilog.c @@ -1216,7 +1215,7 @@ libbfd_la_LIBADD = `cat ofiles` @SHARED_LIBADD@ $(LIBDL) $(ZLIB) $(ZSTD_LIBS) .. # everything else starts using libtool. FIXME. noinst_LIBRARIES = libbfd.a libbfd_a_SOURCES = -BFD_H_FILES = bfd-in.h init.c opncls.c libbfd.c \ +BFD_H_FILES = bfd-in.h opncls.c libbfd.c \ bfdio.c bfdwin.c section.c archures.c reloc.c \ syms.c bfd.c archive.c corefile.c targets.c format.c \ linker.c simple.c compress.c @@ -1263,7 +1262,6 @@ DOCFILES = \ doc/elf.texi \ doc/format.texi \ doc/hash.texi \ - doc/init.texi \ doc/libbfd.texi \ doc/linker.texi \ doc/mmo.texi \ @@ -1296,13 +1294,12 @@ SRCPROT = $(srcdir)/archive.c $(srcdir)/archures.c \ $(srcdir)/bfdio.c $(srcdir)/bfdwin.c \ $(srcdir)/opncls.c $(srcdir)/reloc.c \ $(srcdir)/section.c $(srcdir)/syms.c \ - $(srcdir)/targets.c $(srcdir)/init.c + $(srcdir)/targets.c SRCIPROT = $(srcdir)/cache.c $(srcdir)/libbfd.c \ $(srcdir)/bfdio.c $(srcdir)/bfdwin.c \ $(srcdir)/reloc.c $(srcdir)/cpu-h8300.c \ - $(srcdir)/archures.c \ - $(srcdir)/init.c + $(srcdir)/archures.c TEXIDIR = $(srcdir)/../texinfo/fsf info_TEXINFOS = doc/bfd.texi @@ -1682,7 +1679,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i386lynx.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i386msdos.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ihex.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/init.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/irix-core.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libbfd.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/linker.Plo@am__quote@ diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index aeb8d5de7b9..bb2b30200dc 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1,8 +1,8 @@ /* DO NOT EDIT! -*- buffer-read-only: t -*- This file is automatically - generated from "bfd-in.h", "init.c", "opncls.c", "libbfd.c", - "bfdio.c", "bfdwin.c", "section.c", "archures.c", "reloc.c", - "syms.c", "bfd.c", "archive.c", "corefile.c", "targets.c", "format.c", - "linker.c", "simple.c" and "compress.c". + generated from "bfd-in.h", "opncls.c", "libbfd.c", "bfdio.c", + "bfdwin.c", "section.c", "archures.c", "reloc.c", "syms.c", "bfd.c", + "archive.c", "corefile.c", "targets.c", "format.c", "linker.c", + "simple.c" and "compress.c". Run "make headers" in your build bfd/ to regenerate. */ /* Main header file for the bfd library -- portable access to object files. @@ -488,13 +488,6 @@ startswith (const char *str, const char *prefix) { return strncmp (str, prefix, strlen (prefix)) == 0; } -/* Extracted from init.c. */ -unsigned int bfd_init (void); - - -/* Value returned by bfd_init. */ - -#define BFD_INIT_MAGIC (sizeof (struct bfd_section)) /* Extracted from opncls.c. */ /* Set to N to open the next N BFDs using an alternate id space. */ extern unsigned int bfd_use_reserved_id; @@ -7263,6 +7256,11 @@ bfd_vma bfd_emul_get_commonpagesize (const char *); char *bfd_demangle (bfd *, const char *, int); +unsigned int bfd_init (void); + +/* Value returned by bfd_init. */ +#define BFD_INIT_MAGIC (sizeof (struct bfd_section)) + /* Extracted from archive.c. */ symindex bfd_get_next_mapent (bfd *abfd, symindex previous, carsym **sym); diff --git a/bfd/bfd.c b/bfd/bfd.c index 9cbb674b989..1d1c4498938 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -696,9 +696,9 @@ CODE_FRAGMENT . */ -static bfd_error_type bfd_error = bfd_error_no_error; -static bfd *input_bfd = NULL; -static bfd_error_type input_error = bfd_error_no_error; +static bfd_error_type bfd_error; +static bfd *input_bfd; +static bfd_error_type input_error; const char *const bfd_errmsgs[] = { @@ -2605,3 +2605,34 @@ _bfd_get_link_info (bfd *abfd) return elf_link_info (abfd); } + +/* +FUNCTION + bfd_init + +SYNOPSIS + unsigned int bfd_init (void); + +DESCRIPTION + This routine must be called before any other BFD function to + initialize magical internal data structures. + Returns a magic number, which may be used to check + that the bfd library is configured as expected by users. + +.{* Value returned by bfd_init. *} +.#define BFD_INIT_MAGIC (sizeof (struct bfd_section)) +. +*/ + +unsigned int +bfd_init (void) +{ + bfd_error = bfd_error_no_error; + input_bfd = NULL; + input_error = bfd_error_no_error; + _bfd_error_program_name = NULL; + _bfd_error_internal = error_handler_fprintf; + _bfd_assert_handler = _bfd_default_assert_handler; + + return BFD_INIT_MAGIC; +} diff --git a/bfd/doc/local.mk b/bfd/doc/local.mk index cf2b479c1c9..41ab89fc6d8 100644 --- a/bfd/doc/local.mk +++ b/bfd/doc/local.mk @@ -32,7 +32,6 @@ DOCFILES = \ %D%/elf.texi \ %D%/format.texi \ %D%/hash.texi \ - %D%/init.texi \ %D%/libbfd.texi \ %D%/linker.texi \ %D%/mmo.texi \ @@ -64,13 +63,12 @@ SRCPROT = $(srcdir)/archive.c $(srcdir)/archures.c \ $(srcdir)/bfdio.c $(srcdir)/bfdwin.c \ $(srcdir)/opncls.c $(srcdir)/reloc.c \ $(srcdir)/section.c $(srcdir)/syms.c \ - $(srcdir)/targets.c $(srcdir)/init.c + $(srcdir)/targets.c SRCIPROT = $(srcdir)/cache.c $(srcdir)/libbfd.c \ $(srcdir)/bfdio.c $(srcdir)/bfdwin.c \ $(srcdir)/reloc.c $(srcdir)/cpu-h8300.c \ - $(srcdir)/archures.c \ - $(srcdir)/init.c + $(srcdir)/archures.c TEXIDIR = $(srcdir)/../texinfo/fsf diff --git a/bfd/init.c b/bfd/init.c index eee9891b1b5..bcae3cbdb99 100644 --- a/bfd/init.c +++ b/bfd/init.c @@ -33,29 +33,3 @@ SUBSECTION These are the functions that handle initializing a BFD. */ -/* -FUNCTION - bfd_init - -SYNOPSIS - unsigned int bfd_init (void); - -DESCRIPTION - This routine must be called before any other BFD function to - initialize magical internal data structures. - Returns a magic number, which may be used to check - that the bfd library is configured as expected by users. -. -.{* Value returned by bfd_init. *} -. -.#define BFD_INIT_MAGIC (sizeof (struct bfd_section)) -*/ - -/* Actually, there is currently nothing for this function to do. - However, someday it may be needed, so keep it around. */ - -unsigned int -bfd_init (void) -{ - return BFD_INIT_MAGIC; -} diff --git a/bfd/po/SRC-POTFILES.in b/bfd/po/SRC-POTFILES.in index 26d5a2ce25d..a127ac0904c 100644 --- a/bfd/po/SRC-POTFILES.in +++ b/bfd/po/SRC-POTFILES.in @@ -284,7 +284,6 @@ i386bsd.c i386lynx.c i386msdos.c ihex.c -init.c irix-core.c libaout.h libbfd.c