bfd_merge_private_bfd_data tidy

bfd_merge_private_bfd_data and _bfd_generic_verify_endian_match are
linker functions, so move them to linker.c.

bfd/
	* Makefile.am (LIBBFD_H_FILES): Update.
	* doc/Makefile.am (LIBBFD_H_DEP): Likewise.
	* cpu-sh.c (sh_merge_bfd_arch): Move to..
	* elf32-sh.c: ..here, and make static.
	* elf32-arc.c (arc_elf_merge_private_bfd_data): Delete extraneous
	error.
	* elf32-cris.c (cris_elf_merge_private_bfd_data): Don't call
	_bfd_generic_verify_endian_match.
	* elf32-microblaze.c (microblaze_elf_merge_private_bfd_data): Delete.
	(bfd_elf32_bfd_merge_private_bfd_data): Define as
	_bfd_generic_verify_endian_match.
	* elf32-mt.c (mt_elf_merge_private_bfd_data): Don't test
	boolean == FALSE.
	* elf32-xgate.c (_bfd_xgate_elf_merge_private_bfd_data): Delete.
	(bfd_elf32_bfd_merge_private_bfd_data): Don't define.
	* elf32-xgate.h (_bfd_xgate_elf_merge_private_bfd_data): Delete.
	* libbfd-in.h (_bfd_generic_verify_endian_match): Delete.
	* libbfd.c (_bfd_generic_verify_endian_match): Move to..
	* linker.c: ..here, and make internal.
	* bfd.c (bfd_merge_private_bfd_data): Move to..
	* linker.c: ..here.
	* Makefile.in: Regenerate.
	* doc/Makefile.in: Regenerate.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
opcodes/
	* sh-opc.h (sh_merge_bfd_arch): Delete prototype.
This commit is contained in:
Alan Modra 2016-10-07 10:58:35 +10:30
parent b62b1f7143
commit 1047201fd0
21 changed files with 159 additions and 163 deletions

View File

@ -1,3 +1,31 @@
2016-10-07 Alan Modra <amodra@gmail.com>
* Makefile.am (LIBBFD_H_FILES): Update.
* doc/Makefile.am (LIBBFD_H_DEP): Likewise.
* cpu-sh.c (sh_merge_bfd_arch): Move to..
* elf32-sh.c: ..here, and make static.
* elf32-arc.c (arc_elf_merge_private_bfd_data): Delete extraneous
error.
* elf32-cris.c (cris_elf_merge_private_bfd_data): Don't call
_bfd_generic_verify_endian_match.
* elf32-microblaze.c (microblaze_elf_merge_private_bfd_data): Delete.
(bfd_elf32_bfd_merge_private_bfd_data): Define as
_bfd_generic_verify_endian_match.
* elf32-mt.c (mt_elf_merge_private_bfd_data): Don't test
boolean == FALSE.
* elf32-xgate.c (_bfd_xgate_elf_merge_private_bfd_data): Delete.
(bfd_elf32_bfd_merge_private_bfd_data): Don't define.
* elf32-xgate.h (_bfd_xgate_elf_merge_private_bfd_data): Delete.
* libbfd-in.h (_bfd_generic_verify_endian_match): Delete.
* libbfd.c (_bfd_generic_verify_endian_match): Move to..
* linker.c: ..here, and make internal.
* bfd.c (bfd_merge_private_bfd_data): Move to..
* linker.c: ..here.
* Makefile.in: Regenerate.
* doc/Makefile.in: Regenerate.
* bfd-in2.h: Regenerate.
* libbfd.h: Regenerate.
2016-10-06 Alan Modra <amodra@gmail.com>
* coff-h8300.c: Spell fall through comments consistently.

View File

@ -1002,8 +1002,8 @@ BFD_H_FILES = bfd-in.h init.c opncls.c libbfd.c \
syms.c bfd.c archive.c corefile.c targets.c format.c \
linker.c simple.c compress.c
BFD64_H_FILES = archive64.c
LIBBFD_H_FILES = libbfd-in.h init.c libbfd.c bfdio.c bfdwin.c \
cache.c reloc.c archures.c elf.c
LIBBFD_H_FILES = libbfd-in.h libbfd.c bfdio.c bfdwin.c \
cache.c reloc.c archures.c linker.c
LIBCOFF_H_FILES = libcoff-in.h coffcode.h
# Could really use a "copy-if-change"...

View File

@ -1176,8 +1176,8 @@ BFD_H_FILES = bfd-in.h init.c opncls.c libbfd.c \
linker.c simple.c compress.c
BFD64_H_FILES = archive64.c
LIBBFD_H_FILES = libbfd-in.h init.c libbfd.c bfdio.c bfdwin.c \
cache.c reloc.c archures.c elf.c
LIBBFD_H_FILES = libbfd-in.h libbfd.c bfdio.c bfdwin.c \
cache.c reloc.c archures.c linker.c
LIBCOFF_H_FILES = libcoff-in.h coffcode.h
MOSTLYCLEANFILES = ofiles stamp-ofiles

View File

@ -6975,11 +6975,6 @@ bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
#define bfd_copy_private_bfd_data(ibfd, obfd) \
BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
(ibfd, obfd))
bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
#define bfd_merge_private_bfd_data(ibfd, obfd) \
BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
(ibfd, obfd))
bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags);
#define bfd_set_private_flags(abfd, flags) \
@ -7620,6 +7615,11 @@ bfd_boolean bfd_link_check_relocs
bfd_boolean _bfd_generic_link_check_relocs
(bfd *abfd, struct bfd_link_info *info);
bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
#define bfd_merge_private_bfd_data(ibfd, obfd) \
BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
(ibfd, obfd))
/* Extracted from simple.c. */
bfd_byte *bfd_simple_get_relocated_section_contents
(bfd *abfd, asection *sec, bfd_byte *outbuf, asymbol **symbol_table);

View File

@ -1406,27 +1406,6 @@ DESCRIPTION
*/
/*
FUNCTION
bfd_merge_private_bfd_data
SYNOPSIS
bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
DESCRIPTION
Merge private BFD information from the BFD @var{ibfd} to the
the output file BFD @var{obfd} when linking. Return <<TRUE>>
on success, <<FALSE>> on error. Possible error returns are:
o <<bfd_error_no_memory>> -
Not enough memory exists to create private data for @var{obfd}.
.#define bfd_merge_private_bfd_data(ibfd, obfd) \
. BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
. (ibfd, obfd))
*/
/*
FUNCTION
bfd_set_private_flags

View File

@ -496,50 +496,3 @@ sh_get_bfd_mach_from_arch_set (unsigned int arch_set)
return result;
}
/* Merge the architecture type of two BFD files, such that the
resultant architecture supports all the features required
by the two input BFDs.
If the input BFDs are multually incompatible - i.e. one uses
DSP while the other uses FPU - or there is no known architecture
that fits the requirements then an error is emitted. */
bfd_boolean
sh_merge_bfd_arch (bfd *ibfd, bfd *obfd)
{
unsigned int old_arch, new_arch, merged_arch;
if (! _bfd_generic_verify_endian_match (ibfd, obfd))
return FALSE;
old_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (obfd));
new_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (ibfd));
merged_arch = SH_MERGE_ARCH_SET (old_arch, new_arch);
if (!SH_VALID_CO_ARCH_SET (merged_arch))
{
_bfd_error_handler
("%B: uses %s instructions while previous modules use %s instructions",
ibfd,
SH_ARCH_SET_HAS_DSP (new_arch) ? "dsp" : "floating point",
SH_ARCH_SET_HAS_DSP (new_arch) ? "floating point" : "dsp");
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
else if (!SH_VALID_ARCH_SET (merged_arch))
{
_bfd_error_handler
("internal error: merge of architecture '%s' with architecture '%s' produced unknown architecture\n",
bfd_printable_name (obfd),
bfd_printable_name (ibfd));
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
bfd_default_set_arch_mach (obfd, bfd_arch_sh,
sh_get_bfd_mach_from_arch_set (merged_arch));
return TRUE;
}

View File

@ -252,14 +252,13 @@ linker.stamp: $(srcdir)/../linker.c $(srcdir)/doc.str $(MKDOC)
LIBBFD_H_DEP = \
$(srcdir)/../libbfd-in.h \
$(srcdir)/../init.c \
$(srcdir)/../libbfd.c \
$(srcdir)/../bfdio.c \
$(srcdir)/../bfdwin.c \
$(srcdir)/../cache.c \
$(srcdir)/../reloc.c \
$(srcdir)/../archures.c \
$(srcdir)/../elf.c \
$(srcdir)/../linker.c \
$(srcdir)/header.sed \
$(srcdir)/proto.str \
$(MKDOC)

View File

@ -379,14 +379,13 @@ AM_CPPFLAGS = -I.. -I$(srcdir)/.. -I$(srcdir)/../../include \
LIBBFD_H_DEP = \
$(srcdir)/../libbfd-in.h \
$(srcdir)/../init.c \
$(srcdir)/../libbfd.c \
$(srcdir)/../bfdio.c \
$(srcdir)/../bfdwin.c \
$(srcdir)/../cache.c \
$(srcdir)/../reloc.c \
$(srcdir)/../archures.c \
$(srcdir)/../elf.c \
$(srcdir)/../linker.c \
$(srcdir)/header.sed \
$(srcdir)/proto.str \
$(MKDOC)

View File

@ -552,12 +552,7 @@ arc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
/* Check if we have the same endianess. */
if (! _bfd_generic_verify_endian_match (ibfd, obfd))
{
_bfd_error_handler (_("ERROR: Endian Match failed. Attempting to link "
"%B with binary %s of opposite endian-ness"),
ibfd, bfd_get_filename (obfd));
return FALSE;
}
return FALSE;
/* Collect ELF flags. */
in_flags = elf_elfheader (ibfd)->e_flags & EF_ARC_MACH_MSK;

View File

@ -4233,18 +4233,14 @@ cris_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
static bfd_boolean
cris_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
{
/* Call the base function. */
if (!_bfd_elf_copy_private_bfd_data (ibfd, obfd))
return FALSE;
/* If output is big-endian for some obscure reason, stop here. */
if (_bfd_generic_verify_endian_match (ibfd, obfd) == FALSE)
return FALSE;
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
return TRUE;
/* Call the base function. */
if (!_bfd_elf_copy_private_bfd_data (ibfd, obfd))
return FALSE;
/* Do what we really came here for. */
return bfd_set_arch_mach (obfd, bfd_arch_cris, bfd_get_mach (ibfd));
}

View File

@ -1596,21 +1596,6 @@ microblaze_elf_relocate_section (bfd *output_bfd,
return ret;
}
/* Merge backend specific data from an object file to the output
object file when linking.
Note: We only use this hook to catch endian mismatches. */
static bfd_boolean
microblaze_elf_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
{
/* Check if we have the same endianess. */
if (! _bfd_generic_verify_endian_match (ibfd, obfd))
return FALSE;
return TRUE;
}
/* Calculate fixup value for reference. */
@ -3500,7 +3485,7 @@ microblaze_elf_add_symbol_hook (bfd *abfd,
#define bfd_elf32_bfd_is_local_label_name microblaze_elf_is_local_label_name
#define elf_backend_relocate_section microblaze_elf_relocate_section
#define bfd_elf32_bfd_relax_section microblaze_elf_relax_section
#define bfd_elf32_bfd_merge_private_bfd_data microblaze_elf_merge_private_bfd_data
#define bfd_elf32_bfd_merge_private_bfd_data _bfd_generic_verify_endian_match
#define bfd_elf32_bfd_reloc_name_lookup microblaze_elf_reloc_name_lookup
#define elf_backend_gc_mark_hook microblaze_elf_gc_mark_hook

View File

@ -508,7 +508,7 @@ mt_elf_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
bfd_boolean ok = TRUE;
/* Check if we have the same endianness. */
if (_bfd_generic_verify_endian_match (ibfd, obfd) == FALSE)
if (!_bfd_generic_verify_endian_match (ibfd, obfd))
return FALSE;
/* If they're not both mt, then merging is meaningless, so just

View File

@ -6414,6 +6414,54 @@ sh_find_elf_flags (unsigned int arch_set)
return sh_elf_get_flags_from_mach (bfd_mach);
}
/* Merge the architecture type of two BFD files, such that the
resultant architecture supports all the features required
by the two input BFDs.
If the input BFDs are multually incompatible - i.e. one uses
DSP while the other uses FPU - or there is no known architecture
that fits the requirements then an error is emitted. */
static bfd_boolean
sh_merge_bfd_arch (bfd *ibfd, bfd *obfd)
{
unsigned int old_arch, new_arch, merged_arch;
if (! _bfd_generic_verify_endian_match (ibfd, obfd))
return FALSE;
old_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (obfd));
new_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (ibfd));
merged_arch = SH_MERGE_ARCH_SET (old_arch, new_arch);
if (!SH_VALID_CO_ARCH_SET (merged_arch))
{
_bfd_error_handler
("%B: uses %s instructions while previous modules "
"use %s instructions",
ibfd,
SH_ARCH_SET_HAS_DSP (new_arch) ? "dsp" : "floating point",
SH_ARCH_SET_HAS_DSP (new_arch) ? "floating point" : "dsp");
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
else if (!SH_VALID_ARCH_SET (merged_arch))
{
_bfd_error_handler
("internal error: merge of architecture '%s' with "
"architecture '%s' produced unknown architecture",
bfd_printable_name (obfd),
bfd_printable_name (ibfd));
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
bfd_default_set_arch_mach (obfd, bfd_arch_sh,
sh_get_bfd_mach_from_arch_set (merged_arch));
return TRUE;
}
/* This routine initialises the elf flags when required and
calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */

View File

@ -654,16 +654,6 @@ _bfd_xgate_elf_set_private_flags (bfd *abfd ATTRIBUTE_UNUSED,
return TRUE;
}
/* Merge backend specific data from an object file to the output
object file when linking. */
bfd_boolean
_bfd_xgate_elf_merge_private_bfd_data (bfd *ibfd ATTRIBUTE_UNUSED,
bfd *obfd ATTRIBUTE_UNUSED)
{
return TRUE;
}
bfd_boolean
_bfd_xgate_elf_print_private_bfd_data (bfd *abfd, void *ptr)
{
@ -722,7 +712,6 @@ elf32_xgate_post_process_headers (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_in
#define elf_backend_add_symbol_hook elf32_xgate_add_symbol_hook
#define bfd_elf32_bfd_link_hash_table_create xgate_elf_bfd_link_hash_table_create
#define bfd_elf32_bfd_merge_private_bfd_data _bfd_xgate_elf_merge_private_bfd_data
#define bfd_elf32_bfd_set_private_flags _bfd_xgate_elf_set_private_flags
#define bfd_elf32_bfd_print_private_bfd_data _bfd_xgate_elf_print_private_bfd_data

View File

@ -29,7 +29,6 @@
#include "elf/xgate.h"
/* Set and control ELF flags in ELF header. */
extern bfd_boolean _bfd_xgate_elf_merge_private_bfd_data (bfd*,bfd*);
extern bfd_boolean _bfd_xgate_elf_set_private_flags (bfd*,flagword);
extern bfd_boolean _bfd_xgate_elf_print_private_bfd_data (bfd*, void*);

View File

@ -749,10 +749,6 @@ extern bfd_size_type _bfd_stringtab_add
/* Write out a string table. */
extern bfd_boolean _bfd_stringtab_emit
(bfd *, struct bfd_strtab_hash *);
/* Check that endianness of input and output file match. */
extern bfd_boolean _bfd_generic_verify_endian_match
(bfd *, bfd *);
/* Macros to tell if bfds are read or write enabled.

View File

@ -922,32 +922,6 @@ bfd_generic_is_local_label_name (bfd *abfd, const char *name)
return name[0] == locals_prefix;
}
/* Can be used from / for bfd_merge_private_bfd_data to check that
endianness matches between input and output file. Returns
TRUE for a match, otherwise returns FALSE and emits an error. */
bfd_boolean
_bfd_generic_verify_endian_match (bfd *ibfd, bfd *obfd)
{
if (ibfd->xvec->byteorder != obfd->xvec->byteorder
&& ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
&& obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
{
const char *msg;
if (bfd_big_endian (ibfd))
msg = _("%B: compiled for a big endian system and target is little endian");
else
msg = _("%B: compiled for a little endian system and target is big endian");
_bfd_error_handler (msg, ibfd);
bfd_set_error (bfd_error_wrong_format);
return FALSE;
}
return TRUE;
}
/* Give a warning at runtime if someone compiles code which calls
old routines. */

View File

@ -1,6 +1,6 @@
/* DO NOT EDIT! -*- buffer-read-only: t -*- This file is automatically
generated from "libbfd-in.h", "init.c", "libbfd.c", "bfdio.c",
"bfdwin.c", "cache.c", "reloc.c", "archures.c" and "elf.c".
generated from "libbfd-in.h", "libbfd.c", "bfdio.c", "bfdwin.c",
"cache.c", "reloc.c", "archures.c" and "linker.c".
Run "make headers" in your build bfd/ to regenerate. */
/* libbfd.h -- Declarations used by bfd library *implementation*.
@ -754,10 +754,6 @@ extern bfd_size_type _bfd_stringtab_add
/* Write out a string table. */
extern bfd_boolean _bfd_stringtab_emit
(bfd *, struct bfd_strtab_hash *);
/* Check that endianness of input and output file match. */
extern bfd_boolean _bfd_generic_verify_endian_match
(bfd *, bfd *);
/* Macros to tell if bfds are read or write enabled.
@ -868,7 +864,6 @@ extern bfd_vma read_unsigned_leb128 (bfd *, bfd_byte *, unsigned int *);
extern bfd_signed_vma read_signed_leb128 (bfd *, bfd_byte *, unsigned int *);
extern bfd_vma safe_read_leb128 (bfd *, bfd_byte *, unsigned int *,
bfd_boolean, const bfd_byte * const);
/* Extracted from init.c. */
/* Extracted from libbfd.c. */
bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int);
@ -3157,7 +3152,10 @@ void *bfd_arch_default_fill (bfd_size_type count,
bfd_boolean is_bigendian,
bfd_boolean code);
/* Extracted from elf.c. */
/* Extracted from linker.c. */
bfd_boolean _bfd_generic_verify_endian_match
(bfd *ibfd, bfd *obfd);
#ifdef __cplusplus
}
#endif

View File

@ -3332,3 +3332,58 @@ _bfd_generic_link_check_relocs (bfd *abfd ATTRIBUTE_UNUSED,
{
return TRUE;
}
/*
FUNCTION
bfd_merge_private_bfd_data
SYNOPSIS
bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
DESCRIPTION
Merge private BFD information from the BFD @var{ibfd} to the
the output file BFD @var{obfd} when linking. Return <<TRUE>> on success,
<<FALSE>> on error. Possible error returns are:
o <<bfd_error_no_memory>> -
Not enough memory exists to create private data for @var{obfd}.
.#define bfd_merge_private_bfd_data(ibfd, obfd) \
. BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
. (ibfd, obfd))
*/
/*
INTERNAL_FUNCTION
_bfd_generic_verify_endian_match
SYNOPSIS
bfd_boolean _bfd_generic_verify_endian_match
(bfd *ibfd, bfd *obfd);
DESCRIPTION
Can be used from / for bfd_merge_private_bfd_data to check that
endianness matches between input and output file. Returns
TRUE for a match, otherwise returns FALSE and emits an error.
*/
bfd_boolean
_bfd_generic_verify_endian_match (bfd *ibfd, bfd *obfd)
{
if (ibfd->xvec->byteorder != obfd->xvec->byteorder
&& ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
&& obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
{
if (bfd_big_endian (ibfd))
_bfd_error_handler (_("%B: compiled for a big endian system "
"and target is little endian"), ibfd);
else
_bfd_error_handler (_("%B: compiled for a little endian system "
"and target is big endian"), ibfd);
bfd_set_error (bfd_error_wrong_format);
return FALSE;
}
return TRUE;
}

View File

@ -1,3 +1,7 @@
2016-10-07 Alan Modra <amodra@gmail.com>
* sh-opc.h (sh_merge_bfd_arch): Delete prototype.
2016-10-06 Alan Modra <amodra@gmail.com>
* aarch64-opc.c: Spell fall through comments consistently.

View File

@ -285,7 +285,6 @@ sh_dsp_reg_nums;
unsigned int sh_get_arch_from_bfd_mach (unsigned long mach);
unsigned int sh_get_arch_up_from_bfd_mach (unsigned long mach);
unsigned long sh_get_bfd_mach_from_arch_set (unsigned int arch_set);
bfd_boolean sh_merge_bfd_arch (bfd *ibfd, bfd *obfd);
/* Below are the 'architecture sets'.
They describe the following inheritance graph: