From bf2dd8d7cf4114b8a60dbb83b340f76b9b2474d1 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 15 Oct 2018 16:10:27 +1030 Subject: BFD_INIT_MAGIC This patch performs a run-time test that a shared libbfd.so has been compiled with the same size bfd_vma as that of apps using the library. On a 32-bit host it is easily possible to have one libbfd.so compiled to support 64-bit targets (or configured with --enable-64-bit-bfd) while another only supports 32-bit targets. The two libraries will have differently sized bfd_vma types, and if the wrong one is loaded all sorts of weird behaviour might be seen. bfd/ PR 23534 * init.c (BFD_INIT_MAGIC): Define. (bfd_init): Return BFD_INIT_MAGIC. bfd-in2.h: Regenerate. binutils/ PR 23534 * addr2line.c (main): Exit with fatal error if bfd_init returns an unexpected value. * ar.c (main): Likewise. * dlltool.c (identify_dll_for_implib): Likewise. * nm.c (main): Likewise. * objcopy.c (main): Likewise. * objdump.c (main): Likewise. * size.c (main): Likewise. * strings.c (main): Likewise. * windmc.c (main): Likewise. * windres.c (main): Likewise. gas/ PR 23534 * as.c (main): Exit with fatal error if bfd_init returns an unexpected value. ld/ PR 23534 * ldmain.c (main): Exit with fatal error if bfd_init returns an unexpected value. --- bfd/ChangeLog | 7 +++++++ bfd/bfd-in2.h | 6 +++++- bfd/init.c | 11 +++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e9696ee..9e0f124 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2018-10-15 Alan Modra + + PR 23534 + * init.c (BFD_INIT_MAGIC): Define. + (bfd_init): Return BFD_INIT_MAGIC. + bfd-in2.h: Regenerate. + 2018-10-13 Alan Modra PR 23770 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 662ef41..beb695a 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1080,8 +1080,12 @@ extern void elf32_csky_next_input_section extern int elf32_csky_setup_section_lists (bfd *, struct bfd_link_info *); /* Extracted from init.c. */ -void bfd_init (void); +size_t 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; diff --git a/bfd/init.c b/bfd/init.c index ec6354e..ad10981 100644 --- a/bfd/init.c +++ b/bfd/init.c @@ -38,17 +38,24 @@ FUNCTION bfd_init SYNOPSIS - void bfd_init (void); + size_t 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. */ -void +size_t bfd_init (void) { + return BFD_INIT_MAGIC; } -- cgit v1.1