[binutils-gdb] move _bfd_mul_overflow from libbfd.h to bfd.h
Alan Modra
amodra@sourceware.org
Wed Jun 17 23:56:00 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=76f08a36658bf1917e58bedd3183f531e5405691
commit 76f08a36658bf1917e58bedd3183f531e5405691
Author: Alan Modra <amodra@gmail.com>
Date: Thu Jun 18 09:21:11 2026 +0930
move _bfd_mul_overflow from libbfd.h to bfd.h
Replace gas_mul_overflow with _bfd_mul_overflow, and don't include
libbfd.h outside of bfd/.
bfd/
* libbfd-in.h (_bfd_mul_overflow, _bfd_constant_p): Move to..
* bfd-in.h: ..here. Include inttypes.h earlier.
* libbfd.h: Regenerate.
* bfd-in2.h: Regenerate.
gas/
* as.h (gas_mul_overflow): Don't define.
* read.c (do_repeat, s_space): Replace gas_mul_overflow with
_bfd_mul_overflow.
* symbols.c (notes_calloc): Likewise.
ld/
* emultempl/nto.em: Don't include libbfd.h.
* ldlang.c: Likewise.
* pdb.c: Likewise.
opcodes/
* kvx-opc.c: Don't include libbfd.h.
Diff:
---
bfd/bfd-in.h | 17 +++++++++++++++--
bfd/bfd-in2.h | 17 +++++++++++++++--
bfd/libbfd-in.h | 14 --------------
bfd/libbfd.h | 14 --------------
gas/as.h | 8 --------
gas/read.c | 4 ++--
gas/symbols.c | 2 +-
ld/emultempl/nto.em | 1 -
ld/ldlang.c | 1 -
ld/pdb.c | 1 -
opcodes/kvx-opc.c | 1 -
11 files changed, 33 insertions(+), 47 deletions(-)
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 3d15132b956..5cac762fb4f 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -41,6 +41,7 @@ extern "C" {
#include <stdarg.h>
#include <string.h>
#include <sys/stat.h>
+#include <inttypes.h>
#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
#ifndef SABER
@@ -70,12 +71,24 @@ extern "C" {
/* The word size of the default bfd target. */
#define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
-#include <inttypes.h>
-
#if BFD_ARCH_SIZE >= 64
#define BFD64
#endif
+#if GCC_VERSION >= 7000
+#define _bfd_mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
+#else
+/* Assumes unsigned values. Careful! Args evaluated multiple times. */
+#define _bfd_mul_overflow(a, b, res) \
+ ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
+#endif
+
+#ifdef __GNUC__
+#define _bfd_constant_p(v) __builtin_constant_p (v)
+#else
+#define _bfd_constant_p(v) 0
+#endif
+
/* Silence "applying zero offset to null pointer" UBSAN warnings. */
#define PTR_ADD(P,A) ((A) != 0 ? (P) + (A) : (P))
/* Also prevent non-zero offsets from being applied to a null pointer. */
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index c019a5accd4..e49d67316f3 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -48,6 +48,7 @@ extern "C" {
#include <stdarg.h>
#include <string.h>
#include <sys/stat.h>
+#include <inttypes.h>
#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
#ifndef SABER
@@ -77,12 +78,24 @@ extern "C" {
/* The word size of the default bfd target. */
#define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
-#include <inttypes.h>
-
#if BFD_ARCH_SIZE >= 64
#define BFD64
#endif
+#if GCC_VERSION >= 7000
+#define _bfd_mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
+#else
+/* Assumes unsigned values. Careful! Args evaluated multiple times. */
+#define _bfd_mul_overflow(a, b, res) \
+ ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
+#endif
+
+#ifdef __GNUC__
+#define _bfd_constant_p(v) __builtin_constant_p (v)
+#else
+#define _bfd_constant_p(v) 0
+#endif
+
/* Silence "applying zero offset to null pointer" UBSAN warnings. */
#define PTR_ADD(P,A) ((A) != 0 ? (P) + (A) : (P))
/* Also prevent non-zero offsets from being applied to a null pointer. */
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index 7b4c93228a7..e7ec6bfa9a0 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -840,20 +840,6 @@ extern uintptr_t _bfd_pagesize_m1 ATTRIBUTE_HIDDEN;
extern uintptr_t _bfd_minimum_mmap_size ATTRIBUTE_HIDDEN;
#endif
-#if GCC_VERSION >= 7000
-#define _bfd_mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
-#else
-/* Assumes unsigned values. Careful! Args evaluated multiple times. */
-#define _bfd_mul_overflow(a, b, res) \
- ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
-#endif
-
-#ifdef __GNUC__
-#define _bfd_constant_p(v) __builtin_constant_p (v)
-#else
-#define _bfd_constant_p(v) 0
-#endif
-
static inline void *
_bfd_alloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
{
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index 3d19b597b71..27bc0875cf6 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -846,20 +846,6 @@ extern uintptr_t _bfd_pagesize_m1 ATTRIBUTE_HIDDEN;
extern uintptr_t _bfd_minimum_mmap_size ATTRIBUTE_HIDDEN;
#endif
-#if GCC_VERSION >= 7000
-#define _bfd_mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
-#else
-/* Assumes unsigned values. Careful! Args evaluated multiple times. */
-#define _bfd_mul_overflow(a, b, res) \
- ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
-#endif
-
-#ifdef __GNUC__
-#define _bfd_constant_p(v) __builtin_constant_p (v)
-#else
-#define _bfd_constant_p(v) 0
-#endif
-
static inline void *
_bfd_alloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
{
diff --git a/gas/as.h b/gas/as.h
index f0fbf38adee..94bc816be1e 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -119,14 +119,6 @@ void *mempcpy(void *, const void *, size_t);
#define xfree free
-#if GCC_VERSION >= 7000
-#define gas_mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
-#else
-/* Assumes unsigned values. Careful! Args evaluated multiple times. */
-#define gas_mul_overflow(a, b, res) \
- ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
-#endif
-
#include "asintl.h"
#define BAD_CASE(val) \
diff --git a/gas/read.c b/gas/read.c
index 5b6a3c115a0..56bd222acf0 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -3222,7 +3222,7 @@ do_repeat (size_t count, const char *start, const char *end,
sb_terminate (&one);
limit = (size_t) LONG_MAX < 0xffffffff ? (size_t) LONG_MAX : 0xffffffff;
- if (gas_mul_overflow (count, one.len, &total) || total > limit)
+ if (_bfd_mul_overflow (count, one.len, &total) || total > limit)
{
as_bad_where (file, line,
_("excessive count %zu for %s - ignored"), count, start);
@@ -3580,7 +3580,7 @@ s_space (int mult)
}
if ((unsigned int) mult <= 1)
total = repeat;
- else if (gas_mul_overflow (repeat, mult, &total)
+ else if (_bfd_mul_overflow (repeat, mult, &total)
|| (offsetT) total < 0)
{
as_warn (_(".space repeat count overflow, ignored"));
diff --git a/gas/symbols.c b/gas/symbols.c
index 3fc0a97927c..02df923d128 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -259,7 +259,7 @@ notes_calloc (size_t n, size_t size)
{
size_t amt;
void *ret;
- if (gas_mul_overflow (n, size, &amt))
+ if (_bfd_mul_overflow (n, size, &amt))
{
obstack_alloc_failed_handler ();
abort ();
diff --git a/ld/emultempl/nto.em b/ld/emultempl/nto.em
index 7af2bef0e21..e5b47a9a94f 100644
--- a/ld/emultempl/nto.em
+++ b/ld/emultempl/nto.em
@@ -29,7 +29,6 @@ cat >>e${EMULATION_NAME}.c <<EOF
#include "elf/internal.h"
#include "elf/common.h"
#include "elf-bfd.h"
-#include "../bfd/libbfd.h"
bool nto_lazy_stack = false;
struct nto_stack_note
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 48dd33a49bb..b04ba113aaa 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -21,7 +21,6 @@
#include "sysdep.h"
#include <limits.h>
#include "bfd.h"
-#include "libbfd.h"
#include "libiberty.h"
#include "filenames.h"
#include "safe-ctype.h"
diff --git a/ld/pdb.c b/ld/pdb.c
index c0ac50b323d..673d041ce2e 100644
--- a/ld/pdb.c
+++ b/ld/pdb.c
@@ -23,7 +23,6 @@
#include "ld.h"
#include "ldmain.h"
#include "ldmisc.h"
-#include "libbfd.h"
#include "libiberty.h"
#include "coff/i386.h"
#include "coff/external.h"
diff --git a/opcodes/kvx-opc.c b/opcodes/kvx-opc.c
index e6504924094..bd74b90670f 100644
--- a/opcodes/kvx-opc.c
+++ b/opcodes/kvx-opc.c
@@ -22,7 +22,6 @@
#include <stddef.h>
#include <stdio.h>
#include "bfd.h"
-#include "libbfd.h"
#include <elf/kvx.h>
#include <opcode/kvx.h>
More information about the Binutils-cvs
mailing list