* Don't include libbfd.h outside of bfd, part 1
@ 2016-07-16 13:10 Alan Modra
2016-07-16 13:12 ` Don't include libbfd.h outside of bfd, part 2 Alan Modra
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Alan Modra @ 2016-07-16 13:10 UTC (permalink / raw)
To: binutils
This series of patches cleans up binutils code that was using the
private libbfd.h header outside of bfd/.
Make BFD_ALIGN available to objcopy. Fix assertions. Don't use
bfd_log2 in ppc32elf.em or bfd_malloc in xtensaelf.em and bucomm.c.
bfd/
* libbfd-in.h (BFD_ALIGN): Move to..
* bfd-in.h: ..here.
* elf32-ppc.h (struct ppc_elf_params): Add pagesize.
* elf32-ppc.c (default_params): Adjust init.
(ppc_elf_link_params): Set pagesize_p2.
* libbfd.h: Regenerate.
* bfd-in2.h: Regenerate.
binutils/
* ar.c: Don't include libbfd.h.
* objcopy.c: Likewise.
* bucomm.c (bfd_get_archive_filename): Use xmalloc rather than
bfd_malloc.
gas/
* config/bfin-parse.y: Don't include libbfd.h.
* config/tc-bfin.c: Likewise.
* config/tc-rl78.c: Likewise.
* config/tc-rx.c: Likewise.
* config/tc-metag.c: Likewise.
(create_dspreg_htabs, create_scond_htab): Use gas_assert not BFD_ASSERT.
* Makefile.am: Update dependencies.
* Makefile.in: Regenerate.
ld/
* ldlang.c: Don't include libbfd.h.
* emultempl/nds32elf.em: Likewise.
* emultempl/ppc64elf.em: Likewise.
* emultempl/ppc32elf.em: Likewise.
(pagesize): Delete.
(params): Update init.
(ppc_after_open_output): Use params.pagesize. Don't call bfd_log2.
(PARSE_AND_LIST_ARGS_CASES): Use params.pagesize.
* emultempl/sh64elf.em: Don't include libbfd.h.
(after_allocation): Use ASSERT, not BFD_ASSERT.
* emultempl/xtensaelf.em: Don't include libbfd.h.
(replace_insn_sec_with_prop_sec): Use xmalloc, not bfd_malloc.
* Makefile.am: Update dependencies.
* Makefile.in: Regenerate.
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index a7532c5..99cafba 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -256,7 +256,7 @@ struct orl /* Output ranlib. */
} u; /* bfd* or file position. */
int namidx; /* Index into string table. */
};
-\f
+
/* Linenumber stuff. */
typedef struct lineno_cache_entry
{
@@ -270,11 +270,19 @@ typedef struct lineno_cache_entry
alent;
\f
/* Object and core file sections. */
+typedef struct bfd_section *sec_ptr;
#define align_power(addr, align) \
(((addr) + ((bfd_vma) 1 << (align)) - 1) & (-((bfd_vma) 1 << (align))))
-typedef struct bfd_section *sec_ptr;
+/* Align an address upward to a boundary, expressed as a number of bytes.
+ E.g. align to an 8-byte boundary with argument of 8. Take care never
+ to wrap around if the address is within boundary-1 of the end of the
+ address space. */
+#define BFD_ALIGN(this, boundary) \
+ ((((bfd_vma) (this) + (boundary) - 1) >= (bfd_vma) (this)) \
+ ? (((bfd_vma) (this) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary)-1)) \
+ : ~ (bfd_vma) 0)
#define bfd_get_section_name(bfd, ptr) ((void) bfd, (ptr)->name)
#define bfd_get_section_vma(bfd, ptr) ((void) bfd, (ptr)->vma)
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 95ce1dc..b1c75a6 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -3365,7 +3365,8 @@ static struct bfd_link_hash_table *
ppc_elf_link_hash_table_create (bfd *abfd)
{
struct ppc_elf_link_hash_table *ret;
- static struct ppc_elf_params default_params = { PLT_OLD, 0, 1, 0, 0, 12, 0 };
+ static struct ppc_elf_params default_params
+ = { PLT_OLD, 0, 1, 0, 0, 12, 0, 0 };
ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
if (ret == NULL)
@@ -3411,6 +3412,7 @@ ppc_elf_link_params (struct bfd_link_info *info, struct ppc_elf_params *params)
if (htab)
htab->params = params;
+ params->pagesize_p2 = bfd_log2 (params->pagesize);
}
/* Create .got and the related sections. */
diff --git a/bfd/elf32-ppc.h b/bfd/elf32-ppc.h
index dd26bd6..5f3a88b 100644
--- a/bfd/elf32-ppc.h
+++ b/bfd/elf32-ppc.h
@@ -48,6 +48,8 @@ struct ppc_elf_params
/* The bfd backend detected a non-PIC reference to a protected symbol
defined in a shared library. */
int pic_fixup;
+
+ bfd_vma pagesize;
};
void ppc_elf_link_params (struct bfd_link_info *, struct ppc_elf_params *);
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index 8644d8d..cde3aad 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -28,15 +28,6 @@
extern "C" {
#endif
-/* Align an address upward to a boundary, expressed as a number of bytes.
- E.g. align to an 8-byte boundary with argument of 8. Take care never
- to wrap around if the address is within boundary-1 of the end of the
- address space. */
-#define BFD_ALIGN(this, boundary) \
- ((((bfd_vma) (this) + (boundary) - 1) >= (bfd_vma) (this)) \
- ? (((bfd_vma) (this) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary)-1)) \
- : ~ (bfd_vma) 0)
-
/* If you want to read and write large blocks, you might want to do it
in quanta of this amount */
#define DEFAULT_BUFFERSIZE 8192
diff --git a/binutils/ar.c b/binutils/ar.c
index 3afa253..1337710 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -29,7 +29,6 @@
#include "progress.h"
#include "getopt.h"
#include "aout/ar.h"
-#include "libbfd.h"
#include "bucomm.h"
#include "arsup.h"
#include "filenames.h"
diff --git a/binutils/bucomm.c b/binutils/bucomm.c
index 8ecd7f2..e719cd3 100644
--- a/binutils/bucomm.c
+++ b/binutils/bucomm.c
@@ -616,14 +616,7 @@ bfd_get_archive_filename (const bfd *abfd)
if (curr)
free (buf);
curr = needed + (needed >> 1);
- buf = (char *) bfd_malloc (curr);
- /* If we can't malloc, fail safe by returning just the file name.
- This function is only used when building error messages. */
- if (!buf)
- {
- curr = 0;
- return bfd_get_filename (abfd);
- }
+ buf = (char *) xmalloc (curr);
}
sprintf (buf, "%s(%s)", bfd_get_filename (abfd->my_archive),
bfd_get_filename (abfd));
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index cf3f983..2e8ff27 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -28,7 +28,6 @@
#include "filenames.h"
#include "fnmatch.h"
#include "elf-bfd.h"
-#include "libbfd.h"
#include "coff/internal.h"
#include "libcoff.h"
diff --git a/gas/Makefile.am b/gas/Makefile.am
index 596e469..7e302fb 100644
--- a/gas/Makefile.am
+++ b/gas/Makefile.am
@@ -484,7 +484,7 @@ bfin-parse.c: $(srcdir)/config/bfin-parse.y
bfin-parse.h: bfin-parse.c
bfin-parse.@OBJEXT@: bfin-parse.c \
$(srcdir)/config/bfin-aux.h $(srcdir)/config/bfin-defs.h \
- $(INCDIR)/elf/common.h $(INCDIR)/elf/bfin.h $(BFDDIR)/libbfd.h
+ $(INCDIR)/elf/common.h $(INCDIR)/elf/bfin.h
bfin-parse.h: ; @true
$(srcdir)/config/bfin-parse.h: ; @true
@@ -507,7 +507,7 @@ rl78-parse.c: $(srcdir)/config/rl78-parse.y
$(SHELL) $(YLWRAP) $(srcdir)/config/rl78-parse.y y.tab.c rl78-parse.c y.tab.h rl78-parse.h -- $(YACCCOMPILE) -d ;
rl78-parse.h: rl78-parse.c
rl78-parse.@OBJEXT@: rl78-parse.c rl78-parse.h $(srcdir)/config/rl78-defs.h \
- $(INCDIR)/elf/common.h $(INCDIR)/elf/rl78.h $(BFDDIR)/libbfd.h
+ $(INCDIR)/elf/common.h $(INCDIR)/elf/rl78.h
rl78-defs.h: ; @true
@@ -515,7 +515,7 @@ rx-parse.c: $(srcdir)/config/rx-parse.y
$(SHELL) $(YLWRAP) $(srcdir)/config/rx-parse.y y.tab.c rx-parse.c y.tab.h rx-parse.h -- $(YACCCOMPILE) -d ;
rx-parse.h: rx-parse.c
rx-parse.@OBJEXT@: rx-parse.c rx-parse.h $(srcdir)/config/rx-defs.h \
- $(INCDIR)/elf/common.h $(INCDIR)/elf/rx.h $(BFDDIR)/libbfd.h
+ $(INCDIR)/elf/common.h $(INCDIR)/elf/rx.h
rx-defs.h: ; @true
$(srcdir)/config/rx-defs.h: ; @true
diff --git a/gas/config/bfin-parse.y b/gas/config/bfin-parse.y
index a2eaa4c..87abd21 100644
--- a/gas/config/bfin-parse.y
+++ b/gas/config/bfin-parse.y
@@ -22,7 +22,6 @@
#include "as.h"
#include "bfin-aux.h" /* Opcode generating auxiliaries. */
-#include "libbfd.h"
#include "elf/common.h"
#include "elf/bfin.h"
diff --git a/gas/config/tc-bfin.c b/gas/config/tc-bfin.c
index 334dce4..1dc88fc 100644
--- a/gas/config/tc-bfin.c
+++ b/gas/config/tc-bfin.c
@@ -26,7 +26,6 @@
#ifdef OBJ_ELF
#include "dwarf2dbg.h"
#endif
-#include "libbfd.h"
#include "elf/common.h"
#include "elf/bfin.h"
diff --git a/gas/config/tc-metag.c b/gas/config/tc-metag.c
index a6c7152..bbc34f7 100644
--- a/gas/config/tc-metag.c
+++ b/gas/config/tc-metag.c
@@ -24,7 +24,6 @@
#include "symcat.h"
#include "safe-ctype.h"
#include "hashtab.h"
-#include "libbfd.h"
#include <stdio.h>
@@ -6416,7 +6415,7 @@ create_dspreg_htabs (void)
/* Make sure there are no hash table collisions, which would
require chaining entries. */
- BFD_ASSERT (*slot == NULL);
+ gas_assert (*slot == NULL);
*slot = reg;
}
@@ -6439,7 +6438,7 @@ create_dspreg_htabs (void)
/* Make sure there are no hash table collisions, which would
require chaining entries. */
- BFD_ASSERT (*slot == NULL);
+ gas_assert (*slot == NULL);
*slot = reg;
}
}
@@ -6486,7 +6485,7 @@ create_scond_htab (void)
scond, INSERT);
/* Make sure there are no hash table collisions, which would
require chaining entries. */
- BFD_ASSERT (*slot == NULL);
+ gas_assert (*slot == NULL);
*slot = scond;
}
}
diff --git a/gas/config/tc-rl78.c b/gas/config/tc-rl78.c
index 8ab35ec..815a10c 100644
--- a/gas/config/tc-rl78.c
+++ b/gas/config/tc-rl78.c
@@ -22,7 +22,6 @@
#include "struc-symbol.h"
#include "safe-ctype.h"
#include "dwarf2dbg.h"
-#include "libbfd.h"
#include "elf/common.h"
#include "elf/rl78.h"
#include "rl78-defs.h"
diff --git a/gas/config/tc-rx.c b/gas/config/tc-rx.c
index a9beec7..bb0f689 100644
--- a/gas/config/tc-rx.c
+++ b/gas/config/tc-rx.c
@@ -22,7 +22,6 @@
#include "struc-symbol.h"
#include "safe-ctype.h"
#include "dwarf2dbg.h"
-#include "libbfd.h"
#include "elf/common.h"
#include "elf/rx.h"
#include "rx-defs.h"
diff --git a/ld/Makefile.am b/ld/Makefile.am
index 0598923..16d95bc 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -1306,7 +1306,7 @@ eelf32xstormy16.c: $(srcdir)/emulparams/elf32xstormy16.sh \
eelf32xtensa.c: $(srcdir)/emulparams/elf32xtensa.sh $(ELF_DEPS) \
$(srcdir)/emultempl/xtensaelf.em $(INCDIR)/xtensa-config.h \
- $(BFDDIR)/elf-bfd.h $(BFDDIR)/libbfd.h $(INCDIR)/elf/xtensa.h \
+ $(BFDDIR)/elf-bfd.h $(INCDIR)/elf/xtensa.h \
$(srcdir)/scripttempl/elfxtensa.sc ${GEN_DEPENDS}
eelf_i386.c: $(srcdir)/emulparams/elf_i386.sh \
@@ -1712,19 +1712,19 @@ eshelf.c: $(srcdir)/emulparams/shelf.sh \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eshelf32.c: $(srcdir)/emulparams/shelf32.sh \
- $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
+ $(INCDIR)/libiberty.h \
$(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eshelf32_linux.c: $(srcdir)/emulparams/shelf32_linux.sh \
$(srcdir)/emulparams/shelf32.sh \
- $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
+ $(INCDIR)/libiberty.h \
$(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eshelf32_nbsd.c: $(srcdir)/emulparams/shelf32_nbsd.sh \
$(srcdir)/emulparams/shelf32.sh \
- $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
+ $(INCDIR)/libiberty.h \
$(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -1758,19 +1758,19 @@ eshlelf.c: $(srcdir)/emulparams/shlelf.sh \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eshlelf32.c: $(srcdir)/emulparams/shlelf32.sh \
- $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h $(srcdir)/emulparams/shelf32.sh \
+ $(INCDIR)/libiberty.h $(srcdir)/emulparams/shelf32.sh \
$(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eshlelf32_linux.c: $(srcdir)/emulparams/shlelf32_linux.sh \
$(srcdir)/emulparams/shelf32_linux.sh $(srcdir)/emulparams/shelf32.sh \
- $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
+ $(INCDIR)/libiberty.h \
$(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eshlelf32_nbsd.c: $(srcdir)/emulparams/shlelf32_nbsd.sh \
$(srcdir)/emulparams/shelf32_nbsd.sh $(srcdir)/emulparams/shelf32.sh \
- $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
+ $(INCDIR)/libiberty.h \
$(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
diff --git a/ld/emultempl/nds32elf.em b/ld/emultempl/nds32elf.em
index 08da695..7c1ddfe 100644
--- a/ld/emultempl/nds32elf.em
+++ b/ld/emultempl/nds32elf.em
@@ -22,7 +22,6 @@
fragment <<EOF
-#include "libbfd.h"
#include "elf-bfd.h"
#include "elf/nds32.h"
#include "bfd_stdint.h"
diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em
index a0255cd..95df30d 100644
--- a/ld/emultempl/ppc32elf.em
+++ b/ld/emultempl/ppc32elf.em
@@ -24,7 +24,6 @@
#
fragment <<EOF
-#include "libbfd.h"
#include "elf32-ppc.h"
#include "ldlex.h"
#include "ldlang.h"
@@ -39,9 +38,7 @@ static int notlsopt = 0;
/* Choose the correct place for .got. */
static int old_got = 0;
-static bfd_vma pagesize = 0;
-
-static struct ppc_elf_params params = { PLT_UNSET, -1, 0, 0, 0, 0, 0 };
+static struct ppc_elf_params params = { PLT_UNSET, -1, 0, 0, 0, 0, 0, 0 };
static void
ppc_after_open_output (void)
@@ -49,9 +46,8 @@ ppc_after_open_output (void)
if (params.emit_stub_syms < 0)
params.emit_stub_syms = (link_info.emitrelocations
|| bfd_link_pic (&link_info));
- if (pagesize == 0)
- pagesize = config.commonpagesize;
- params.pagesize_p2 = bfd_log2 (pagesize);
+ if (params.pagesize == 0)
+ params.pagesize = config.commonpagesize;
ppc_elf_link_params (&link_info, ¶ms);
}
@@ -331,10 +327,10 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
if (optarg != NULL)
{
char *end;
- pagesize = strtoul (optarg, &end, 0);
+ params.pagesize = strtoul (optarg, &end, 0);
if (*end
- || (pagesize < 4096 && pagesize != 0)
- || pagesize != (pagesize & -pagesize))
+ || (params.pagesize < 4096 && params.pagesize != 0)
+ || params.pagesize != (params.pagesize & -params.pagesize))
einfo (_("%P%F: invalid pagesize `%s'\''\n"), optarg);
}
break;
diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em
index d7c0686..eaa692d 100644
--- a/ld/emultempl/ppc64elf.em
+++ b/ld/emultempl/ppc64elf.em
@@ -25,7 +25,6 @@
fragment <<EOF
#include "ldctor.h"
-#include "libbfd.h"
#include "elf-bfd.h"
#include "elf64-ppc.h"
#include "ldlex.h"
diff --git a/ld/emultempl/sh64elf.em b/ld/emultempl/sh64elf.em
index c538f39..0d42510 100644
--- a/ld/emultempl/sh64elf.em
+++ b/ld/emultempl/sh64elf.em
@@ -29,7 +29,6 @@ LDEMUL_BEFORE_ALLOCATION=sh64_elf_${EMULATION_NAME}_before_allocation
fragment <<EOF
#include "libiberty.h"
-#include "libbfd.h"
#include "elf-bfd.h"
#include "elf/sh.h"
#include "elf32-sh64.h"
@@ -332,7 +331,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
{
oflags_isa = SHF_SH5_ISA32_MIXED;
- BFD_ASSERT (sh64_elf_section_data (osec)->sh64_info);
+ ASSERT (sh64_elf_section_data (osec)->sh64_info);
sh64_elf_section_data (osec)->sh64_info->contents_flags
= SHF_SH5_ISA32_MIXED;
@@ -382,7 +381,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
if (cranges->contents != NULL)
free (cranges->contents);
- BFD_ASSERT (sh64_elf_section_data (cranges)->sh64_info != NULL);
+ ASSERT (sh64_elf_section_data (cranges)->sh64_info != NULL);
/* Make sure we have .cranges in memory even if there were only
assembler-generated .cranges. */
diff --git a/ld/emultempl/xtensaelf.em b/ld/emultempl/xtensaelf.em
index 01ac7a9..4a87ac4 100644
--- a/ld/emultempl/xtensaelf.em
+++ b/ld/emultempl/xtensaelf.em
@@ -26,7 +26,6 @@ fragment <<EOF
#include <xtensa-config.h>
#include "../bfd/elf-bfd.h"
-#include "../bfd/libbfd.h"
#include "elf/xtensa.h"
#include "bfd.h"
@@ -116,12 +115,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
if (insn_sec->size != 0)
{
- insn_contents = (bfd_byte *) bfd_malloc (insn_sec->size);
- if (insn_contents == NULL)
- {
- *error_message = _("out of memory");
- goto cleanup;
- }
+ insn_contents = (bfd_byte *) xmalloc (insn_sec->size);
if (! bfd_get_section_contents (abfd, insn_sec, insn_contents,
(file_ptr) 0, insn_sec->size))
{
diff --git a/ld/ldlang.c b/ld/ldlang.c
index b841408..82d5582 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -39,7 +39,6 @@
#include "fnmatch.h"
#include "demangle.h"
#include "hashtab.h"
-#include "libbfd.h"
#include "elf-bfd.h"
#ifdef ENABLE_PLUGINS
#include "plugin.h"
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Don't include libbfd.h outside of bfd, part 2
2016-07-16 13:10 Don't include libbfd.h outside of bfd, part 1 Alan Modra
@ 2016-07-16 13:12 ` Alan Modra
2016-07-16 13:13 ` Don't include libbfd.h outside of bfd, part 3 Alan Modra
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Alan Modra @ 2016-07-16 13:12 UTC (permalink / raw)
To: binutils
Make bfd_default_set_arch_mach available to a bunch of gas backend
files. Some gdb files also want to use bfd_default_set_arch_mach, so
this might allow them to be weaned off libbfd.h too.
bfd/
* archures.c (bfd_default_set_arch_mach): Make available in bfd.h.
* libbfd.h: Regenerate.
* bfd-in2.h: Regenerate.
gas/
* config/tc-epiphany.c: Don't include libbfd.h.
* config/tc-frv.c: Likewise.
* config/tc-ip2k.c: Likewise.
* config/tc-iq2000.c: Likewise.
* config/tc-m32c.c: Likewise.
* config/tc-mep.c: Likewise.
* config/tc-mt.c: Likewise.
* config/tc-nios2.c: Likewise.
diff --git a/bfd/archures.c b/bfd/archures.c
index 96c9109..af70b18 100644
--- a/bfd/archures.c
+++ b/bfd/archures.c
@@ -934,7 +934,7 @@ bfd_set_arch_info (bfd *abfd, const bfd_arch_info_type *arg)
}
/*
-INTERNAL_FUNCTION
+FUNCTION
bfd_default_set_arch_mach
SYNOPSIS
diff --git a/gas/config/tc-epiphany.c b/gas/config/tc-epiphany.c
index f35198e..d14c3a0 100644
--- a/gas/config/tc-epiphany.c
+++ b/gas/config/tc-epiphany.c
@@ -28,7 +28,6 @@
#include "elf/common.h"
#include "elf/epiphany.h"
#include "dwarf2dbg.h"
-#include "libbfd.h"
/* Structure to hold all of the different components describing
an individual instruction. */
diff --git a/gas/config/tc-frv.c b/gas/config/tc-frv.c
index 8912f44..f49096d 100644
--- a/gas/config/tc-frv.c
+++ b/gas/config/tc-frv.c
@@ -24,7 +24,6 @@
#include "opcodes/frv-desc.h"
#include "opcodes/frv-opc.h"
#include "cgen.h"
-#include "libbfd.h"
#include "elf/common.h"
#include "elf/frv.h"
#include "dwarf2dbg.h"
diff --git a/gas/config/tc-ip2k.c b/gas/config/tc-ip2k.c
index 642dfea..c1e50c1 100644
--- a/gas/config/tc-ip2k.c
+++ b/gas/config/tc-ip2k.c
@@ -26,7 +26,6 @@
#include "cgen.h"
#include "elf/common.h"
#include "elf/ip2k.h"
-#include "libbfd.h"
/* Structure to hold all of the different components describing
an individual instruction. */
diff --git a/gas/config/tc-iq2000.c b/gas/config/tc-iq2000.c
index f150e19..3bb8726 100644
--- a/gas/config/tc-iq2000.c
+++ b/gas/config/tc-iq2000.c
@@ -27,7 +27,6 @@
#include "cgen.h"
#include "elf/common.h"
#include "elf/iq2000.h"
-#include "libbfd.h"
#include "sb.h"
#include "macro.h"
diff --git a/gas/config/tc-m32c.c b/gas/config/tc-m32c.c
index b28797b..ed1d1c8 100644
--- a/gas/config/tc-m32c.c
+++ b/gas/config/tc-m32c.c
@@ -27,7 +27,6 @@
#include "cgen.h"
#include "elf/common.h"
#include "elf/m32c.h"
-#include "libbfd.h"
#include "safe-ctype.h"
/* Structure to hold all of the different components
diff --git a/gas/config/tc-mep.c b/gas/config/tc-mep.c
index 6128b6e..f018f74 100644
--- a/gas/config/tc-mep.c
+++ b/gas/config/tc-mep.c
@@ -28,7 +28,6 @@
#include "cgen.h"
#include "elf/common.h"
#include "elf/mep.h"
-#include "libbfd.h"
#include "xregex.h"
/* Structure to hold all of the different components describing
diff --git a/gas/config/tc-mt.c b/gas/config/tc-mt.c
index e0bca88..bbcd87e 100644
--- a/gas/config/tc-mt.c
+++ b/gas/config/tc-mt.c
@@ -27,7 +27,6 @@
#include "cgen.h"
#include "elf/common.h"
#include "elf/mt.h"
-#include "libbfd.h"
/* Structure to hold all of the different components
describing an individual instruction. */
diff --git a/gas/config/tc-nios2.c b/gas/config/tc-nios2.c
index 0ddc501..0a1286a 100644
--- a/gas/config/tc-nios2.c
+++ b/gas/config/tc-nios2.c
@@ -25,7 +25,6 @@
#include "elf/nios2.h"
#include "tc-nios2.h"
#include "bfd.h"
-#include "libbfd.h"
#include "dwarf2dbg.h"
#include "subsegs.h"
#include "safe-ctype.h"
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Don't include libbfd.h outside of bfd, part 3
2016-07-16 13:10 Don't include libbfd.h outside of bfd, part 1 Alan Modra
2016-07-16 13:12 ` Don't include libbfd.h outside of bfd, part 2 Alan Modra
@ 2016-07-16 13:13 ` Alan Modra
2016-07-16 13:14 ` Don't include libbfd.h outside of bfd, part 4 Alan Modra
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Alan Modra @ 2016-07-16 13:13 UTC (permalink / raw)
To: binutils
Fix od-macho.c to use a leb128 function from binutils/dwarf.c rather
than one from bfd/libbfd.c.
binutils/
* elfcomm.h (HOST_WIDEST_INT): Move to..
* sysdep.h: ..here.
* od-macho.c: Don't include libbfd.h. Do include dwarf.h
(dump_dyld_info_rebase): Use read_leb128 rather than
read_unsigned_leb128.
(dump_dyld_info_bind, dump_dyld_info_export_1): Likewise.
(dump_segment_split_info): Likewise.
(dump_dyld_info): Rename vars to avoid shadowing dwarf.h enums.
(dump_load_command): Likewise.
diff --git a/binutils/elfcomm.h b/binutils/elfcomm.h
index 6ffd0c1..f9c43d1 100644
--- a/binutils/elfcomm.h
+++ b/binutils/elfcomm.h
@@ -29,13 +29,6 @@
void error (const char *, ...) ATTRIBUTE_PRINTF_1;
void warn (const char *, ...) ATTRIBUTE_PRINTF_1;
-#if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
-/* We can't use any bfd types here since readelf may define BFD64 and
- objdump may not. */
-#define HOST_WIDEST_INT long long
-#else
-#define HOST_WIDEST_INT long
-#endif
typedef unsigned HOST_WIDEST_INT elf_vma;
extern void (*byte_put) (unsigned char *, elf_vma, int);
diff --git a/binutils/sysdep.h b/binutils/sysdep.h
index b4d8049..f28d9dc 100644
--- a/binutils/sysdep.h
+++ b/binutils/sysdep.h
@@ -187,4 +187,12 @@ size_t strnlen (const char *, size_t);
# endif
#endif
+#if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
+/* We can't use any bfd types here since readelf may define BFD64 and
+ objdump may not. */
+#define HOST_WIDEST_INT long long
+#else
+#define HOST_WIDEST_INT long
+#endif
+
#endif /* _BIN_SYSDEP_H */
diff --git a/binutils/od-macho.c b/binutils/od-macho.c
index 0c86cad..d1a4e0f 100644
--- a/binutils/od-macho.c
+++ b/binutils/od-macho.c
@@ -26,8 +26,8 @@
#include "bfd.h"
#include "objdump.h"
#include "bucomm.h"
+#include "dwarf.h"
#include "bfdlink.h"
-#include "libbfd.h"
#include "mach-o.h"
#include "mach-o/external.h"
#include "mach-o/codesign.h"
@@ -688,13 +688,13 @@ dump_dyld_info_rebase (bfd *abfd, unsigned char *buf, unsigned int len,
bfd_mach_o_get_name (bfd_mach_o_dyld_rebase_type_name, imm));
break;
case BFD_MACH_O_REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("set segment: %u and offset: 0x%08x\n",
imm, (unsigned) leb);
i += leblen;
break;
case BFD_MACH_O_REBASE_OPCODE_ADD_ADDR_ULEB:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("add addr uleb: 0x%08x\n", (unsigned) leb);
i += leblen;
break;
@@ -705,20 +705,20 @@ dump_dyld_info_rebase (bfd *abfd, unsigned char *buf, unsigned int len,
printf ("rebase imm times: %u\n", imm);
break;
case BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ULEB_TIMES:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("rebase uleb times: %u\n", (unsigned) leb);
i += leblen;
break;
case BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("rebase add addr uleb: %u\n", (unsigned) leb);
i += leblen;
break;
case BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("rebase uleb times (%u)", (unsigned) leb);
i += leblen;
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf (" skipping uleb (%u)\n", (unsigned) leb);
i += leblen;
break;
@@ -755,7 +755,7 @@ dump_dyld_info_bind (bfd *abfd, unsigned char *buf, unsigned int len,
printf ("set dylib ordinal imm: %u\n", imm);
break;
case BFD_MACH_O_BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("set dylib ordinal uleb: %u\n", imm);
i += leblen;
break;
@@ -778,19 +778,19 @@ dump_dyld_info_bind (bfd *abfd, unsigned char *buf, unsigned int len,
case BFD_MACH_O_BIND_OPCODE_SET_ADDEND_SLEB:
{
bfd_signed_vma svma;
- svma = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ svma = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("set addend sleb: 0x%08x\n", (unsigned) svma);
i += leblen;
}
break;
case BFD_MACH_O_BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("set segment: %u and offset: 0x%08x\n",
imm, (unsigned) leb);
i += leblen;
break;
case BFD_MACH_O_BIND_OPCODE_ADD_ADDR_ULEB:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("add addr uleb: 0x%08x\n", (unsigned) leb);
i += leblen;
break;
@@ -798,7 +798,7 @@ dump_dyld_info_bind (bfd *abfd, unsigned char *buf, unsigned int len,
printf ("do bind\n");
break;
case BFD_MACH_O_BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("do bind add addr uleb: 0x%08x\n", (unsigned) leb);
i += leblen;
break;
@@ -806,10 +806,10 @@ dump_dyld_info_bind (bfd *abfd, unsigned char *buf, unsigned int len,
printf ("do bind add addr imm scaled: %u\n", imm * ptrsize);
break;
case BFD_MACH_O_BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB:
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("do bind uleb times (%u)", (unsigned) leb);
i += leblen;
- leb = read_unsigned_leb128 (abfd, buf + i, &leblen);
+ leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf (" skipping uleb (%u)\n", (unsigned) leb);
i += leblen;
break;
@@ -837,7 +837,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
unsigned int child_count;
unsigned int i;
- size = read_unsigned_leb128 (abfd, buf + off, &leblen);
+ size = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen;
if (size != 0)
@@ -845,7 +845,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
bfd_vma flags;
struct export_info_data *d;
- flags = read_unsigned_leb128 (abfd, buf + off, &leblen);
+ flags = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen;
fputs (" ", stdout);
@@ -868,7 +868,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
{
bfd_vma lib;
- lib = read_unsigned_leb128 (abfd, buf + off, &leblen);
+ lib = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen;
fputs (" [reexport] ", stdout);
@@ -890,12 +890,12 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
bfd_vma offset;
bfd_vma resolv = 0;
- offset = read_unsigned_leb128 (abfd, buf + off, &leblen);
+ offset = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen;
if (flags & BFD_MACH_O_EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER)
{
- resolv = read_unsigned_leb128 (abfd, buf + off, &leblen);
+ resolv = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen;
}
@@ -908,7 +908,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
}
}
- child_count = read_unsigned_leb128 (abfd, buf + off, &leblen);
+ child_count = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen;
for (i = 0; i < child_count; i++)
@@ -922,7 +922,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
off += strlen ((const char *)buf + off) + 1;
- sub_off = read_unsigned_leb128 (abfd, buf + off, &leblen);
+ sub_off = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen;
dump_dyld_info_export_1 (abfd, buf, len, sub_off, &sub_data, base);
@@ -946,49 +946,49 @@ static void
dump_dyld_info (bfd *abfd, bfd_mach_o_load_command *cmd,
bfd_boolean verbose)
{
- bfd_mach_o_dyld_info_command *info = &cmd->command.dyld_info;
+ bfd_mach_o_dyld_info_command *dinfo = &cmd->command.dyld_info;
printf (" rebase: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
- info->rebase_off, info->rebase_size,
- info->rebase_off + info->rebase_size);
+ dinfo->rebase_off, dinfo->rebase_size,
+ dinfo->rebase_off + dinfo->rebase_size);
printf (" bind: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
- info->bind_off, info->bind_size,
- info->bind_off + info->bind_size);
+ dinfo->bind_off, dinfo->bind_size,
+ dinfo->bind_off + dinfo->bind_size);
printf (" weak bind: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
- info->weak_bind_off, info->weak_bind_size,
- info->weak_bind_off + info->weak_bind_size);
+ dinfo->weak_bind_off, dinfo->weak_bind_size,
+ dinfo->weak_bind_off + dinfo->weak_bind_size);
printf (" lazy bind: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
- info->lazy_bind_off, info->lazy_bind_size,
- info->lazy_bind_off + info->lazy_bind_size);
+ dinfo->lazy_bind_off, dinfo->lazy_bind_size,
+ dinfo->lazy_bind_off + dinfo->lazy_bind_size);
printf (" export: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
- info->export_off, info->export_size,
- info->export_off + info->export_size);
+ dinfo->export_off, dinfo->export_size,
+ dinfo->export_off + dinfo->export_size);
if (!verbose)
return;
printf (" rebase:\n");
- if (!load_and_dump (abfd, info->rebase_off, info->rebase_size,
+ if (!load_and_dump (abfd, dinfo->rebase_off, dinfo->rebase_size,
dump_dyld_info_rebase))
non_fatal (_("cannot read rebase dyld info"));
printf (" bind:\n");
- if (!load_and_dump (abfd, info->bind_off, info->bind_size,
+ if (!load_and_dump (abfd, dinfo->bind_off, dinfo->bind_size,
dump_dyld_info_bind))
non_fatal (_("cannot read bind dyld info"));
printf (" weak bind:\n");
- if (!load_and_dump (abfd, info->weak_bind_off, info->weak_bind_size,
+ if (!load_and_dump (abfd, dinfo->weak_bind_off, dinfo->weak_bind_size,
dump_dyld_info_bind))
non_fatal (_("cannot read weak bind dyld info"));
printf (" lazy bind:\n");
- if (!load_and_dump (abfd, info->lazy_bind_off, info->lazy_bind_size,
+ if (!load_and_dump (abfd, dinfo->lazy_bind_off, dinfo->lazy_bind_size,
dump_dyld_info_bind))
non_fatal (_("cannot read lazy bind dyld info"));
printf (" exported symbols:\n");
- if (!load_and_dump (abfd, info->export_off, info->export_size,
+ if (!load_and_dump (abfd, dinfo->export_off, dinfo->export_size,
dump_dyld_info_export))
non_fatal (_("cannot read export symbols dyld info"));
}
@@ -1287,7 +1287,7 @@ dump_segment_split_info (bfd *abfd, bfd_mach_o_linkedit_command *cmd)
}
for (p = buf + 1; *p != 0; p += len)
{
- addr += read_unsigned_leb128 (abfd, p, &len);
+ addr += read_leb128 (p, &len, 0, buf + cmd->datasize);
fputs (" ", stdout);
bfd_printf_vma (abfd, addr);
putchar ('\n');
@@ -1556,8 +1556,8 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
case BFD_MACH_O_LC_SUB_CLIENT:
case BFD_MACH_O_LC_RPATH:
{
- bfd_mach_o_str_command *str = &cmd->command.str;
- printf (" %s\n", str->str);
+ bfd_mach_o_str_command *strc = &cmd->command.str;
+ printf (" %s\n", strc->str);
break;
}
case BFD_MACH_O_LC_THREAD:
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Don't include libbfd.h outside of bfd, part 5
2016-07-16 13:10 Don't include libbfd.h outside of bfd, part 1 Alan Modra
` (2 preceding siblings ...)
2016-07-16 13:14 ` Don't include libbfd.h outside of bfd, part 4 Alan Modra
@ 2016-07-16 13:14 ` Alan Modra
2016-07-16 13:16 ` Don't include libbfd.h outside of bfd, part 6 Alan Modra
4 siblings, 0 replies; 6+ messages in thread
From: Alan Modra @ 2016-07-16 13:14 UTC (permalink / raw)
To: binutils
A rewrite of the code in bucomm.c supporting objdump -i, to use
bfd_iterate_over_targets rather than accessing bfd_target_vector
directly. Calculates widest arch string rather than using an
out of date constant. Stashes info from the first display of valid
target/arch combinations for use in second tabular display.
binutils/
* bucomm.c: Don't include libbfd.h.
(endian_string, display_target_list): Delete forward declaration.
(display_info_table, display_target_tables): Likewise.
(LONGEST_ARCH): Delete.
(struct display_target): New.
(do_display_target): New function.
(display_target_list, display_info): Rewrite functions.
(display_info_table): Delete.
(do_info_size, do_info_header, do_info_row): New functions.
diff --git a/binutils/bucomm.c b/binutils/bucomm.c
index e719cd3..22bf24a 100644
--- a/binutils/bucomm.c
+++ b/binutils/bucomm.c
@@ -25,7 +25,6 @@
#include "bfd.h"
#include "libiberty.h"
#include "filenames.h"
-#include "libbfd.h"
#include <time.h> /* ctime, maybe time_t */
#include <assert.h>
@@ -36,11 +35,6 @@
typedef long time_t;
#endif
#endif
-
-static const char * endian_string (enum bfd_endian);
-static int display_target_list (void);
-static int display_info_table (int, int);
-static int display_target_tables (void);
\f
/* Error reporting. */
@@ -216,9 +210,6 @@ list_supported_architectures (const char *name, FILE *f)
free (arches);
}
\f
-/* The length of the longest architecture name + 1. */
-#define LONGEST_ARCH sizeof ("powerpc:common")
-
static const char *
endian_string (enum bfd_endian endian)
{
@@ -230,184 +221,205 @@ endian_string (enum bfd_endian endian)
}
}
+/* Data passed to do_display_target and other target iterators. */
+
+struct display_target {
+ /* Temp file. */
+ char *filename;
+ /* Return status. */
+ int error;
+ /* Number of targets. */
+ int count;
+ /* Size of info in bytes. */
+ size_t alloc;
+ /* Per-target info. */
+ struct {
+ /* Target name. */
+ const char *name;
+ /* Non-zero if target/arch combination supported. */
+ unsigned char arch[bfd_arch_last - bfd_arch_obscure - 1];
+ } *info;
+};
+
/* List the targets that BFD is configured to support, each followed
- by its endianness and the architectures it supports. */
+ by its endianness and the architectures it supports. Also build
+ info about target/archs. */
static int
-display_target_list (void)
+do_display_target (const bfd_target *targ, void *data)
{
- char *dummy_name;
- int t;
- int ret = 1;
+ struct display_target *param = (struct display_target *) data;
+ bfd *abfd;
+ size_t amt;
- dummy_name = make_temp_file (NULL);
- for (t = 0; bfd_target_vector[t]; t++)
+ param->count += 1;
+ amt = param->count * sizeof (*param->info);
+ if (param->alloc < amt)
{
- const bfd_target *p = bfd_target_vector[t];
- bfd *abfd = bfd_openw (dummy_name, p->name);
- int a;
-
- printf (_("%s\n (header %s, data %s)\n"), p->name,
- endian_string (p->header_byteorder),
- endian_string (p->byteorder));
+ size_t size = ((param->count < 64 ? 64 : param->count)
+ * sizeof (*param->info) * 2);
+ param->info = xrealloc (param->info, size);
+ memset ((char *) param->info + param->alloc, 0, size - param->alloc);
+ param->alloc = size;
+ }
+ param->info[param->count - 1].name = targ->name;
- if (abfd == NULL)
- {
- bfd_nonfatal (dummy_name);
- ret = 0;
- continue;
- }
+ printf (_("%s\n (header %s, data %s)\n"), targ->name,
+ endian_string (targ->header_byteorder),
+ endian_string (targ->byteorder));
- if (! bfd_set_format (abfd, bfd_object))
+ abfd = bfd_openw (param->filename, targ->name);
+ if (abfd == NULL)
+ {
+ bfd_nonfatal (param->filename);
+ param->error = 1;
+ }
+ else if (!bfd_set_format (abfd, bfd_object))
+ {
+ if (bfd_get_error () != bfd_error_invalid_operation)
{
- if (bfd_get_error () != bfd_error_invalid_operation)
- {
- bfd_nonfatal (p->name);
- ret = 0;
- }
- bfd_close_all_done (abfd);
- continue;
+ bfd_nonfatal (targ->name);
+ param->error = 1;
}
+ }
+ else
+ {
+ enum bfd_architecture a;
for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
- if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
- printf (" %s\n",
- bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
- bfd_close_all_done (abfd);
+ if (bfd_set_arch_mach (abfd, a, 0))
+ {
+ printf (" %s\n", bfd_printable_arch_mach (a, 0));
+ param->info[param->count - 1].arch[a - bfd_arch_obscure - 1] = 1;
+ }
}
- unlink (dummy_name);
- free (dummy_name);
+ if (abfd != NULL)
+ bfd_close_all_done (abfd);
- return ret;
+ return param->error;
+}
+
+static void
+display_target_list (struct display_target *arg)
+{
+ arg->filename = make_temp_file (NULL);
+ arg->error = 0;
+ arg->count = 0;
+ arg->alloc = 0;
+ arg->info = NULL;
+
+ bfd_iterate_over_targets (do_display_target, arg);
+
+ unlink (arg->filename);
+ free (arg->filename);
}
-/* Print a table showing which architectures are supported for entries
- FIRST through LAST-1 of bfd_target_vector (targets across,
- architectures down). */
+/* Calculate how many targets we can print across the page. */
static int
-display_info_table (int first, int last)
+do_info_size (int targ, int width, const struct display_target *arg)
{
- int t;
- int ret = 1;
- char *dummy_name;
- int a;
-
- /* Print heading of target names. */
- printf ("\n%*s", (int) LONGEST_ARCH, " ");
- for (t = first; t < last && bfd_target_vector[t]; t++)
- printf ("%s ", bfd_target_vector[t]->name);
- putchar ('\n');
-
- dummy_name = make_temp_file (NULL);
- for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
- if (strcmp (bfd_printable_arch_mach ((enum bfd_architecture) a, 0),
- "UNKNOWN!") != 0)
- {
- printf ("%*s ", (int) LONGEST_ARCH - 1,
- bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
- for (t = first; t < last && bfd_target_vector[t]; t++)
- {
- const bfd_target *p = bfd_target_vector[t];
- bfd_boolean ok = TRUE;
- bfd *abfd = bfd_openw (dummy_name, p->name);
-
- if (abfd == NULL)
- {
- bfd_nonfatal (p->name);
- ret = 0;
- ok = FALSE;
- }
-
- if (ok)
- {
- if (! bfd_set_format (abfd, bfd_object))
- {
- if (bfd_get_error () != bfd_error_invalid_operation)
- {
- bfd_nonfatal (p->name);
- ret = 0;
- }
- ok = FALSE;
- }
- }
-
- if (ok)
- {
- if (! bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
- ok = FALSE;
- }
-
- if (ok)
- printf ("%s ", p->name);
- else
- {
- int l = strlen (p->name);
- while (l--)
- putchar ('-');
- putchar (' ');
- }
- if (abfd != NULL)
- bfd_close_all_done (abfd);
- }
- putchar ('\n');
- }
- unlink (dummy_name);
- free (dummy_name);
+ while (targ < arg->count)
+ {
+ width -= strlen (arg->info[targ].name) + 1;
+ if (width < 0)
+ return targ;
+ ++targ;
+ }
+ return targ;
+}
- return ret;
+/* Print header of target names. */
+
+static void
+do_info_header (int targ, int stop_targ, const struct display_target *arg)
+{
+ while (targ != stop_targ)
+ printf ("%s ", arg->info[targ++].name);
+}
+
+/* Print a table row. */
+
+static void
+do_info_row (int targ, int stop_targ, enum bfd_architecture a,
+ const struct display_target *arg)
+{
+ while (targ != stop_targ)
+ {
+ if (arg->info[targ].arch[a - bfd_arch_obscure - 1])
+ fputs (arg->info[targ].name, stdout);
+ else
+ {
+ int l = strlen (arg->info[targ].name);
+ while (l--)
+ putchar ('-');
+ }
+ ++targ;
+ if (targ != stop_targ)
+ putchar (' ');
+ }
}
/* Print tables of all the target-architecture combinations that
BFD has been configured to support. */
-static int
-display_target_tables (void)
+static void
+display_target_tables (const struct display_target *arg)
{
- int t;
- int columns;
- int ret = 1;
- char *colum;
-
- columns = 0;
- colum = getenv ("COLUMNS");
- if (colum != NULL)
- columns = atoi (colum);
- if (columns == 0)
- columns = 80;
-
- t = 0;
- while (bfd_target_vector[t] != NULL)
+ const char *columns;
+ int width, start_targ, stop_targ;
+ enum bfd_architecture arch;
+ int longest_arch = 0;
+
+ for (arch = bfd_arch_obscure + 1; arch < bfd_arch_last; arch++)
{
- int oldt = t, wid;
+ const char *s = bfd_printable_arch_mach (arch, 0);
+ int len = strlen (s);
+ if (len > longest_arch)
+ longest_arch = len;
+ }
- wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
- ++t;
- while (wid < columns && bfd_target_vector[t] != NULL)
- {
- int newwid;
+ width = 0;
+ columns = getenv ("COLUMNS");
+ if (columns != NULL)
+ width = atoi (columns);
+ if (width == 0)
+ width = 80;
- newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
- if (newwid >= columns)
- break;
- wid = newwid;
- ++t;
+ for (start_targ = 0; start_targ < arg->count; start_targ = stop_targ)
+ {
+ stop_targ = do_info_size (start_targ, width - longest_arch - 1, arg);
+
+ printf ("\n%*s", longest_arch + 1, " ");
+ do_info_header (start_targ, stop_targ, arg);
+ putchar ('\n');
+
+ for (arch = bfd_arch_obscure + 1; arch < bfd_arch_last; arch++)
+ {
+ if (strcmp (bfd_printable_arch_mach (arch, 0), "UNKNOWN!") != 0)
+ {
+ printf ("%*s ", longest_arch,
+ bfd_printable_arch_mach (arch, 0));
+
+ do_info_row (start_targ, stop_targ, arch, arg);
+ putchar ('\n');
+ }
}
- if (! display_info_table (oldt, t))
- ret = 0;
}
-
- return ret;
}
int
display_info (void)
{
+ struct display_target arg;
+
printf (_("BFD header file version %s\n"), BFD_VERSION_STRING);
- if (! display_target_list () || ! display_target_tables ())
- return 1;
- else
- return 0;
+
+ display_target_list (&arg);
+ if (!arg.error)
+ display_target_tables (&arg);
+
+ return arg.error;
}
\f
/* Display the archive header for an element as if it were an ls -l listing:
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Don't include libbfd.h outside of bfd, part 4
2016-07-16 13:10 Don't include libbfd.h outside of bfd, part 1 Alan Modra
2016-07-16 13:12 ` Don't include libbfd.h outside of bfd, part 2 Alan Modra
2016-07-16 13:13 ` Don't include libbfd.h outside of bfd, part 3 Alan Modra
@ 2016-07-16 13:14 ` Alan Modra
2016-07-16 13:14 ` Don't include libbfd.h outside of bfd, part 5 Alan Modra
2016-07-16 13:16 ` Don't include libbfd.h outside of bfd, part 6 Alan Modra
4 siblings, 0 replies; 6+ messages in thread
From: Alan Modra @ 2016-07-16 13:14 UTC (permalink / raw)
To: binutils
Not much to see here, just renaming a function.
bfd/
* targets.c (bfd_seach_for_target): Rename to..
(bfd_iterate_over_targets): ..this. Rewrite doc.
* bfd-in2.h: Regenerate.
ld/
* ldlang.c (open_output): Replace bfd_search_for_target with
bfd_iterate_over_targets. Localize vars.
diff --git a/bfd/targets.c b/bfd/targets.c
index a9edd4c..19d442a 100644
--- a/bfd/targets.c
+++ b/bfd/targets.c
@@ -1815,29 +1815,28 @@ bfd_target_list (void)
/*
FUNCTION
- bfd_seach_for_target
+ bfd_iterate_over_targets
SYNOPSIS
- const bfd_target *bfd_search_for_target
- (int (*search_func) (const bfd_target *, void *),
- void *);
+ const bfd_target *bfd_iterate_over_targets
+ (int (*func) (const bfd_target *, void *),
+ void *data);
DESCRIPTION
- Return a pointer to the first transfer vector in the list of
- transfer vectors maintained by BFD that produces a non-zero
- result when passed to the function @var{search_func}. The
- parameter @var{data} is passed, unexamined, to the search
- function.
+ Call @var{func} for each target in the list of BFD target
+ vectors, passing @var{data} to @var{func}. Stop iterating if
+ @var{func} returns a non-zero result, and return that target
+ vector. Return NULL if @var{func} always returns zero.
*/
const bfd_target *
-bfd_search_for_target (int (*search_func) (const bfd_target *, void *),
- void *data)
+bfd_iterate_over_targets (int (*func) (const bfd_target *, void *),
+ void *data)
{
- const bfd_target * const *target;
+ const bfd_target *const *target;
- for (target = bfd_target_vector; *target != NULL; target ++)
- if (search_func (*target, data))
+ for (target = bfd_target_vector; *target != NULL; ++target)
+ if (func (*target, data))
return *target;
return NULL;
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 82d5582..aee8720 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -3113,15 +3113,15 @@ open_output (const char *name)
line? */
if (command_line.endian != ENDIAN_UNSET)
{
- const bfd_target *target;
- enum bfd_endian desired_endian;
-
/* Get the chosen target. */
- target = bfd_search_for_target (get_target, (void *) output_target);
+ const bfd_target *target
+ = bfd_iterate_over_targets (get_target, (void *) output_target);
/* If the target is not supported, we cannot do anything. */
if (target != NULL)
{
+ enum bfd_endian desired_endian;
+
if (command_line.endian == ENDIAN_BIG)
desired_endian = BFD_ENDIAN_BIG;
else
@@ -3143,8 +3143,8 @@ open_output (const char *name)
/* Try to find a target as similar as possible to
the default target, but which has the desired
endian characteristic. */
- bfd_search_for_target (closest_target_match,
- (void *) target);
+ bfd_iterate_over_targets (closest_target_match,
+ (void *) target);
/* Oh dear - we could not find any targets that
satisfy our requirements. */
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Don't include libbfd.h outside of bfd, part 6
2016-07-16 13:10 Don't include libbfd.h outside of bfd, part 1 Alan Modra
` (3 preceding siblings ...)
2016-07-16 13:14 ` Don't include libbfd.h outside of bfd, part 5 Alan Modra
@ 2016-07-16 13:16 ` Alan Modra
4 siblings, 0 replies; 6+ messages in thread
From: Alan Modra @ 2016-07-16 13:16 UTC (permalink / raw)
To: binutils
Some messing with plugin code in order to not need arelt_size in
ld code. File descriptor handling in ld/plugin.c is tidied too,
simply duping the open fd rather than opening the file again.
bfd/
* elflink.c: Include plugin-api.h.
* plugin.c (bfd_plugin_open_input): New function, extracted from..
(try_claim): ..here.
* plugin.h: Don't include bfd.h.
(bfd_plugin_open_input): Declare.
binutils/
* ar.c: Include plugin-api.h.
* nm.c: Likewise.
ld/
* plugin.c: Don't include libbfd.h. Include plugin-api.h
before bfd/plugin.h.
(plugin_object_p): Use bfd_plugin_open_input.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index b2a814f..a994b83 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -29,6 +29,7 @@
#include "libiberty.h"
#include "objalloc.h"
#if BFD_SUPPORTS_PLUGINS
+#include "plugin-api.h"
#include "plugin.h"
#endif
diff --git a/bfd/plugin.c b/bfd/plugin.c
index c66d95e..3931d27 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -158,49 +158,50 @@ bfd_plugin_set_program_name (const char *program_name)
plugin_program_name = program_name;
}
-static int
-try_claim (bfd *abfd)
+int
+bfd_plugin_open_input (bfd *ibfd, struct ld_plugin_input_file *file)
{
- int claimed = 0;
- struct ld_plugin_input_file file;
bfd *iobfd;
- file.name = abfd->filename;
-
- if (abfd->my_archive && !bfd_is_thin_archive (abfd->my_archive))
- {
- iobfd = abfd->my_archive;
- file.offset = abfd->origin;
- file.filesize = arelt_size (abfd);
- }
- else
- {
- iobfd = abfd;
- file.offset = 0;
- file.filesize = 0;
- }
+ iobfd = ibfd;
+ if (ibfd->my_archive && !bfd_is_thin_archive (ibfd->my_archive))
+ iobfd = ibfd->my_archive;
+ file->name = iobfd->filename;
if (!iobfd->iostream && !bfd_open_file (iobfd))
return 0;
- file.fd = fileno ((FILE *) iobfd->iostream);
+ file->fd = fileno ((FILE *) iobfd->iostream);
- if (!abfd->my_archive || bfd_is_thin_archive (abfd->my_archive))
+ if (iobfd == ibfd)
{
struct stat stat_buf;
- if (fstat (file.fd, &stat_buf))
+ if (fstat (file->fd, &stat_buf))
return 0;
- file.filesize = stat_buf.st_size;
+ file->offset = 0;
+ file->filesize = stat_buf.st_size;
+ }
+ else
+ {
+ file->offset = ibfd->origin;
+ file->filesize = arelt_size (ibfd);
}
+ return 1;
+}
+
+static int
+try_claim (bfd *abfd)
+{
+ int claimed = 0;
+ struct ld_plugin_input_file file;
+ if (!bfd_plugin_open_input (abfd, &file))
+ return 0;
file.handle = abfd;
- off_t cur_offset = lseek(file.fd, 0, SEEK_CUR);
+ off_t cur_offset = lseek (file.fd, 0, SEEK_CUR);
claim_file (&file, &claimed);
- lseek(file.fd, cur_offset, SEEK_SET);
- if (!claimed)
- return 0;
-
- return 1;
+ lseek (file.fd, cur_offset, SEEK_SET);
+ return claimed;
}
static int
diff --git a/bfd/plugin.h b/bfd/plugin.h
index 529f8c1..0867122 100644
--- a/bfd/plugin.h
+++ b/bfd/plugin.h
@@ -21,9 +21,8 @@
#ifndef _PLUGIN_H_
#define _PLUGIN_H_
-#include "bfd.h"
-
void bfd_plugin_set_program_name (const char *);
+int bfd_plugin_open_input (bfd *, struct ld_plugin_input_file *);
void bfd_plugin_set_plugin (const char *);
bfd_boolean bfd_plugin_target_p (const bfd_target *);
bfd_boolean bfd_plugin_specified_p (void);
diff --git a/binutils/ar.c b/binutils/ar.c
index 1337710..ba0d581 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -33,6 +33,7 @@
#include "arsup.h"
#include "filenames.h"
#include "binemul.h"
+#include "plugin-api.h"
#include "plugin.h"
#ifdef __GO32___
diff --git a/binutils/nm.c b/binutils/nm.c
index 5ca4d34..766564d 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -36,6 +36,7 @@
#include "coff/internal.h"
#include "libcoff.h"
#include "bucomm.h"
+#include "plugin-api.h"
#include "plugin.h"
/* When sorting by size, we use this structure to hold the size and a
diff --git a/ld/plugin.c b/ld/plugin.c
index 924b59c..ffa0dd3 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -21,7 +21,6 @@
#include "sysdep.h"
#include "libiberty.h"
#include "bfd.h"
-#include "libbfd.h"
#include "bfdlink.h"
#include "bfdver.h"
#include "ld.h"
@@ -30,9 +29,9 @@
#include "ldexp.h"
#include "ldlang.h"
#include "ldfile.h"
+#include "plugin-api.h"
#include "../bfd/plugin.h"
#include "plugin.h"
-#include "plugin-api.h"
#include "elf-bfd.h"
#if HAVE_MMAP
# include <sys/mman.h>
@@ -1083,12 +1082,8 @@ plugin_object_p (bfd *ibfd)
{
int claimed;
plugin_input_file_t *input;
- off_t offset, filesize;
struct ld_plugin_input_file file;
bfd *abfd;
- bfd_boolean inarchive;
- const char *name;
- int fd;
/* Don't try the dummy object file. */
if ((ibfd->flags & BFD_PLUGIN) != 0)
@@ -1102,14 +1097,6 @@ plugin_object_p (bfd *ibfd)
return NULL;
}
- inarchive = (ibfd->my_archive != NULL
- && !bfd_is_thin_archive (ibfd->my_archive));
- name = inarchive ? ibfd->my_archive->filename : ibfd->filename;
- fd = open (name, O_RDONLY | O_BINARY);
-
- if (fd < 0)
- return NULL;
-
/* We create a dummy BFD, initially empty, to house whatever symbols
the plugin may want to add. */
abfd = plugin_get_ir_dummy_bfd (ibfd->filename, ibfd);
@@ -1119,39 +1106,31 @@ plugin_object_p (bfd *ibfd)
einfo (_("%P%F: plugin failed to allocate memory for input: %s\n"),
bfd_get_error ());
- if (inarchive)
- {
- /* Offset and filesize must refer to the individual archive
- member, not the whole file, and must exclude the header.
- Fortunately for us, that is how the data is stored in the
- origin field of the bfd and in the arelt_data. */
- offset = ibfd->origin;
- filesize = arelt_size (ibfd);
- }
- else
- {
- offset = 0;
- filesize = lseek (fd, 0, SEEK_END);
+ if (!bfd_plugin_open_input (ibfd, &file))
+ return NULL;
+ if (file.name == ibfd->filename)
+ {
/* We must copy filename attached to ibfd if it is not an archive
member since it may be freed by bfd_close below. */
- name = plugin_strdup (abfd, name);
+ file.name = plugin_strdup (abfd, file.name);
}
- file.name = name;
- file.offset = offset;
- file.filesize = filesize;
- file.fd = fd;
file.handle = input;
+ /* The plugin API expects that the file descriptor won't be closed
+ and reused as done by the bfd file cache. So dup one. */
+ file.fd = dup (file.fd);
+ if (file.fd < 0)
+ return NULL;
input->abfd = abfd;
input->view_buffer.addr = NULL;
input->view_buffer.filesize = 0;
input->view_buffer.offset = 0;
- input->fd = fd;
+ input->fd = file.fd;
input->use_mmap = FALSE;
- input->offset = offset;
- input->filesize = filesize;
+ input->offset = file.offset;
+ input->filesize = file.filesize;
input->name = plugin_strdup (abfd, ibfd->filename);
claimed = 0;
@@ -1160,7 +1139,7 @@ plugin_object_p (bfd *ibfd)
einfo (_("%P%F: %s: plugin reported error claiming file\n"),
plugin_error_plugin ());
- if (input->fd != -1 && ! bfd_plugin_target_p (ibfd->xvec))
+ if (input->fd != -1 && !bfd_plugin_target_p (ibfd->xvec))
{
/* FIXME: fd belongs to us, not the plugin. GCC plugin, which
doesn't need fd after plugin_call_claim_file, doesn't use
@@ -1170,7 +1149,7 @@ plugin_object_p (bfd *ibfd)
release_input_file after it is done, uses BFD plugin target
vector. This scheme doesn't work when a plugin needs fd and
doesn't use BFD plugin target vector neither. */
- close (fd);
+ close (input->fd);
input->fd = -1;
}
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-07-16 13:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-16 13:10 Don't include libbfd.h outside of bfd, part 1 Alan Modra
2016-07-16 13:12 ` Don't include libbfd.h outside of bfd, part 2 Alan Modra
2016-07-16 13:13 ` Don't include libbfd.h outside of bfd, part 3 Alan Modra
2016-07-16 13:14 ` Don't include libbfd.h outside of bfd, part 4 Alan Modra
2016-07-16 13:14 ` Don't include libbfd.h outside of bfd, part 5 Alan Modra
2016-07-16 13:16 ` Don't include libbfd.h outside of bfd, part 6 Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).