From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by sourceware.org (Postfix) with ESMTPS id 5AA983858288 for ; Wed, 1 Jun 2022 01:27:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5AA983858288 Received: by mail-pj1-x1032.google.com with SMTP id o6-20020a17090a0a0600b001e2c6566046so4660052pjo.0 for ; Tue, 31 May 2022 18:27:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3sRIzv8mIGXpgxc2hmKddPuv+RpHJHFxQGCXvWjZvcQ=; b=Bv2QNNZvsS2WcsKNMP58k/9lbfOT5GPWLVHzR8sV2fija8BoD00xifsYDto+wxmZx4 1Jar4tM635lHveLAtaTCu3ne1CrU6I0YdSXiLiVzKi7JPme2wMrOI7N1aomtZlzjBqAo g+IqjsnboWZl2+cc3Ba2XCOhDcpHYu5Nysd7HJ383yQYHuv/n2yBoVJLB67Ck8wZNUHo v3pby159fEp9GRhA2nFhmfzZfVk1TRuLnPDYFlBgDDIgglGbyS8d2w/DDkI/mIP6G8D9 /po8QTai/ZCR1vpOL9YvVw1jK/a22bS6c2bst66xLD83h39aTeu8biqkAjAZA4gbZaMZ xkYg== X-Gm-Message-State: AOAM532vLm9JvdSDa6SImDsMnCL3IaPqWubOj7YKercffYWTQ2l0z0q0 FJub3uu4BsNZOK3q3ujVC2xNtsxBct8= X-Google-Smtp-Source: ABdhPJyOy4EwKcx7PIKZVWwdgEP+q0Lg4VZ8M4J7j8fmBVq0gBhTqj6zl45E+v9dImNvL+eZYMSfZQ== X-Received: by 2002:a17:90b:1e4f:b0:1e0:b91:39ef with SMTP id pi15-20020a17090b1e4f00b001e00b9139efmr31394888pjb.51.1654046827309; Tue, 31 May 2022 18:27:07 -0700 (PDT) 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 k62-20020a638441000000b003fbc60e3358sm116310pgd.4.2022.05.31.18.27.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 18:27:06 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id B22B2114015F; Wed, 1 Jun 2022 10:57:03 +0930 (ACST) Date: Wed, 1 Jun 2022 10:57:03 +0930 From: Alan Modra To: "H.J. Lu" Cc: Binutils Subject: Re: use libiberty xmalloc in bfd/doc/chew.c Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3037.1 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, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Wed, 01 Jun 2022 01:27:12 -0000 On Tue, May 31, 2022 at 05:10:16PM -0700, H.J. Lu wrote: > On Mon, May 30, 2022 at 2:36 AM Alan Modra via Binutils > wrote: > > > > Catch out-of-memory. > > > > * doc/chew.c: Include libibery.h. > > (init_string_with_size, nextword): Replace malloc with xmalloc. > > (newentry, add_to_definition): Likewise. > > (catchar, catbuf): Replace realloc with xrealloc. > > (add_intrinsic): Replace strdup with xstrdup. > > * doc/local.mk (LIBIBERTY): Define. > > (chew): Link against libiberty. > > * Makefile.in: Regenerate. > > > This breaks --enable-pgo-build since ../libiberty/libiberty.a is a host library > compiled with -fprofile-generate, but chew is a build program. If we want > to use libiberty.a in a build program, we need to build a libiberty.a for build. Drat, I didn't think of that. Committing the following: We can't use libiberty.a in chew. libiberty is a host library, chew a build program. Partly revert commit 7273d78f3f7a, instead define local versions of the libiberty functions. ansidecl.h also isn't needed. * doc/chew.c: Don't include libiberty.h or ansidecl.h. (xmalloc, xrealloc, xstrdup): New functions. * doc/local.mk (LIBIBERTY): Don't define or use. * Makefile.in: Regenerate. diff --git a/bfd/Makefile.in b/bfd/Makefile.in index 53cac75af0e..741e08d603c 100644 --- a/bfd/Makefile.in +++ b/bfd/Makefile.in @@ -1301,7 +1301,6 @@ doc_bfd_TEXINFOS = $(DOCFILES) doc/bfdsumm.texi AM_MAKEINFOFLAGS = --no-split -I "$(srcdir)/doc" -I doc TEXI2DVI = texi2dvi -I "$(srcdir)/doc" -I doc MKDOC = doc/chew$(EXEEXT_FOR_BUILD) -LIBIBERTY = ../libiberty/libiberty.a # We can't replace these rules with an implicit rule, because # makes without VPATH support couldn't find the .h files in `..'. @@ -2488,7 +2487,7 @@ doc/chew.stamp: $(srcdir)/doc/chew.c doc/$(am__dirstamp) $(AM_V_CCLD)$(CC_FOR_BUILD) -o doc/chw$$$$$(EXEEXT_FOR_BUILD) $(CFLAGS_FOR_BUILD) \ $(LDFLAGS_FOR_BUILD) $(H_CFLAGS) \ -I. -I$(srcdir) -Idoc -I$(srcdir)/../include -I$(srcdir)/../intl -I../intl \ - $(srcdir)/doc/chew.c $(LIBIBERTY) && \ + $(srcdir)/doc/chew.c && \ $(SHELL) $(srcdir)/../move-if-change \ doc/chw$$$$$(EXEEXT_FOR_BUILD) $(MKDOC) && \ touch $@ diff --git a/bfd/doc/chew.c b/bfd/doc/chew.c index a12c00370d9..1695173970a 100644 --- a/bfd/doc/chew.c +++ b/bfd/doc/chew.c @@ -81,8 +81,6 @@ Foo. */ -#include "ansidecl.h" -#include "libiberty.h" #include #include #include @@ -145,6 +143,45 @@ die (char *msg) exit (1); } +void * +xmalloc (size_t size) +{ + void *newmem; + + if (size == 0) + size = 1; + newmem = malloc (size); + if (!newmem) + die ("out of memory"); + + return newmem; +} + +void * +xrealloc (void *oldmem, size_t size) +{ + void *newmem; + + if (size == 0) + size = 1; + if (!oldmem) + newmem = malloc (size); + else + newmem = realloc (oldmem, size); + if (!newmem) + die ("out of memory"); + + return newmem; +} + +char * +xstrdup (const char *s) +{ + size_t len = strlen (s) + 1; + char *ret = xmalloc (len); + return memcpy (ret, s, len); +} + static void init_string_with_size (string_type *buffer, unsigned int size) { diff --git a/bfd/doc/local.mk b/bfd/doc/local.mk index 8c6932802f6..931942f874c 100644 --- a/bfd/doc/local.mk +++ b/bfd/doc/local.mk @@ -82,14 +82,12 @@ TEXI2DVI = texi2dvi -I "$(srcdir)/%D%" -I %D% MKDOC = %D%/chew$(EXEEXT_FOR_BUILD) -LIBIBERTY = ../libiberty/libiberty.a - $(MKDOC): %D%/chew.stamp ; @true %D%/chew.stamp: $(srcdir)/%D%/chew.c %D%/$(am__dirstamp) $(AM_V_CCLD)$(CC_FOR_BUILD) -o %D%/chw$$$$$(EXEEXT_FOR_BUILD) $(CFLAGS_FOR_BUILD) \ $(LDFLAGS_FOR_BUILD) $(H_CFLAGS) \ -I. -I$(srcdir) -I%D% -I$(srcdir)/../include -I$(srcdir)/../intl -I../intl \ - $(srcdir)/%D%/chew.c $(LIBIBERTY) && \ + $(srcdir)/%D%/chew.c && \ $(SHELL) $(srcdir)/../move-if-change \ %D%/chw$$$$$(EXEEXT_FOR_BUILD) $(MKDOC) && \ touch $@ -- Alan Modra Australia Development Lab, IBM