From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 328B93857437 for ; Wed, 3 May 2023 06:03:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 328B93857437 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-pg1-x535.google.com with SMTP id 41be03b00d2f7-52160f75920so3286946a12.2 for ; Tue, 02 May 2023 23:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683093802; x=1685685802; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=1LP/o9/dqCWrToAYJESCOrPEoeJMk30ds7A1IPApWa0=; b=pRiFta069rB5CY/xoTzRfHclblgfXx/03f6qV9Bsmrg0CriKPR2ndy5/fJOf++iTmr pOvvBMVpJAU5X8VfUsSTJNlSlXQcx2hTP+bmuG31lIu9Jk7PQr6sXzmBX1zdOg5qKZDF z0zdaItTW7WBDwOVdLstNnX6u19sp0yQlGi81id4TdK3YdHSfBBMpS+JPVKvamsxPLky 8aeiiW7oKfbHaL7LesJoSwkNiLVh5OZapVMVTJamiG4Qdya18GEbCQni9FdthYZ6mrzU x+pAp+jHUj1PLdLtcwrfpoaf0e3BFU9fGvlFygjY+U6C6xedDEnHeF0Qz+1iRXOcVD2D kSbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683093802; x=1685685802; 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=1LP/o9/dqCWrToAYJESCOrPEoeJMk30ds7A1IPApWa0=; b=mE0HusuS9Rczp2vlKFe2Z/4D+l2IIbD56+TfNC/3YSK62eIns2/j6r3VJFIpwksHsk 0L+fYze771vgbeE3Tyd7Ixf7GlCg3gzTsVql/aEisHsGbfccdM81s0TTghYFiXen0e/g jmPI7HdOuWhpd/HulmKJC9bh3NWyP4MQR67j9dR7tccOjjKGlQwdW5yyxG0WDWKiq0M9 jVOVuyeD44Qzqr5sz7LVGadoAAylicpyifZTrXl4mFqYsejClPwg6hpBKuSfUHMRifLT ReXQatmvPbhO6NT2KPhgTOVhxTPhzZCTjOFKElXBbMNFwpHmHJv8tyFlGMtYCHxOIEPH YI3w== X-Gm-Message-State: AC+VfDx+8tHfQz9EvFX02HE18WPWPZqcsNeGWweXXbzgol1S5VKp1HuI 0AF51iOSavHnXqrNn0JRJxCuLq4Q0gc= X-Google-Smtp-Source: ACHHUZ6LK1tMgW7hWzRuHk2WdVoqjKkOUtJVqg/uDvJKuyhPD8u4CSUGfvUlRuqYn1Y0M6G/RmpZ7Q== X-Received: by 2002:a05:6a00:2e1e:b0:643:587:f48 with SMTP id fc30-20020a056a002e1e00b0064305870f48mr4277725pfb.3.1683093801603; Tue, 02 May 2023 23:03:21 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:e289:4864:2d83:727f]) by smtp.gmail.com with ESMTPSA id ei28-20020a056a0080dc00b0063d24fcc2besm22720412pfb.125.2023.05.02.23.03.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 23:03:20 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id ADC141142C83; Wed, 3 May 2023 15:33:18 +0930 (ACST) Date: Wed, 3 May 2023 15:33:18 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Move bfd_alloc, bfd_zalloc and bfd_release to libbfd.c Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3034.4 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 List-Id: These functions don't belong in opncls.c. * libbfd-in.h (bfd_release): Delete prototype. * opncls.c (bfd_alloc, bfd_zalloc, bfd_release): Move to.. * libbfd.c: ..here. Include objalloc.c and provide bfd_release with a FUNCTION comment. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 470a3cc9d3b..0c1844d5ca4 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -495,10 +495,6 @@ bool bfd_make_writable (bfd *abfd); bool bfd_make_readable (bfd *abfd); -void *bfd_alloc (bfd *abfd, bfd_size_type wanted); - -void *bfd_zalloc (bfd *abfd, bfd_size_type wanted); - uint32_t bfd_calc_gnu_debuglink_crc32 (uint32_t crc, const bfd_byte *buf, bfd_size_type len); @@ -523,6 +519,12 @@ char *bfd_follow_build_id_debuglink (bfd *abfd, const char *dir); const char *bfd_set_filename (bfd *abfd, const char *filename); /* Extracted from libbfd.c. */ +void *bfd_alloc (bfd *abfd, bfd_size_type wanted); + +void *bfd_zalloc (bfd *abfd, bfd_size_type wanted); + +void bfd_release (bfd *, void *); + /* Byte swapping macros for user section data. */ diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h index 4305b8416ea..ca15b8b0a23 100644 --- a/bfd/libbfd-in.h +++ b/bfd/libbfd-in.h @@ -119,10 +119,6 @@ bfd_strdup (const char *str) memcpy (buf, str, len); return buf; } -/* These routines allocate and free things on the BFD's objalloc. */ - -extern void bfd_release - (bfd *, void *) ATTRIBUTE_HIDDEN; extern bfd * _bfd_create_empty_archive_element_shell (bfd *) ATTRIBUTE_HIDDEN; diff --git a/bfd/libbfd.c b/bfd/libbfd.c index e21cd988208..66ef32469fb 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -22,6 +22,7 @@ #include "sysdep.h" #include "bfd.h" #include "libbfd.h" +#include "objalloc.h" #ifndef HAVE_GETPAGESIZE #define getpagesize() 2048 @@ -416,6 +417,87 @@ bfd_zmalloc (bfd_size_type size) return ptr; } +/* +FUNCTION + bfd_alloc + +SYNOPSIS + void *bfd_alloc (bfd *abfd, bfd_size_type wanted); + +DESCRIPTION + Allocate a block of @var{wanted} bytes of memory attached to + <> and return a pointer to it. +*/ + +void * +bfd_alloc (bfd *abfd, bfd_size_type size) +{ + void *ret; + unsigned long ul_size = (unsigned long) size; + + if (size != ul_size + /* Note - although objalloc_alloc takes an unsigned long as its + argument, internally the size is treated as a signed long. This can + lead to problems where, for example, a request to allocate -1 bytes + can result in just 1 byte being allocated, rather than + ((unsigned long) -1) bytes. Also memory checkers will often + complain about attempts to allocate a negative amount of memory. + So to stop these problems we fail if the size is negative. */ + || ((signed long) ul_size) < 0) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + + ret = objalloc_alloc ((struct objalloc *) abfd->memory, ul_size); + if (ret == NULL) + bfd_set_error (bfd_error_no_memory); + else + abfd->alloc_size += size; + return ret; +} + +/* +FUNCTION + bfd_zalloc + +SYNOPSIS + void *bfd_zalloc (bfd *abfd, bfd_size_type wanted); + +DESCRIPTION + Allocate a block of @var{wanted} bytes of zeroed memory + attached to <> and return a pointer to it. +*/ + +void * +bfd_zalloc (bfd *abfd, bfd_size_type size) +{ + void *res; + + res = bfd_alloc (abfd, size); + if (res) + memset (res, 0, (size_t) size); + return res; +} + +/* +FUNCTION + bfd_release + +SYNOPSIS + void bfd_release (bfd *, void *); + +DESCRIPTION + Free a block allocated for a BFD. + Note: Also frees all more recently allocated blocks! +*/ + +void +bfd_release (bfd *abfd, void *block) +{ + objalloc_free_block ((struct objalloc *) abfd->memory, block); +} + /* INTERNAL_FUNCTION bfd_write_bigendian_4byte_int diff --git a/bfd/libbfd.h b/bfd/libbfd.h index aceec4ab9c0..3bd79d2d3bd 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -125,10 +125,6 @@ bfd_strdup (const char *str) memcpy (buf, str, len); return buf; } -/* These routines allocate and free things on the BFD's objalloc. */ - -extern void bfd_release - (bfd *, void *) ATTRIBUTE_HIDDEN; extern bfd * _bfd_create_empty_archive_element_shell (bfd *) ATTRIBUTE_HIDDEN; diff --git a/bfd/opncls.c b/bfd/opncls.c index 602dc80a6c4..b7b9d8f2d0b 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -1042,79 +1042,6 @@ bfd_make_readable (bfd *abfd) return true; } -/* -FUNCTION - bfd_alloc - -SYNOPSIS - void *bfd_alloc (bfd *abfd, bfd_size_type wanted); - -DESCRIPTION - Allocate a block of @var{wanted} bytes of memory attached to - <> and return a pointer to it. -*/ - -void * -bfd_alloc (bfd *abfd, bfd_size_type size) -{ - void *ret; - unsigned long ul_size = (unsigned long) size; - - if (size != ul_size - /* Note - although objalloc_alloc takes an unsigned long as its - argument, internally the size is treated as a signed long. This can - lead to problems where, for example, a request to allocate -1 bytes - can result in just 1 byte being allocated, rather than - ((unsigned long) -1) bytes. Also memory checkers will often - complain about attempts to allocate a negative amount of memory. - So to stop these problems we fail if the size is negative. */ - || ((signed long) ul_size) < 0) - { - bfd_set_error (bfd_error_no_memory); - return NULL; - } - - ret = objalloc_alloc ((struct objalloc *) abfd->memory, ul_size); - if (ret == NULL) - bfd_set_error (bfd_error_no_memory); - else - abfd->alloc_size += size; - return ret; -} - -/* -FUNCTION - bfd_zalloc - -SYNOPSIS - void *bfd_zalloc (bfd *abfd, bfd_size_type wanted); - -DESCRIPTION - Allocate a block of @var{wanted} bytes of zeroed memory - attached to <> and return a pointer to it. -*/ - -void * -bfd_zalloc (bfd *abfd, bfd_size_type size) -{ - void *res; - - res = bfd_alloc (abfd, size); - if (res) - memset (res, 0, (size_t) size); - return res; -} - -/* Free a block allocated for a BFD. - Note: Also frees all more recently allocated blocks! */ - -void -bfd_release (bfd *abfd, void *block) -{ - objalloc_free_block ((struct objalloc *) abfd->memory, block); -} - - /* GNU Extension: separate debug-info files -- Alan Modra Australia Development Lab, IBM