xgate cleanup

Message ID 20180709082716.GD3373@bubble.grove.modra.org
State New
Headers show
Series
  • xgate cleanup
Related show

Commit Message

Alan Modra July 9, 2018, 8:27 a.m.
elf32-xgate.c contains many functions that are only stubs and
elf32-xgate.h contains unused declarations.  While this might be
reasonable for the initial commit of a port with subsequent work
fleshing out the stubs, xgate has only had two minor target specific
patches since the initial commit over six years ago.  The rest of the
changes have been general maintenance work applied to all ELF targets,
and some of this work could have been avoided if the stubs hadn't been
there.  So this patch removes all the stubs.

I've kept the functionality of the old elf32_xgate_add_symbol_hook,
implemented in elf32_xgate_backend_symbol_processing.  Presumably,
that's to set the symbol st_target_internal flag for use in
elf32-m68hc1x.c:elf32_m68hc11_relocate_section.

The empty elf32_xgate_relocate_section meant that xgate had no linker.
Or at least, no linker relocation processing.  Deleting the
elf_backend_relocate_section define means the target will now use the
generic linker reloc processing.  How good that is will depend on the
accuracy of the reloc howtos..

I haven't updated the ld testsuite to xfail tests expected to fail
for generic elf targets, as I'm wondering whether it might be better
to simply not configure ld for xgate?

bfd/
	* elf32-xgate.h: Delete.
	* elf32-xgate.c: Delete unnecessary forward declarations, add two
	that are now needed.
	(xgate_elf_bfd_link_hash_table_create)
	(xgate_elf_bfd_link_hash_table_free)
	(xgate_elf_set_mach_from_flags, struct xgate_scan_param)
	(stub_hash_newfunc, elf32_xgate_add_symbol_hook)
	(elf32_xgate_setup_section_lists, elf32_xgate_size_stubs)
	(elf32_xgate_build_stubs, elf32_xgate_check_relocs)
	(elf32_xgate_relocate_section, _bfd_xgate_elf_set_private_flags)
	(elf32_xgate_post_process_headers): Delete.
	(elf32_xgate_backend_symbol_processing): New function.
	(xgate_elf_ignore_reloc, xgate_elf_special_reloc)
	(_bfd_xgate_elf_print_private_bfd_data): Make static.
	(ELF_TARGET_ID, elf_info_to_howto, elf_backend_check_relocs)
	(elf_backend_relocate_section, elf_backend_object_p)
	(elf_backend_final_write_processing, elf_backend_can_gc_sections)
	(elf_backend_post_process_headers, elf_backend_add_symbol_hook)
	(bfd_elf32_bfd_link_hash_table_create)
	(bfd_elf32_bfd_set_private_flags)
	(xgate_stub_hash_lookup): Don't define.
	(elf_backend_symbol_processing): Define.
	* elf-bfd.h (elf_target_id): Delete XGATE_ELF_DATA.
ld/
	* emulparams/xgateelf.sh (TEMPLATE_NAME) Set to generic.
	(EXTRA_EM_FILE): Set to genelf.


-- 
Alan Modra
Australia Development Lab, IBM

Comments

Sean Keys July 9, 2018, 6:26 p.m. | #1
Hi Alan,

Thanks for taking a look at this. Sadly, I have not had much time to put 
into this port in the last few years, I appreciate your investigation.

 >Presumably, that's to set the symbol st_target_internal flag for use 

in elf32-m68hc1x.c:elf32_m68hc11_relocate_section.
That was the only special handling of symbols that I can recall. Using 
the generic linker reloc processing should be fine.

 >as I'm wondering whether it might be better to simply not configure ld 

for xgate?
Maybe, xgate isn't really a standalone processor anyway. I have used 
xgate-ld to build stand alone blobs in the past, but it's typically much 
less useful.

Also there's a bunch of xgate duplication in tc-m68hc1x.h/c that can be 
cleaned up. Maybe I can try out your patch on hardware to make sure all 
is well, and submit a couple more cleanup patches.

Cheers,
Sean

On 07/09/2018 01:27 AM, Alan Modra wrote:
> elf32-xgate.c contains many functions that are only stubs and

> elf32-xgate.h contains unused declarations.  While this might be

> reasonable for the initial commit of a port with subsequent work

> fleshing out the stubs, xgate has only had two minor target specific

> patches since the initial commit over six years ago.  The rest of the

> changes have been general maintenance work applied to all ELF targets,

> and some of this work could have been avoided if the stubs hadn't been

> there.  So this patch removes all the stubs.

>

> I've kept the functionality of the old elf32_xgate_add_symbol_hook,

> implemented in elf32_xgate_backend_symbol_processing.  Presumably,

> that's to set the symbol st_target_internal flag for use in

> elf32-m68hc1x.c:elf32_m68hc11_relocate_section.

>

> The empty elf32_xgate_relocate_section meant that xgate had no linker.

> Or at least, no linker relocation processing.  Deleting the

> elf_backend_relocate_section define means the target will now use the

> generic linker reloc processing.  How good that is will depend on the

> accuracy of the reloc howtos..

>

> I haven't updated the ld testsuite to xfail tests expected to fail

> for generic elf targets, as I'm wondering whether it might be better

> to simply not configure ld for xgate?

>

> bfd/

> 	* elf32-xgate.h: Delete.

> 	* elf32-xgate.c: Delete unnecessary forward declarations, add two

> 	that are now needed.

> 	(xgate_elf_bfd_link_hash_table_create)

> 	(xgate_elf_bfd_link_hash_table_free)

> 	(xgate_elf_set_mach_from_flags, struct xgate_scan_param)

> 	(stub_hash_newfunc, elf32_xgate_add_symbol_hook)

> 	(elf32_xgate_setup_section_lists, elf32_xgate_size_stubs)

> 	(elf32_xgate_build_stubs, elf32_xgate_check_relocs)

> 	(elf32_xgate_relocate_section, _bfd_xgate_elf_set_private_flags)

> 	(elf32_xgate_post_process_headers): Delete.

> 	(elf32_xgate_backend_symbol_processing): New function.

> 	(xgate_elf_ignore_reloc, xgate_elf_special_reloc)

> 	(_bfd_xgate_elf_print_private_bfd_data): Make static.

> 	(ELF_TARGET_ID, elf_info_to_howto, elf_backend_check_relocs)

> 	(elf_backend_relocate_section, elf_backend_object_p)

> 	(elf_backend_final_write_processing, elf_backend_can_gc_sections)

> 	(elf_backend_post_process_headers, elf_backend_add_symbol_hook)

> 	(bfd_elf32_bfd_link_hash_table_create)

> 	(bfd_elf32_bfd_set_private_flags)

> 	(xgate_stub_hash_lookup): Don't define.

> 	(elf_backend_symbol_processing): Define.

> 	* elf-bfd.h (elf_target_id): Delete XGATE_ELF_DATA.

> ld/

> 	* emulparams/xgateelf.sh (TEMPLATE_NAME) Set to generic.

> 	(EXTRA_EM_FILE): Set to genelf.

>

> diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h

> index 903dd9a4fa..9453c324ae 100644

> --- a/bfd/elf-bfd.h

> +++ b/bfd/elf-bfd.h

> @@ -515,7 +515,6 @@ enum elf_target_id

>     TIC6X_ELF_DATA,

>     X86_64_ELF_DATA,

>     XTENSA_ELF_DATA,

> -  XGATE_ELF_DATA,

>     TILEGX_ELF_DATA,

>     TILEPRO_ELF_DATA,

>     RISCV_ELF_DATA,

> diff --git a/bfd/elf32-xgate.c b/bfd/elf32-xgate.c

> index a3675260f5..9866864a58 100644

> --- a/bfd/elf32-xgate.c

> +++ b/bfd/elf32-xgate.c

> @@ -24,25 +24,15 @@

>   #include "bfdlink.h"

>   #include "libbfd.h"

>   #include "elf-bfd.h"

> -#include "elf32-xgate.h"

>   #include "elf/xgate.h"

>   #include "opcode/xgate.h"

>   #include "libiberty.h"

>   

> -/* Relocation functions.  */

> -static reloc_howto_type *

> -bfd_elf32_bfd_reloc_type_lookup (bfd *, bfd_reloc_code_real_type);

> -static reloc_howto_type *

> -bfd_elf32_bfd_reloc_name_lookup (bfd *, const char *);

> -static bfd_boolean

> -xgate_info_to_howto_rel (bfd *, arelent *, Elf_Internal_Rela *);

> -static bfd_boolean

> -xgate_elf_set_mach_from_flags (bfd *);

> -static struct bfd_hash_entry *

> -stub_hash_newfunc (struct bfd_hash_entry *, struct bfd_hash_table *,

> -    const char *);

> -static struct bfd_link_hash_table*

> -xgate_elf_bfd_link_hash_table_create (bfd *);

> +/* Forward declarations.  */

> +static bfd_reloc_status_type xgate_elf_ignore_reloc

> +  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);

> +static bfd_reloc_status_type xgate_elf_special_reloc

> +  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);

>   

>   /* Use REL instead of RELA to save space */

>   #define USE_REL	1

> @@ -434,66 +424,6 @@ xgate_info_to_howto_rel (bfd *abfd,

>     return TRUE;

>   }

>   

> -/* Destroy an XGATE ELF linker hash table.  */

> -

> -static void

> -xgate_elf_bfd_link_hash_table_free (bfd *obfd)

> -{

> -  struct xgate_elf_link_hash_table *ret =

> -      (struct xgate_elf_link_hash_table *) obfd->link.hash;

> -

> -  bfd_hash_table_free (ret->stub_hash_table);

> -  free (ret->stub_hash_table);

> -  _bfd_elf_link_hash_table_free (obfd);

> -}

> -

> -/* Create an XGATE ELF linker hash table.  */

> -

> -static struct bfd_link_hash_table*

> -xgate_elf_bfd_link_hash_table_create (bfd *abfd)

> -{

> -  struct xgate_elf_link_hash_table *ret;

> -  bfd_size_type amt = sizeof(struct xgate_elf_link_hash_table);

> -

> -  ret = (struct xgate_elf_link_hash_table *) bfd_zmalloc (amt);

> -  if (ret == (struct xgate_elf_link_hash_table *) NULL)

> -    return NULL;

> -

> -  if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,

> -      _bfd_elf_link_hash_newfunc, sizeof(struct elf_link_hash_entry),

> -      XGATE_ELF_DATA))

> -    {

> -      free (ret);

> -      return NULL;

> -    }

> -

> -  /* Init the stub hash table too.  */

> -  amt = sizeof(struct bfd_hash_table);

> -  ret->stub_hash_table = (struct bfd_hash_table*) bfd_zmalloc (amt);

> -  if (ret->stub_hash_table == NULL)

> -    {

> -      _bfd_elf_link_hash_table_free (abfd);

> -      return NULL;

> -    }

> -

> -  if (!bfd_hash_table_init (ret->stub_hash_table, stub_hash_newfunc,

> -      sizeof(struct elf32_xgate_stub_hash_entry)))

> -    {

> -      free (ret->stub_hash_table);

> -      _bfd_elf_link_hash_table_free (abfd);

> -      return NULL;

> -    }

> -  ret->root.root.hash_table_free = xgate_elf_bfd_link_hash_table_free;

> -

> -  return &ret->root.root;

> -}

> -

> -static bfd_boolean

> -xgate_elf_set_mach_from_flags (bfd *abfd ATTRIBUTE_UNUSED)

> -{

> -  return TRUE;

> -}

> -

>   /* Specific sections:

>    - The .page0 is a data section that is mapped in [0x0000..0x00FF].

>      Page0 accesses are faster on the M68HC12.

> @@ -511,91 +441,20 @@ static const struct bfd_elf_special_section elf32_xgate_special_sections[] =

>     { NULL, 0, 0, 0, 0 }

>   };

>   

> -struct xgate_scan_param

> -{

> -  struct xgate_page_info* pinfo;

> -  bfd_boolean use_memory_banks;

> -};

> -

> -/* Assorted hash table functions.  */

> +/* Hook called when reading symbols. */

>   

> -/* Initialize an entry in the stub hash table.  */

> -

> -static struct bfd_hash_entry *

> -stub_hash_newfunc (struct bfd_hash_entry *entry,

> -		   struct bfd_hash_table *table ATTRIBUTE_UNUSED,

> -		   const char *string ATTRIBUTE_UNUSED)

> -{

> -  return entry;

> -}

> -

> -/* Hook called by the linker routine which adds symbols from an object

> -   file. */

> -

> -bfd_boolean

> -elf32_xgate_add_symbol_hook (bfd *abfd ATTRIBUTE_UNUSED,

> -			     struct bfd_link_info *info ATTRIBUTE_UNUSED,

> -			     Elf_Internal_Sym *sym,

> -			     const char **namep ATTRIBUTE_UNUSED,

> -			     flagword *flagsp ATTRIBUTE_UNUSED,

> -			     asection **secp ATTRIBUTE_UNUSED,

> -			     bfd_vma *valp ATTRIBUTE_UNUSED)

> -{

> -  /* For some reason the st_target_internal value is not retained

> -     after xgate_frob_symbol is called, hence this temp hack.  */

> -  sym->st_target_internal = 1;

> -  return TRUE;

> -}

> -

> -/* External entry points for sizing and building linker stubs.  */

> -

> -/* Set up various things so that we can make a list of input sections

> -   for each output section included in the link.  Returns -1 on error,

> -   0 when no stubs will be needed, and 1 on success.  */

> -

> -int

> -elf32_xgate_setup_section_lists (bfd *output_bfd ATTRIBUTE_UNUSED,

> -				 struct bfd_link_info *info ATTRIBUTE_UNUSED)

> -{

> -  return 1;

> -}

> -

> -/* Determine and set the size of the stub section for a final link.

> -   The basic idea here is to examine all the relocations looking for

> -   PC-relative calls to a target that is unreachable with any "9-bit PC-REL"

> -   instruction.  */

> -

> -bfd_boolean

> -elf32_xgate_size_stubs (bfd *output_bfd ATTRIBUTE_UNUSED,

> -			bfd *stub_bfd ATTRIBUTE_UNUSED,

> -			struct bfd_link_info *info ATTRIBUTE_UNUSED,

> -			asection * (*add_stub_section) (const char*, asection*) ATTRIBUTE_UNUSED)

> -{

> -  return FALSE;

> -}

> -

> -/* Build all the stubs associated with the current output file.  The

> -   stubs are kept in a hash table attached to the main linker hash

> -   table.  This function is called via xgateelf_finish in the

> -   linker.  */

> -

> -bfd_boolean

> -elf32_xgate_build_stubs (bfd *abfd ATTRIBUTE_UNUSED,

> -			 struct bfd_link_info *info ATTRIBUTE_UNUSED)

> -{

> -  return TRUE;

> -}

> -

> -void

> -xgate_elf_get_bank_parameters (struct bfd_link_info *info ATTRIBUTE_UNUSED)

> +static void

> +elf32_xgate_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,

> +				       asymbol *sym)

>   {

> -  return;

> +  /* Mark xgate symbols.  */

> +  ((elf_symbol_type *) sym)->internal_elf_sym.st_target_internal = 1;

>   }

>   

>   /* This function is used for relocs which are only used for relaxing,

>      which the linker should otherwise ignore.  */

>   

> -bfd_reloc_status_type

> +static bfd_reloc_status_type

>   xgate_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,

>   			arelent *reloc_entry,

>   			asymbol *symbol ATTRIBUTE_UNUSED,

> @@ -609,7 +468,7 @@ xgate_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,

>     return bfd_reloc_ok;

>   }

>   

> -bfd_reloc_status_type

> +static bfd_reloc_status_type

>   xgate_elf_special_reloc (bfd *abfd ATTRIBUTE_UNUSED,

>   			 arelent *reloc_entry ATTRIBUTE_UNUSED,

>   			 asymbol *symbol ATTRIBUTE_UNUSED,

> @@ -621,44 +480,7 @@ xgate_elf_special_reloc (bfd *abfd ATTRIBUTE_UNUSED,

>     abort ();

>   }

>   

> -/* Look through the relocs for a section during the first phase.

> -   Since we don't do .gots or .plts, we just need to consider the

> -   virtual table relocs for gc.  */

> -

> -bfd_boolean

> -elf32_xgate_check_relocs (bfd *abfd ATTRIBUTE_UNUSED,

> -			  struct bfd_link_info *info ATTRIBUTE_UNUSED,

> -			  asection *sec ATTRIBUTE_UNUSED,

> -			  const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED)

> -{

> -  return TRUE;

> -}

> -

> -/* Relocate a XGATE/S12x ELF section.  */

> -

> -bfd_boolean

> -elf32_xgate_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,

> -			      struct bfd_link_info *info ATTRIBUTE_UNUSED,

> -			      bfd *input_bfd ATTRIBUTE_UNUSED,

> -			      asection *input_section ATTRIBUTE_UNUSED,

> -			      bfd_byte *contents ATTRIBUTE_UNUSED,

> -			      Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED,

> -			      Elf_Internal_Sym *local_syms ATTRIBUTE_UNUSED,

> -			      asection **local_sections ATTRIBUTE_UNUSED)

> -{

> -  return TRUE;

> -}

> -

> -/* Set and control ELF flags in ELF header.  */

> -

> -bfd_boolean

> -_bfd_xgate_elf_set_private_flags (bfd *abfd ATTRIBUTE_UNUSED,

> -				  flagword flags ATTRIBUTE_UNUSED)

> -{

> -  return TRUE;

> -}

> -

> -bfd_boolean

> +static bfd_boolean

>   _bfd_xgate_elf_print_private_bfd_data (bfd *abfd, void *ptr)

>   {

>     FILE *file = (FILE *) ptr;

> @@ -689,38 +511,17 @@ _bfd_xgate_elf_print_private_bfd_data (bfd *abfd, void *ptr)

>     return TRUE;

>   }

>   

> -void

> -elf32_xgate_post_process_headers (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *link_info ATTRIBUTE_UNUSED)

> -{

> -

> -}

> -

>   #define ELF_ARCH			     bfd_arch_xgate

>   #define ELF_MACHINE_CODE		     EM_XGATE

> -#define ELF_TARGET_ID			     XGATE_ELF_DATA

>   

>   #define ELF_MAXPAGESIZE			     0x1000

>   

>   #define TARGET_BIG_SYM			     xgate_elf32_vec

>   #define TARGET_BIG_NAME			     "elf32-xgate"

>   

> -#define elf_info_to_howto		     NULL

>   #define elf_info_to_howto_rel		     xgate_info_to_howto_rel

> -#define elf_backend_check_relocs	     elf32_xgate_check_relocs

> -#define elf_backend_relocate_section	     elf32_xgate_relocate_section

> -#define elf_backend_object_p		     xgate_elf_set_mach_from_flags

> -#define elf_backend_final_write_processing   NULL

> -#define elf_backend_can_gc_sections	     1

>   #define elf_backend_special_sections	     elf32_xgate_special_sections

> -#define elf_backend_post_process_headers     elf32_xgate_post_process_headers

> -#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_set_private_flags	     _bfd_xgate_elf_set_private_flags

> +#define elf_backend_symbol_processing	     elf32_xgate_backend_symbol_processing

>   #define bfd_elf32_bfd_print_private_bfd_data _bfd_xgate_elf_print_private_bfd_data

>   

> -#define xgate_stub_hash_lookup(table, string, create, copy)	\

> -    ((struct elf32_xgate_stub_hash_entry *) \

> -	bfd_hash_lookup ((table), (string), (create), (copy)))

> -

>   #include "elf32-target.h"

> diff --git a/bfd/elf32-xgate.h b/bfd/elf32-xgate.h

> deleted file mode 100644

> index 99ab9a4935..0000000000

> --- a/bfd/elf32-xgate.h

> +++ /dev/null

> @@ -1,142 +0,0 @@

> -/* Freescale XGATE-specific support for 32-bit ELF

> -   Copyright (C) 2012-2018 Free Software Foundation, Inc.

> -

> -   Contributed by Sean Keys (skeys@ipdatasys.com)

> -   (Heavily copied from the HC11 port by Stephane Carrez (stcarrez@nerim.fr))

> -

> -   This file is part of BFD, the Binary File Descriptor library.

> -

> -   This program is free software; you can redistribute it and/or modify

> -   it under the terms of the GNU General Public License as published by

> -   the Free Software Foundation; either version 3 of the License, or

> -   (at your option) any later version.

> -

> -   This program is distributed in the hope that it will be useful,

> -   but WITHOUT ANY WARRANTY; without even the implied warranty of

> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

> -   GNU General Public License for more details.

> -

> -   You should have received a copy of the GNU General Public License

> -   along with this program; if not, write to the Free Software

> -   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,

> -   MA 02110-1301, USA.  */

> -

> -#ifndef _ELF32_XGATE_H

> -#define _ELF32_XGATE_H

> -

> -#include "elf-bfd.h"

> -#include "bfdlink.h"

> -#include "elf/xgate.h"

> -

> -/* Set and control ELF flags in ELF header.  */

> -extern bfd_boolean _bfd_xgate_elf_set_private_flags (bfd*,flagword);

> -extern bfd_boolean _bfd_xgate_elf_print_private_bfd_data (bfd*, void*);

> -

> -struct elf32_xgate_stub_hash_entry

> -{

> -  /* Base hash table entry structure.  */

> -  struct bfd_hash_entry root;

> -

> -  /* The stub section.  */

> -  asection *stub_sec;

> -

> -  /* Offset within stub_sec of the beginning of this stub.  */

> -  bfd_vma stub_offset;

> -

> -  /* Given the symbol's value and its section we can determine its final

> -     value when building the stubs (so the stub knows where to jump.  */

> -  bfd_vma target_value;

> -  asection *target_section;

> -};

> -

> -struct xgate_page_info

> -{

> -  bfd_vma bank_virtual;

> -  bfd_vma bank_physical;

> -  bfd_vma bank_physical_end;

> -  bfd_vma bank_mask;

> -  bfd_vma bank_size;

> -  int bank_shift;

> -  int bank_param_initialized;

> -  bfd_vma trampoline_addr;

> -};

> -

> -struct xgate_elf_link_hash_table

> -{

> -  struct elf_link_hash_table root;

> -  struct xgate_page_info pinfo;

> -

> -  /* The stub hash table.  */

> -  struct bfd_hash_table* stub_hash_table;

> -

> -  /* Linker stub bfd.  */

> -  bfd *stub_bfd;

> -

> -  asection* stub_section;

> -  asection* tramp_section;

> -

> -  /* Linker call-backs.  */

> -  asection * (*add_stub_section) (const char *, asection *);

> -

> -  /* Assorted information used by elf32_hppa_size_stubs.  */

> -  unsigned int bfd_count;

> -  int	       top_index;

> -  asection **  input_list;

> -

> -  /* Small local sym cache.  */

> -  struct sym_cache sym_cache;

> -

> -  bfd_boolean (*size_one_stub) (struct bfd_hash_entry*, void*);

> -  bfd_boolean (*build_one_stub) (struct bfd_hash_entry*, void*);

> -};

> -

> -/* Get the XGate ELF linker hash table from a link_info structure.  */

> -

> -#define xgate_elf_hash_table(p) \

> -  ((struct xgate_elf_link_hash_table *) ((p)->hash))

> -

> -/* Create a XGATE ELF linker hash table.  */

> -

> -extern struct xgate_elf_link_hash_table* xgate_elf_hash_table_create

> -  (bfd *);

> -

> -extern void xgate_elf_get_bank_parameters (struct bfd_link_info *);

> -

> -/* Return 1 if the address is in banked memory.

> -   This can be applied to a virtual address and to a physical address.  */

> -extern int xgate_addr_is_banked (struct xgate_page_info *, bfd_vma);

> -

> -/* Return the physical address seen by the processor, taking

> -   into account banked memory.  */

> -extern bfd_vma xgate_phys_addr (struct xgate_page_info *, bfd_vma);

> -

> -/* Return the page number corresponding to an address in banked memory.  */

> -extern bfd_vma xgate_phys_page (struct xgate_page_info *, bfd_vma);

> -

> -bfd_reloc_status_type xgate_elf_ignore_reloc

> -  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);

> -bfd_reloc_status_type xgate_elf_special_reloc

> -  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);

> -

> -bfd_boolean elf32_xgate_check_relocs

> -  (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);

> -bfd_boolean elf32_xgate_relocate_section

> -  (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,

> -   Elf_Internal_Rela *, Elf_Internal_Sym *, asection **);

> -

> -bfd_boolean elf32_xgate_add_symbol_hook

> -  (bfd *, struct bfd_link_info *, Elf_Internal_Sym *, const char **,

> -   flagword *, asection **, bfd_vma *);

> -

> -/* Tweak the OSABI field of the elf header.  */

> -extern void elf32_xgate_post_process_headers (bfd *, struct bfd_link_info *);

> -

> -int elf32_xgate_setup_section_lists (bfd *, struct bfd_link_info *);

> -

> -bfd_boolean elf32_xgate_size_stubs

> -  (bfd *, bfd *, struct bfd_link_info *,

> -   asection * (*) (const char *, asection *));

> -

> -bfd_boolean elf32_xgate_build_stubs (bfd * abfd, struct bfd_link_info *);

> -

> -#endif /* _ELF32_XGATE_H */

> diff --git a/ld/emulparams/xgateelf.sh b/ld/emulparams/xgateelf.sh

> index 1f9253e805..fa2e60ae1c 100644

> --- a/ld/emulparams/xgateelf.sh

> +++ b/ld/emulparams/xgateelf.sh

> @@ -1,4 +1,6 @@

>   MACHINE=

> +TEMPLATE_NAME=generic

> +EXTRA_EM_FILE=genelf

>   SCRIPT_NAME=elfxgate

>   OUTPUT_FORMAT="elf32-xgate"

>   ROM_START_ADDR=0x08000

> @@ -14,5 +16,3 @@ ARCH=xgate

>   MAXPAGESIZE=32

>   EMBEDDED=yes

>   GENERIC_BOARD=no

> -TEMPLATE_NAME=elf32

> -EXTRA_EM_FILE=

>
Alan Modra July 10, 2018, 2:42 p.m. | #2
On Mon, Jul 09, 2018 at 11:26:41AM -0700, Sean Keys wrote:
> > I'm wondering whether it might be better to simply not configure ld for

> > xgate?

> Maybe, xgate isn't really a standalone processor anyway. I have used

> xgate-ld to build stand alone blobs in the past, but it's typically much

> less useful.


OK, we'll keep the ld support, and I'll commit the patch along with
this one.

binutils/
	* testsuite/lib/binutils-common.exp (supports_gnu_unique): Return
	zero for xgate.
ld/
	* testsuite/lib/ld-lib.exp (check_gc_sections_available): Return 0
	for xgate.
	* testsuite/ld-elf/elf.exp: Add xgate to pr21703 xfails.
	* testsuite/ld-elf/shared.exp: Add xgate to pr21703 xfails.
	* testsuite/ld-discard/extern.d: xfail xgate.
	* testsuite/ld-discard/start.d: Likewise.
	* testsuite/ld-discard/static.d: Likewise.
	* testsuite/ld-elf/attributes.d: Likewise.
	* testsuite/ld-elf/compressed1d.d: Likewise.
	* testsuite/ld-elf/group1.d: Likewise.
	* testsuite/ld-elf/group3b.d: Likewise.
	* testsuite/ld-elf/group8a.d: Likewise.
	* testsuite/ld-elf/group8b.d: Likewise.
	* testsuite/ld-elf/group9a.d: Likewise.
	* testsuite/ld-elf/group9b.d: Likewise.
	* testsuite/ld-elf/linkonce2.d: Likewise.
	* testsuite/ld-elf/merge.d: Likewise.
	* testsuite/ld-elf/merge2.d: Likewise.
	* testsuite/ld-elf/merge3.d: Likewise.
	* testsuite/ld-elf/orphan-10.d: Likewise.
	* testsuite/ld-elf/orphan-9.d: Likewise.
	* testsuite/ld-elf/orphan-region.d: Likewise.
	* testsuite/ld-elf/orphan.d: Likewise.
	* testsuite/ld-elf/orphan3.d: Likewise.
	* testsuite/ld-elf/pr12851.d: Likewise.
	* testsuite/ld-elf/pr12975.d: Likewise.
	* testsuite/ld-elf/pr13177.d: Likewise.
	* testsuite/ld-elf/pr13195.d: Likewise.
	* testsuite/ld-elf/pr14156b.d: Likewise.
	* testsuite/ld-elf/pr17550c.d: Likewise.
	* testsuite/ld-elf/pr17550d.d: Likewise.
	* testsuite/ld-elf/pr17615.d: Likewise.
	* testsuite/ld-elf/pr20528a.d: Likewise.
	* testsuite/ld-elf/pr20528b.d: Likewise.
	* testsuite/ld-elf/pr21562a.d: Likewise.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-elf/pr22677.d: Likewise.
	* testsuite/ld-elf/pr22836-1a.d: Likewise.
	* testsuite/ld-elf/pr22836-1b.d: Likewise.
	* testsuite/ld-elf/pr349.d: Likewise.
	* testsuite/ld-elf/warn1.d: Likewise.
	* testsuite/ld-elf/warn2.d: Likewise.
	* testsuite/ld-elf/warn3.d: Likewise.

diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
index dcaab847d2..7de7d6796a 100644
--- a/binutils/testsuite/lib/binutils-common.exp
+++ b/binutils/testsuite/lib/binutils-common.exp
@@ -177,7 +177,8 @@ proc supports_gnu_unique {} {
     if { [istarget "am33_2.0-*-*"]
 	 || [istarget "d30v-*-*"]
 	 || [istarget "dlx-*-*"]
-	 || [istarget "pj*-*-*"] } {
+	 || [istarget "pj*-*-*"]
+	 || [istarget "xgate-*-*"] } {
 	return 0
     }
     return 1
diff --git a/ld/testsuite/ld-discard/extern.d b/ld/testsuite/ld-discard/extern.d
index a8d91fb872..223c06b695 100644
--- a/ld/testsuite/ld-discard/extern.d
+++ b/ld/testsuite/ld-discard/extern.d
@@ -2,7 +2,7 @@
 #ld: -T discard.ld
 #error: .*data.* referenced in section `\.text' of tmpdir/extern.o: defined in discarded section `\.data\.exit' of tmpdir/extern.o
 #objdump: -p
-#xfail: d30v-*-* dlx-*-* pj*-*-*
+#xfail: d30v-*-* dlx-*-* pj*-*-* xgate-*-*
 #pass
 # The expected warning used to start with "`data' referenced..." but
 # this has two problems: 1) It does not include the name of the linker
diff --git a/ld/testsuite/ld-discard/start.d b/ld/testsuite/ld-discard/start.d
index fcb4e8fee0..274befcfef 100644
--- a/ld/testsuite/ld-discard/start.d
+++ b/ld/testsuite/ld-discard/start.d
@@ -3,5 +3,5 @@
 #ld: -T discard.ld
 #error: `data' referenced in section `\.text' of tmpdir/start.o: defined in discarded section `\.data\.exit' of tmpdir/exit.o
 #objdump: -p
-#xfail: d30v-*-* dlx-*-* pj*-*-*
+#xfail: d30v-*-* dlx-*-* pj*-*-* xgate-*-*
 #pass
diff --git a/ld/testsuite/ld-discard/static.d b/ld/testsuite/ld-discard/static.d
index c80fcde087..2b49d8446c 100644
--- a/ld/testsuite/ld-discard/static.d
+++ b/ld/testsuite/ld-discard/static.d
@@ -2,5 +2,5 @@
 #ld: -T discard.ld
 #error: `(\.data\.exit|data)' referenced in section `\.text' of tmpdir/static.o: defined in discarded section `\.data\.exit' of tmpdir/static.o
 #objdump: -p
-#xfail: d30v-*-* dlx-*-* pj*-*-*
+#xfail: d30v-*-* dlx-*-* pj*-*-* xgate-*-*
 #pass
diff --git a/ld/testsuite/ld-elf/attributes.d b/ld/testsuite/ld-elf/attributes.d
index 78d896c317..9ca6d98863 100644
--- a/ld/testsuite/ld-elf/attributes.d
+++ b/ld/testsuite/ld-elf/attributes.d
@@ -1,7 +1,7 @@
 #name: Symbol flags copy
 #ld: -T attributes.ld
 #objdump: -t
-#xfail: pj-*-* dlx-*-* d30v-*-*
+#xfail: pj-*-* dlx-*-* d30v-*-* xgate-*-*
 
 #...
 0+0000000 g     F .text	0+0000000 __start
diff --git a/ld/testsuite/ld-elf/compressed1d.d b/ld/testsuite/ld-elf/compressed1d.d
index 95611c324c..cd6a49b4d4 100644
--- a/ld/testsuite/ld-elf/compressed1d.d
+++ b/ld/testsuite/ld-elf/compressed1d.d
@@ -4,6 +4,7 @@
 #readelf: -SW
 #xfail: d30v-*-* dlx-*-* fr30-*-* frv-*-elf ft32-*-* iq2000-*-*
 #xfail: mn10200-*-* moxie-*-* msp430-*-* mt-*-* pj-*-* riscv*-*-*
+#xfail: xgate-*-*
 # Not all ELF targets use the elf.em emulation...
 # RISC-V has linker relaxations that delete code, so text label subtractions
 # do not get resolved at assembly time, which results in a compressed section.
diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp
index b3223cf721..cabc79daad 100644
--- a/ld/testsuite/ld-elf/elf.exp
+++ b/ld/testsuite/ld-elf/elf.exp
@@ -115,7 +115,7 @@ run_ld_link_tests {
       {"PR ld/21703 -r"
 	"-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
 	{pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
-} "d30v-*-*" "dlx-*-*" "pj-*-*"
+} "d30v-*-*" "dlx-*-*" "pj-*-*" "xgate-*-*"
 
 if [is_underscore_target] {
     set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
diff --git a/ld/testsuite/ld-elf/group1.d b/ld/testsuite/ld-elf/group1.d
index c2d67b9585..22d2df4f36 100644
--- a/ld/testsuite/ld-elf/group1.d
+++ b/ld/testsuite/ld-elf/group1.d
@@ -2,7 +2,7 @@
 #source: group1b.s
 #ld: -T group.ld
 #readelf: -s
-#xfail: d30v-*-* dlx-*-* pj*-*-* *-*-solaris*
+#xfail: d30v-*-* dlx-*-* pj*-*-* xgate-*-* *-*-solaris*
 # generic linker targets don't comply with all symbol merging rules
 
 Symbol table '.symtab' contains .* entries:
diff --git a/ld/testsuite/ld-elf/group3b.d b/ld/testsuite/ld-elf/group3b.d
index bb8813f4f3..15f1a43300 100644
--- a/ld/testsuite/ld-elf/group3b.d
+++ b/ld/testsuite/ld-elf/group3b.d
@@ -2,7 +2,7 @@
 #source: group3a.s
 #ld: -T group.ld
 #readelf: -s
-#xfail: d30v-*-* dlx-*-* pj*-*-*
+#xfail: d30v-*-* dlx-*-* pj*-*-* xgate-*-*
 # generic linker targets don't comply with all symbol merging rules
 
 Symbol table '.symtab' contains .* entries:
diff --git a/ld/testsuite/ld-elf/group8a.d b/ld/testsuite/ld-elf/group8a.d
index 58283c92ea..c3b1546e6b 100644
--- a/ld/testsuite/ld-elf/group8a.d
+++ b/ld/testsuite/ld-elf/group8a.d
@@ -2,7 +2,7 @@
 #ld: -r --gc-sections --entry foo
 #readelf: -g --wide
 #xfail: cr16-*-* crx-*-* d30v-*-* dlx-*-* hppa64-*-*
-#xfail: mep-*-* mn10200-*-* pj*-*-* pru-*-*
+#xfail: mep-*-* mn10200-*-* pj*-*-* pru-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 # cr16 and crx use non-standard scripts with memory regions, which don't play
 # well with unique group sections under ld -r.
diff --git a/ld/testsuite/ld-elf/group8b.d b/ld/testsuite/ld-elf/group8b.d
index 512a73b77a..1178b4f3de 100644
--- a/ld/testsuite/ld-elf/group8b.d
+++ b/ld/testsuite/ld-elf/group8b.d
@@ -1,9 +1,8 @@
 #source: group8.s
 #ld: -r --gc-sections --entry bar
 #readelf: -g --wide
-#xfail: d30v-*-* dlx-*-* pj*-*-* pru-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
-#xfail: cr16-*-* crx-*-*
+#xfail: cr16-*-* crx-*-* d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-*
+#xfail: pj*-*-* pru-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 # cr16 and crx use non-standard scripts with memory regions, which don't play
 # well with unique group sections under ld -r.
diff --git a/ld/testsuite/ld-elf/group9a.d b/ld/testsuite/ld-elf/group9a.d
index 8ebd1d1881..403283cfa7 100644
--- a/ld/testsuite/ld-elf/group9a.d
+++ b/ld/testsuite/ld-elf/group9a.d
@@ -1,9 +1,8 @@
 #source: group9.s
 #ld: -r --gc-sections --entry foo
 #readelf: -g --wide
-#xfail: d30v-*-* dlx-*-* pj*-*-* pru-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
-#xfail: cr16-*-* crx-*-*
+#xfail: cr16-*-* crx-*-* d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-*
+#xfail: pj*-*-* pru-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 # cr16 and crx use non-standard scripts with memory regions, which don't play
 # well with unique group sections under ld -r.
diff --git a/ld/testsuite/ld-elf/group9b.d b/ld/testsuite/ld-elf/group9b.d
index d8e1470231..c4475f793b 100644
--- a/ld/testsuite/ld-elf/group9b.d
+++ b/ld/testsuite/ld-elf/group9b.d
@@ -1,9 +1,8 @@
 #source: group9.s
 #ld: -r --gc-sections --entry bar
 #readelf: -g --wide
-#xfail: d30v-*-* dlx-*-* pj*-*-* pru-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
-#xfail: cr16-*-* crx-*-*
+#xfail: cr16-*-* crx-*-* d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-*
+#xfail: pj*-*-* pru-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 # cr16 and crx use non-standard scripts with memory regions, which don't play
 # well with unique group sections under ld -r.
diff --git a/ld/testsuite/ld-elf/linkonce2.d b/ld/testsuite/ld-elf/linkonce2.d
index 5d97a185a8..5a00e056b0 100644
--- a/ld/testsuite/ld-elf/linkonce2.d
+++ b/ld/testsuite/ld-elf/linkonce2.d
@@ -2,7 +2,7 @@
 #source: linkonce1b.s
 #ld: -emit-relocs
 #objdump: -r
-#xfail: d30v-*-* dlx-*-* pj*-*-*
+#xfail: d30v-*-* dlx-*-* pj*-*-* xgate-*-*
 # generic elf targets don't emit relocs
 
 .*:     file format .*
diff --git a/ld/testsuite/ld-elf/merge.d b/ld/testsuite/ld-elf/merge.d
index ebabae8d95..3e3bcba372 100644
--- a/ld/testsuite/ld-elf/merge.d
+++ b/ld/testsuite/ld-elf/merge.d
@@ -1,12 +1,11 @@
 #source: merge.s
 #ld: -T merge.ld
 #objdump: -s
-#xfail: "bfin-*-*" "cr16-*-*" "cris*-*-*" "crx-*-*" "d10v-*-*" "d30v-*-*"
-#xfail: "dlx-*-*" "fr30-*-*" "frv-*-*" "hppa*64*-*-*" "h8300-*-*" "score-*-*"
-#xfail: "ip2k-*-*" "iq2000-*-*" "lm32-*-*"
-#xfail: "mcore-*-*" "mn102*-*-*" "ms1-*-*" "mep-*-*" "m68hc11-*-*" "nios2-*-*" s12z-*-*
-#xfail: "or32-*-*" "pj-*-*" "tic6x-*-*" "vax-*-*" "xstormy16-*-*"
-#xfail: "xtensa*-*-*" "metag-*-*" "ft32-*-*" "pru-*-*"
+#xfail: bfin-*-* cr16-*-* cris*-*-* crx-*-* d10v-*-* d30v-*-* dlx-*-*
+#xfail: fr30-*-* frv-*-* ft32-*-* h8300-*-* hppa*64*-*-* ip2k-*-* iq2000-*-*
+#xfail: lm32-*-* m68hc11-*-* mcore-*-* mep-*-* metag-*-* mn102*-*-* ms1-*-*
+#xfail: nios2-*-* or32-*-* pj-*-* pru-*-* s12z-*-* score-*-* tic6x-*-*
+#xfail: vax-*-* xgate-*-* xstormy16-*-* xtensa*-*-*
 
 .*:     file format .*elf.*
 
diff --git a/ld/testsuite/ld-elf/merge2.d b/ld/testsuite/ld-elf/merge2.d
index 8ac1648ab4..0a7faa7b56 100644
--- a/ld/testsuite/ld-elf/merge2.d
+++ b/ld/testsuite/ld-elf/merge2.d
@@ -1,8 +1,7 @@
 #source: merge2.s
 #ld: -T merge.ld
 #objdump: -s
-#xfail: "d30v-*-*" "dlx-*-*" "hppa64-*-*"
-#xfail: "ip2k-*-*" "pj-*-*"
+#xfail: d30v-*-* dlx-*-* hppa64-*-* ip2k-*-* pj-*-* xgate-*-*
 
 .*:     file format .*elf.*
 
diff --git a/ld/testsuite/ld-elf/merge3.d b/ld/testsuite/ld-elf/merge3.d
index b9ae79c1b9..53dc3428d9 100644
--- a/ld/testsuite/ld-elf/merge3.d
+++ b/ld/testsuite/ld-elf/merge3.d
@@ -1,8 +1,7 @@
 #source: merge3.s
 #ld: -T merge.ld
 #objdump: -s
-#xfail: "d30v-*-*" "dlx-*-*" "hppa64-*-*"
-#xfail: "ip2k-*-*" "pj-*-*"
+#xfail: d30v-*-* dlx-*-* hppa64-*-* ip2k-*-* pj-*-* xgate-*-*
 
 .*:     file format .*elf.*
 
diff --git a/ld/testsuite/ld-elf/orphan-10.d b/ld/testsuite/ld-elf/orphan-10.d
index 90ddb6b004..2571c0e4ef 100644
--- a/ld/testsuite/ld-elf/orphan-10.d
+++ b/ld/testsuite/ld-elf/orphan-10.d
@@ -2,7 +2,7 @@
 #ld: -N -T orphan-9.ld
 #objdump: -h
 #xfail: d30v-* dlx-* fr30-* frv-*-elf ft32-* iq2000-*
-#xfail: mn10200-* moxie-* ms1-* msp430-* mt-* pj-*
+#xfail: mn10200-* moxie-* ms1-* msp430-* mt-* pj-* xgate-*
 
 #...
   . \.text         0+(08|10)  [0-9a-f]+  0+200 .*
diff --git a/ld/testsuite/ld-elf/orphan-9.d b/ld/testsuite/ld-elf/orphan-9.d
index 1c6d29c3c0..3d9e324463 100644
--- a/ld/testsuite/ld-elf/orphan-9.d
+++ b/ld/testsuite/ld-elf/orphan-9.d
@@ -2,7 +2,7 @@
 #ld: -N -T orphan-9.ld
 #objdump: -h
 #xfail: d30v-* dlx-* fr30-* frv-*-elf ft32-* iq2000-*
-#xfail: mn10200-* moxie-* ms1-* msp430-* mt-* pj-*
+#xfail: mn10200-* moxie-* ms1-* msp430-* mt-* pj-* xgate-*
 
 #...
   . \.text         0+(08|10)  [0-9a-f]+  0+200 .*
diff --git a/ld/testsuite/ld-elf/orphan-region.d b/ld/testsuite/ld-elf/orphan-region.d
index 7af263a8d7..dd98320921 100644
--- a/ld/testsuite/ld-elf/orphan-region.d
+++ b/ld/testsuite/ld-elf/orphan-region.d
@@ -1,9 +1,9 @@
 #source: orphan-region.s
 #ld: -T orphan-region.ld -N -z stack-size=0
 #readelf: -S -l --wide
-#xfail: d30v-*-* dlx-*-* fr30-*-* frv-*-elf ft32-*-*
+#xfail: d30v-*-* dlx-*-* fr30-*-* frv-*-elf ft32-*-* hppa*64*-*-*
 #xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-*
-#xfail: spu-*-* hppa*64*-*-* *-*-nacl*
+#xfail: spu-*-* xgate-*-* *-*-nacl*
 # if not using elf32.em, you don't get fancy orphan handling
 # spu twiddles LOAD range, hppa64 adds PHDR, nacl splits to two segments
 
diff --git a/ld/testsuite/ld-elf/orphan.d b/ld/testsuite/ld-elf/orphan.d
index 2d10e27125..38af1fd634 100644
--- a/ld/testsuite/ld-elf/orphan.d
+++ b/ld/testsuite/ld-elf/orphan.d
@@ -2,7 +2,7 @@
 #ld: -T orphan.ld
 #readelf: -S --wide
 #xfail: d30v-*-* dlx-*-* fr30-*-* frv-*-elf ft32-*-*
-#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-*
+#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-* xgate-*-*
 # if not using elf32.em, you don't get fancy orphan handling
 
 #...
diff --git a/ld/testsuite/ld-elf/orphan3.d b/ld/testsuite/ld-elf/orphan3.d
index 2c96f64f74..7c2e5128b4 100644
--- a/ld/testsuite/ld-elf/orphan3.d
+++ b/ld/testsuite/ld-elf/orphan3.d
@@ -6,10 +6,8 @@
 #source: orphan3f.s
 #ld:
 #readelf: -S --wide
-#xfail: "d30v-*-*" "dlx-*-*" "fr30-*-*" "frv-*-elf" "ft32-*-*"
-#xfail: "iq2000-*-*" "mn10200-*-*" "msp430-*-*" "mt-*-*"
-#xfail: "pj-*-*"
-#xfail: "xstormy16-*-*"
+#xfail: d30v-*-* dlx-*-* fr30-*-* frv-*-elf ft32-*-* iq2000-*-*
+#xfail: mn10200-*-* msp430-*-* mt-*-* pj-*-* xgate-*-* xstormy16-*-*
 
 #...
   \[[ 0-9]+\] \.foo +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+20 +0+ +A +0 +0 +[0-9]+
diff --git a/ld/testsuite/ld-elf/pr12851.d b/ld/testsuite/ld-elf/pr12851.d
index c44b9013ae..0c42515d65 100644
--- a/ld/testsuite/ld-elf/pr12851.d
+++ b/ld/testsuite/ld-elf/pr12851.d
@@ -2,8 +2,8 @@
 #source: start.s
 #ld: --gc-sections
 #readelf: -s --wide
-#xfail: d30v-*-* dlx-*-* pj*-*-* pru-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-*
+#xfail: pj*-*-* pru-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr12975.d b/ld/testsuite/ld-elf/pr12975.d
index fd52b80782..927924c89b 100644
--- a/ld/testsuite/ld-elf/pr12975.d
+++ b/ld/testsuite/ld-elf/pr12975.d
@@ -1,8 +1,7 @@
 #ld: --gc-sections -shared -version-script pr12975.t
 #readelf: -s --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #failif
diff --git a/ld/testsuite/ld-elf/pr13177.d b/ld/testsuite/ld-elf/pr13177.d
index d775c5e37a..64d701631a 100644
--- a/ld/testsuite/ld-elf/pr13177.d
+++ b/ld/testsuite/ld-elf/pr13177.d
@@ -2,8 +2,7 @@
 #ld: --gc-sections -shared
 #readelf: -s -D --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #failif
diff --git a/ld/testsuite/ld-elf/pr13195.d b/ld/testsuite/ld-elf/pr13195.d
index 3d7facc474..c0a7f31ecb 100644
--- a/ld/testsuite/ld-elf/pr13195.d
+++ b/ld/testsuite/ld-elf/pr13195.d
@@ -1,8 +1,7 @@
 #ld: --gc-sections -shared -version-script pr13195.t
 #readelf: -s --wide -D
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr14156b.d b/ld/testsuite/ld-elf/pr14156b.d
index ae9fa0513d..07c72b054e 100644
--- a/ld/testsuite/ld-elf/pr14156b.d
+++ b/ld/testsuite/ld-elf/pr14156b.d
@@ -5,6 +5,7 @@
 #source: finin.s
 #ld: --sort-section=alignment
 #nm: -n
+#xfail: xgate-*-*
 
 #...
 [0-9a-f]+ T foo
diff --git a/ld/testsuite/ld-elf/pr17550c.d b/ld/testsuite/ld-elf/pr17550c.d
index 9cc4c04aa8..c9c06d01ce 100644
--- a/ld/testsuite/ld-elf/pr17550c.d
+++ b/ld/testsuite/ld-elf/pr17550c.d
@@ -2,6 +2,6 @@
 #source: pr17550-3.s
 #ld: -r
 #error: .*: defined in discarded section `\.data\[foo_group\]'
-#xfail: alpha-*-* d30v-*-* dlx-*-* pj*-*-*
+#xfail: alpha-*-* d30v-*-* dlx-*-* pj*-*-* xgate-*-*
 # Disabled on alpha because alpha has a different .set directive.
 # Generic linker targets don't support comdat group sections.
diff --git a/ld/testsuite/ld-elf/pr17550d.d b/ld/testsuite/ld-elf/pr17550d.d
index a8c43e7da5..70ef97171a 100644
--- a/ld/testsuite/ld-elf/pr17550d.d
+++ b/ld/testsuite/ld-elf/pr17550d.d
@@ -2,7 +2,7 @@
 #source: pr17550-4.s
 #ld: -r
 #readelf: -s --wide
-#xfail: alpha-*-* cr16-*-* crx-*-* d30v-*-* dlx-*-* pj*-*-*
+#xfail: alpha-*-* cr16-*-* crx-*-* d30v-*-* dlx-*-* pj*-*-* xgate-*-*
 # Disabled on alpha because alpha has a different .set directive.
 # cr16 and crx use non-standard scripts with memory regions, which don't
 # play well with comdat group sections under ld -r.  Generic linker
diff --git a/ld/testsuite/ld-elf/pr17615.d b/ld/testsuite/ld-elf/pr17615.d
index 7d8f1c4439..c4263664ee 100644
--- a/ld/testsuite/ld-elf/pr17615.d
+++ b/ld/testsuite/ld-elf/pr17615.d
@@ -1,8 +1,7 @@
 #ld: --gc-sections -shared
 #readelf: -S --wide --dyn-syms
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr20528a.d b/ld/testsuite/ld-elf/pr20528a.d
index 8b56e1128f..68ea140cb7 100644
--- a/ld/testsuite/ld-elf/pr20528a.d
+++ b/ld/testsuite/ld-elf/pr20528a.d
@@ -3,7 +3,7 @@
 #ld: -r
 #readelf: -S --wide
 #xfail: d30v-*-* dlx-*-* fr30-*-* frv-*-elf ft32-*-*
-#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-*
+#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-* xgate-*-*
 
 #...
 [ 	]*\[.*\][ 	]+\.text.startup[ 	]+PROGBITS.*[ 	]+AX[   ]+.*
diff --git a/ld/testsuite/ld-elf/pr20528b.d b/ld/testsuite/ld-elf/pr20528b.d
index 34fd9fb622..5777c27518 100644
--- a/ld/testsuite/ld-elf/pr20528b.d
+++ b/ld/testsuite/ld-elf/pr20528b.d
@@ -3,7 +3,7 @@
 #ld: -r
 #readelf: -S --wide
 #xfail: d30v-*-* dlx-*-* fr30-*-* frv-*-elf ft32-*-*
-#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-*
+#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-* xgate-*-*
 
 #...
 [ 	]*\[.*\][ 	]+\.text.startup[ 	]+PROGBITS.*[ 	]+AXE[   ]+.*
diff --git a/ld/testsuite/ld-elf/pr21562a.d b/ld/testsuite/ld-elf/pr21562a.d
index 29c7b409be..5a80357993 100644
--- a/ld/testsuite/ld-elf/pr21562a.d
+++ b/ld/testsuite/ld-elf/pr21562a.d
@@ -1,8 +1,7 @@
 #ld: -shared -z defs --gc-sections
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr21562b.d b/ld/testsuite/ld-elf/pr21562b.d
index 115833e661..b875c0f320 100644
--- a/ld/testsuite/ld-elf/pr21562b.d
+++ b/ld/testsuite/ld-elf/pr21562b.d
@@ -1,8 +1,7 @@
 #ld: -shared -z defs --gc-sections
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr21562c.d b/ld/testsuite/ld-elf/pr21562c.d
index cb3df1ff89..a551c34442 100644
--- a/ld/testsuite/ld-elf/pr21562c.d
+++ b/ld/testsuite/ld-elf/pr21562c.d
@@ -2,8 +2,7 @@
 #ld: -shared -z defs --gc-sections -T pr21562a.t
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr21562d.d b/ld/testsuite/ld-elf/pr21562d.d
index 068462ec46..674938df05 100644
--- a/ld/testsuite/ld-elf/pr21562d.d
+++ b/ld/testsuite/ld-elf/pr21562d.d
@@ -2,8 +2,7 @@
 #ld: -shared -z defs --gc-sections -T pr21562a.t
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr21562i.d b/ld/testsuite/ld-elf/pr21562i.d
index 77b8db2e5e..fb75243785 100644
--- a/ld/testsuite/ld-elf/pr21562i.d
+++ b/ld/testsuite/ld-elf/pr21562i.d
@@ -2,8 +2,7 @@
 #ld: -shared -z defs --gc-sections -T pr21562b.t
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr21562j.d b/ld/testsuite/ld-elf/pr21562j.d
index f8748bf2e4..42ca86ed2c 100644
--- a/ld/testsuite/ld-elf/pr21562j.d
+++ b/ld/testsuite/ld-elf/pr21562j.d
@@ -2,8 +2,7 @@
 #ld: -shared -z defs --gc-sections -T pr21562b.t
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr21562k.d b/ld/testsuite/ld-elf/pr21562k.d
index aec167ad1e..2c64e2b0ef 100644
--- a/ld/testsuite/ld-elf/pr21562k.d
+++ b/ld/testsuite/ld-elf/pr21562k.d
@@ -2,8 +2,7 @@
 #ld: -shared -z defs --gc-sections -T pr21562c.t
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr21562l.d b/ld/testsuite/ld-elf/pr21562l.d
index 943dd18ea9..7222611110 100644
--- a/ld/testsuite/ld-elf/pr21562l.d
+++ b/ld/testsuite/ld-elf/pr21562l.d
@@ -2,8 +2,7 @@
 #ld: -shared -z defs --gc-sections -T pr21562c.t
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr21562m.d b/ld/testsuite/ld-elf/pr21562m.d
index 16d803244f..917b2ca065 100644
--- a/ld/testsuite/ld-elf/pr21562m.d
+++ b/ld/testsuite/ld-elf/pr21562m.d
@@ -2,8 +2,7 @@
 #ld: -shared -z defs --gc-sections -T pr21562d.t
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr21562n.d b/ld/testsuite/ld-elf/pr21562n.d
index 35f965c881..881db3deea 100644
--- a/ld/testsuite/ld-elf/pr21562n.d
+++ b/ld/testsuite/ld-elf/pr21562n.d
@@ -2,8 +2,7 @@
 #ld: -shared -z defs --gc-sections -T pr21562d.t
 #readelf: -s -S --wide
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
-#xfail: d30v-*-* dlx-*-* pj*-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
+#xfail: d30v-*-* dlx-*-* hppa64-*-* mep-*-* mn10200-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
diff --git a/ld/testsuite/ld-elf/pr22677.d b/ld/testsuite/ld-elf/pr22677.d
index c834be2e19..983fda8859 100644
--- a/ld/testsuite/ld-elf/pr22677.d
+++ b/ld/testsuite/ld-elf/pr22677.d
@@ -1,8 +1,7 @@
 #ld: -r  --gc-sections -u foo
 #readelf: -S --wide
-#xfail: d30v-*-* dlx-*-* pj*-*-* pru-*-*
-#xfail: hppa64-*-* mep-*-* mn10200-*-*
-#xfail: cr16-*-* crx-*-* msp430-*-*
+#xfail: cr16-*-* crx-*-* d30v-*-* dlx-*-* hppa64-*-*
+#xfail: mep-*-* mn10200-*-* msp430-*-* pj*-*-* pru-*-* xgate-*-*
 # msp430 puts the init_array and fini_array inside the .rodata section.
 # generic linker targets don't support --gc-sections, nor do a bunch of
 # others.
diff --git a/ld/testsuite/ld-elf/pr22836-1a.d b/ld/testsuite/ld-elf/pr22836-1a.d
index bd2d0f45a7..fbfd8d9d11 100644
--- a/ld/testsuite/ld-elf/pr22836-1a.d
+++ b/ld/testsuite/ld-elf/pr22836-1a.d
@@ -1,7 +1,7 @@
 #source: pr22836-1.s
 #ld: -r -s
 #readelf: -g --wide
-#xfail: d30v-*-* dlx-*-* pj-*-*
+#xfail: d30v-*-* dlx-*-* pj-*-* xgate-*-*
 # Targets using the generic linker don't properly support comdat group sections
 
 There are no section groups in this file\.
diff --git a/ld/testsuite/ld-elf/pr22836-1b.d b/ld/testsuite/ld-elf/pr22836-1b.d
index 2a332bcfbd..ca7d3f0839 100644
--- a/ld/testsuite/ld-elf/pr22836-1b.d
+++ b/ld/testsuite/ld-elf/pr22836-1b.d
@@ -1,7 +1,7 @@
 #source: pr22836-1.s
 #ld: -r -S
 #readelf: -g --wide
-#xfail: d30v-*-* dlx-*-* pj-*-*
+#xfail: d30v-*-* dlx-*-* pj-*-* xgate-*-*
 # Targets using the generic linker don't properly support comdat group sections
 
 There are no section groups in this file\.
diff --git a/ld/testsuite/ld-elf/pr349.d b/ld/testsuite/ld-elf/pr349.d
index b56683d19c..3354df2200 100644
--- a/ld/testsuite/ld-elf/pr349.d
+++ b/ld/testsuite/ld-elf/pr349.d
@@ -3,7 +3,7 @@
 #ld: -r
 #readelf: -S
 #xfail: d30v-*-* dlx-*-* fr30-*-* frv-*-elf ft32-*-*
-#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-*
+#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-* xgate-*-*
 # if not using elf32.em, you don't get fancy section handling
 
 #...
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index daac3be43d..7970fe99ef 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -359,7 +359,7 @@ run_ld_link_tests [list \
 	 tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "$AFLAGS_PIC" \
 	{pr21703-3.s pr21703-4.s} {{readelf {--dyn-syms} pr21703-shared.sd}} \
 	"pr21703.so" ] \
-] "d30v-*-*" "dlx-*-*" "pj-*-*" "hppa64-*-*"
+] "d30v-*-*" "dlx-*-*" "pj-*-*" "hppa64-*-*" "xgate-*-*"
 
 # This target requires extra GAS options when building non-PIC code
 # for linking with shared libraries.
diff --git a/ld/testsuite/ld-elf/warn1.d b/ld/testsuite/ld-elf/warn1.d
index 9c5ab86aef..ac5d207145 100644
--- a/ld/testsuite/ld-elf/warn1.d
+++ b/ld/testsuite/ld-elf/warn1.d
@@ -5,7 +5,7 @@
 #warning: ^[^\n]*\): warning: witty one-liner$
 #readelf: -s
 #notarget: "sparc64-*-solaris2*" "sparcv9-*-solaris2*"
-#xfail: "d30v-*-*" "dlx-*-*" "pj-*-*"
+#xfail: d30v-*-* dlx-*-* pj-*-* xgate-*-*
 
 # Check that warnings are generated for the .gnu.warning.SYMBOL
 # construct and that the symbol still appears as expected.
diff --git a/ld/testsuite/ld-elf/warn2.d b/ld/testsuite/ld-elf/warn2.d
index cee842ae47..b952e84e63 100644
--- a/ld/testsuite/ld-elf/warn2.d
+++ b/ld/testsuite/ld-elf/warn2.d
@@ -6,7 +6,7 @@
 #readelf: -s
 #notarget: "sparc64-*-solaris2*" "sparcv9-*-solaris2*"
 #xfail: d30v-*-* dlx-*-* fr30-*-* frv-*-elf ft32-*-*
-#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-*
+#xfail: iq*-*-* mn10200-*-* moxie-*-* msp*-*-* mt-*-* pj*-*-* xgate-*-*
 # if not using elf32.em, you don't get fancy section handling
 
 # Check that warnings are generated for the symbols in .gnu.warning
diff --git a/ld/testsuite/ld-elf/warn3.d b/ld/testsuite/ld-elf/warn3.d
index a0acd4b0f2..5b55654970 100644
--- a/ld/testsuite/ld-elf/warn3.d
+++ b/ld/testsuite/ld-elf/warn3.d
@@ -2,7 +2,7 @@
 #ld: tmpdir/symbol3w.o tmpdir/symbol3.a 
 #warning: .*: warning: badsym warning$
 #readelf: -s
-#xfail: d30v-*-* dlx-*-* pj*-*-*
+#xfail: d30v-*-* dlx-*-* pj*-*-* xgate-*-*
 # generic linker targets don't support .gnu.warning sections.
 
 # Check that warnings are generated for the symbols in .gnu.warning
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index 1c313c8751..5880c67842 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1839,15 +1839,16 @@ proc check_gc_sections_available { } {
     if {![info exists gc_sections_available_saved]} {
 	# Some targets don't support gc-sections despite whatever's
 	# advertised by ld's options.
-	if {   [istarget d30v-*-*]
+	if {   [istarget alpha-*-*]
+	    || [istarget d30v-*-*]
 	    || [istarget dlx-*-*]
-	    || [istarget pj*-*-*]
-	    || [istarget pru*-*-*]
-	    || [istarget alpha-*-*]
 	    || [istarget hppa*64-*-*]
 	    || [istarget ia64-*-*]
 	    || [istarget mep-*-*]
-	    || [istarget mn10200-*-*] } {
+	    || [istarget mn10200-*-*]
+	    || [istarget pj*-*-*]
+	    || [istarget pru*-*-*]
+	    || [istarget xgate-*-*] } {
 	    set gc_sections_available_saved 0
 	    return 0
 	}
@@ -1902,7 +1903,8 @@ proc is_generic_elf { } {
 	 || [istarget "moxie-*-*"]
 	 || [istarget "msp430-*-*"]
 	 || [istarget "mt-*-*"]
-	 || [istarget "pj*-*-*"] } {
+	 || [istarget "pj*-*-*"]
+	 || [istarget "xgate-*-*"] } {
 	return 1;
     }
     return 0;

-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 903dd9a4fa..9453c324ae 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -515,7 +515,6 @@  enum elf_target_id
   TIC6X_ELF_DATA,
   X86_64_ELF_DATA,
   XTENSA_ELF_DATA,
-  XGATE_ELF_DATA,
   TILEGX_ELF_DATA,
   TILEPRO_ELF_DATA,
   RISCV_ELF_DATA,
diff --git a/bfd/elf32-xgate.c b/bfd/elf32-xgate.c
index a3675260f5..9866864a58 100644
--- a/bfd/elf32-xgate.c
+++ b/bfd/elf32-xgate.c
@@ -24,25 +24,15 @@ 
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
-#include "elf32-xgate.h"
 #include "elf/xgate.h"
 #include "opcode/xgate.h"
 #include "libiberty.h"
 
-/* Relocation functions.  */
-static reloc_howto_type *
-bfd_elf32_bfd_reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
-static reloc_howto_type *
-bfd_elf32_bfd_reloc_name_lookup (bfd *, const char *);
-static bfd_boolean
-xgate_info_to_howto_rel (bfd *, arelent *, Elf_Internal_Rela *);
-static bfd_boolean
-xgate_elf_set_mach_from_flags (bfd *);
-static struct bfd_hash_entry *
-stub_hash_newfunc (struct bfd_hash_entry *, struct bfd_hash_table *,
-    const char *);
-static struct bfd_link_hash_table*
-xgate_elf_bfd_link_hash_table_create (bfd *);
+/* Forward declarations.  */
+static bfd_reloc_status_type xgate_elf_ignore_reloc
+  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
+static bfd_reloc_status_type xgate_elf_special_reloc
+  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 
 /* Use REL instead of RELA to save space */
 #define USE_REL	1
@@ -434,66 +424,6 @@  xgate_info_to_howto_rel (bfd *abfd,
   return TRUE;
 }
 
-/* Destroy an XGATE ELF linker hash table.  */
-
-static void
-xgate_elf_bfd_link_hash_table_free (bfd *obfd)
-{
-  struct xgate_elf_link_hash_table *ret =
-      (struct xgate_elf_link_hash_table *) obfd->link.hash;
-
-  bfd_hash_table_free (ret->stub_hash_table);
-  free (ret->stub_hash_table);
-  _bfd_elf_link_hash_table_free (obfd);
-}
-
-/* Create an XGATE ELF linker hash table.  */
-
-static struct bfd_link_hash_table*
-xgate_elf_bfd_link_hash_table_create (bfd *abfd)
-{
-  struct xgate_elf_link_hash_table *ret;
-  bfd_size_type amt = sizeof(struct xgate_elf_link_hash_table);
-
-  ret = (struct xgate_elf_link_hash_table *) bfd_zmalloc (amt);
-  if (ret == (struct xgate_elf_link_hash_table *) NULL)
-    return NULL;
-
-  if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
-      _bfd_elf_link_hash_newfunc, sizeof(struct elf_link_hash_entry),
-      XGATE_ELF_DATA))
-    {
-      free (ret);
-      return NULL;
-    }
-
-  /* Init the stub hash table too.  */
-  amt = sizeof(struct bfd_hash_table);
-  ret->stub_hash_table = (struct bfd_hash_table*) bfd_zmalloc (amt);
-  if (ret->stub_hash_table == NULL)
-    {
-      _bfd_elf_link_hash_table_free (abfd);
-      return NULL;
-    }
-
-  if (!bfd_hash_table_init (ret->stub_hash_table, stub_hash_newfunc,
-      sizeof(struct elf32_xgate_stub_hash_entry)))
-    {
-      free (ret->stub_hash_table);
-      _bfd_elf_link_hash_table_free (abfd);
-      return NULL;
-    }
-  ret->root.root.hash_table_free = xgate_elf_bfd_link_hash_table_free;
-
-  return &ret->root.root;
-}
-
-static bfd_boolean
-xgate_elf_set_mach_from_flags (bfd *abfd ATTRIBUTE_UNUSED)
-{
-  return TRUE;
-}
-
 /* Specific sections:
  - The .page0 is a data section that is mapped in [0x0000..0x00FF].
    Page0 accesses are faster on the M68HC12.
@@ -511,91 +441,20 @@  static const struct bfd_elf_special_section elf32_xgate_special_sections[] =
   { NULL, 0, 0, 0, 0 }
 };
 
-struct xgate_scan_param
-{
-  struct xgate_page_info* pinfo;
-  bfd_boolean use_memory_banks;
-};
-
-/* Assorted hash table functions.  */
+/* Hook called when reading symbols. */
 
-/* Initialize an entry in the stub hash table.  */
-
-static struct bfd_hash_entry *
-stub_hash_newfunc (struct bfd_hash_entry *entry,
-		   struct bfd_hash_table *table ATTRIBUTE_UNUSED,
-		   const char *string ATTRIBUTE_UNUSED)
-{
-  return entry;
-}
-
-/* Hook called by the linker routine which adds symbols from an object
-   file. */
-
-bfd_boolean
-elf32_xgate_add_symbol_hook (bfd *abfd ATTRIBUTE_UNUSED,
-			     struct bfd_link_info *info ATTRIBUTE_UNUSED,
-			     Elf_Internal_Sym *sym,
-			     const char **namep ATTRIBUTE_UNUSED,
-			     flagword *flagsp ATTRIBUTE_UNUSED,
-			     asection **secp ATTRIBUTE_UNUSED,
-			     bfd_vma *valp ATTRIBUTE_UNUSED)
-{
-  /* For some reason the st_target_internal value is not retained
-     after xgate_frob_symbol is called, hence this temp hack.  */
-  sym->st_target_internal = 1;
-  return TRUE;
-}
-
-/* External entry points for sizing and building linker stubs.  */
-
-/* Set up various things so that we can make a list of input sections
-   for each output section included in the link.  Returns -1 on error,
-   0 when no stubs will be needed, and 1 on success.  */
-
-int
-elf32_xgate_setup_section_lists (bfd *output_bfd ATTRIBUTE_UNUSED,
-				 struct bfd_link_info *info ATTRIBUTE_UNUSED)
-{
-  return 1;
-}
-
-/* Determine and set the size of the stub section for a final link.
-   The basic idea here is to examine all the relocations looking for
-   PC-relative calls to a target that is unreachable with any "9-bit PC-REL"
-   instruction.  */
-
-bfd_boolean
-elf32_xgate_size_stubs (bfd *output_bfd ATTRIBUTE_UNUSED,
-			bfd *stub_bfd ATTRIBUTE_UNUSED,
-			struct bfd_link_info *info ATTRIBUTE_UNUSED,
-			asection * (*add_stub_section) (const char*, asection*) ATTRIBUTE_UNUSED)
-{
-  return FALSE;
-}
-
-/* Build all the stubs associated with the current output file.  The
-   stubs are kept in a hash table attached to the main linker hash
-   table.  This function is called via xgateelf_finish in the
-   linker.  */
-
-bfd_boolean
-elf32_xgate_build_stubs (bfd *abfd ATTRIBUTE_UNUSED,
-			 struct bfd_link_info *info ATTRIBUTE_UNUSED)
-{
-  return TRUE;
-}
-
-void
-xgate_elf_get_bank_parameters (struct bfd_link_info *info ATTRIBUTE_UNUSED)
+static void
+elf32_xgate_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
+				       asymbol *sym)
 {
-  return;
+  /* Mark xgate symbols.  */
+  ((elf_symbol_type *) sym)->internal_elf_sym.st_target_internal = 1;
 }
 
 /* This function is used for relocs which are only used for relaxing,
    which the linker should otherwise ignore.  */
 
-bfd_reloc_status_type
+static bfd_reloc_status_type
 xgate_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,
 			arelent *reloc_entry,
 			asymbol *symbol ATTRIBUTE_UNUSED,
@@ -609,7 +468,7 @@  xgate_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,
   return bfd_reloc_ok;
 }
 
-bfd_reloc_status_type
+static bfd_reloc_status_type
 xgate_elf_special_reloc (bfd *abfd ATTRIBUTE_UNUSED,
 			 arelent *reloc_entry ATTRIBUTE_UNUSED,
 			 asymbol *symbol ATTRIBUTE_UNUSED,
@@ -621,44 +480,7 @@  xgate_elf_special_reloc (bfd *abfd ATTRIBUTE_UNUSED,
   abort ();
 }
 
-/* Look through the relocs for a section during the first phase.
-   Since we don't do .gots or .plts, we just need to consider the
-   virtual table relocs for gc.  */
-
-bfd_boolean
-elf32_xgate_check_relocs (bfd *abfd ATTRIBUTE_UNUSED,
-			  struct bfd_link_info *info ATTRIBUTE_UNUSED,
-			  asection *sec ATTRIBUTE_UNUSED,
-			  const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED)
-{
-  return TRUE;
-}
-
-/* Relocate a XGATE/S12x ELF section.  */
-
-bfd_boolean
-elf32_xgate_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
-			      struct bfd_link_info *info ATTRIBUTE_UNUSED,
-			      bfd *input_bfd ATTRIBUTE_UNUSED,
-			      asection *input_section ATTRIBUTE_UNUSED,
-			      bfd_byte *contents ATTRIBUTE_UNUSED,
-			      Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED,
-			      Elf_Internal_Sym *local_syms ATTRIBUTE_UNUSED,
-			      asection **local_sections ATTRIBUTE_UNUSED)
-{
-  return TRUE;
-}
-
-/* Set and control ELF flags in ELF header.  */
-
-bfd_boolean
-_bfd_xgate_elf_set_private_flags (bfd *abfd ATTRIBUTE_UNUSED,
-				  flagword flags ATTRIBUTE_UNUSED)
-{
-  return TRUE;
-}
-
-bfd_boolean
+static bfd_boolean
 _bfd_xgate_elf_print_private_bfd_data (bfd *abfd, void *ptr)
 {
   FILE *file = (FILE *) ptr;
@@ -689,38 +511,17 @@  _bfd_xgate_elf_print_private_bfd_data (bfd *abfd, void *ptr)
   return TRUE;
 }
 
-void
-elf32_xgate_post_process_headers (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
-{
-
-}
-
 #define ELF_ARCH			     bfd_arch_xgate
 #define ELF_MACHINE_CODE		     EM_XGATE
-#define ELF_TARGET_ID			     XGATE_ELF_DATA
 
 #define ELF_MAXPAGESIZE			     0x1000
 
 #define TARGET_BIG_SYM			     xgate_elf32_vec
 #define TARGET_BIG_NAME			     "elf32-xgate"
 
-#define elf_info_to_howto		     NULL
 #define elf_info_to_howto_rel		     xgate_info_to_howto_rel
-#define elf_backend_check_relocs	     elf32_xgate_check_relocs
-#define elf_backend_relocate_section	     elf32_xgate_relocate_section
-#define elf_backend_object_p		     xgate_elf_set_mach_from_flags
-#define elf_backend_final_write_processing   NULL
-#define elf_backend_can_gc_sections	     1
 #define elf_backend_special_sections	     elf32_xgate_special_sections
-#define elf_backend_post_process_headers     elf32_xgate_post_process_headers
-#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_set_private_flags	     _bfd_xgate_elf_set_private_flags
+#define elf_backend_symbol_processing	     elf32_xgate_backend_symbol_processing
 #define bfd_elf32_bfd_print_private_bfd_data _bfd_xgate_elf_print_private_bfd_data
 
-#define xgate_stub_hash_lookup(table, string, create, copy)	\
-    ((struct elf32_xgate_stub_hash_entry *) \
-	bfd_hash_lookup ((table), (string), (create), (copy)))
-
 #include "elf32-target.h"
diff --git a/bfd/elf32-xgate.h b/bfd/elf32-xgate.h
deleted file mode 100644
index 99ab9a4935..0000000000
--- a/bfd/elf32-xgate.h
+++ /dev/null
@@ -1,142 +0,0 @@ 
-/* Freescale XGATE-specific support for 32-bit ELF
-   Copyright (C) 2012-2018 Free Software Foundation, Inc.
-
-   Contributed by Sean Keys (skeys@ipdatasys.com)
-   (Heavily copied from the HC11 port by Stephane Carrez (stcarrez@nerim.fr))
-
-   This file is part of BFD, the Binary File Descriptor library.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-   MA 02110-1301, USA.  */
-
-#ifndef _ELF32_XGATE_H
-#define _ELF32_XGATE_H
-
-#include "elf-bfd.h"
-#include "bfdlink.h"
-#include "elf/xgate.h"
-
-/* Set and control ELF flags in ELF header.  */
-extern bfd_boolean _bfd_xgate_elf_set_private_flags (bfd*,flagword);
-extern bfd_boolean _bfd_xgate_elf_print_private_bfd_data (bfd*, void*);
-
-struct elf32_xgate_stub_hash_entry
-{
-  /* Base hash table entry structure.  */
-  struct bfd_hash_entry root;
-
-  /* The stub section.  */
-  asection *stub_sec;
-
-  /* Offset within stub_sec of the beginning of this stub.  */
-  bfd_vma stub_offset;
-
-  /* Given the symbol's value and its section we can determine its final
-     value when building the stubs (so the stub knows where to jump.  */
-  bfd_vma target_value;
-  asection *target_section;
-};
-
-struct xgate_page_info
-{
-  bfd_vma bank_virtual;
-  bfd_vma bank_physical;
-  bfd_vma bank_physical_end;
-  bfd_vma bank_mask;
-  bfd_vma bank_size;
-  int bank_shift;
-  int bank_param_initialized;
-  bfd_vma trampoline_addr;
-};
-
-struct xgate_elf_link_hash_table
-{
-  struct elf_link_hash_table root;
-  struct xgate_page_info pinfo;
-
-  /* The stub hash table.  */
-  struct bfd_hash_table* stub_hash_table;
-
-  /* Linker stub bfd.  */
-  bfd *stub_bfd;
-
-  asection* stub_section;
-  asection* tramp_section;
-
-  /* Linker call-backs.  */
-  asection * (*add_stub_section) (const char *, asection *);
-
-  /* Assorted information used by elf32_hppa_size_stubs.  */
-  unsigned int bfd_count;
-  int	       top_index;
-  asection **  input_list;
-
-  /* Small local sym cache.  */
-  struct sym_cache sym_cache;
-
-  bfd_boolean (*size_one_stub) (struct bfd_hash_entry*, void*);
-  bfd_boolean (*build_one_stub) (struct bfd_hash_entry*, void*);
-};
-
-/* Get the XGate ELF linker hash table from a link_info structure.  */
-
-#define xgate_elf_hash_table(p) \
-  ((struct xgate_elf_link_hash_table *) ((p)->hash))
-
-/* Create a XGATE ELF linker hash table.  */
-
-extern struct xgate_elf_link_hash_table* xgate_elf_hash_table_create
-  (bfd *);
-
-extern void xgate_elf_get_bank_parameters (struct bfd_link_info *);
-
-/* Return 1 if the address is in banked memory.
-   This can be applied to a virtual address and to a physical address.  */
-extern int xgate_addr_is_banked (struct xgate_page_info *, bfd_vma);
-
-/* Return the physical address seen by the processor, taking
-   into account banked memory.  */
-extern bfd_vma xgate_phys_addr (struct xgate_page_info *, bfd_vma);
-
-/* Return the page number corresponding to an address in banked memory.  */
-extern bfd_vma xgate_phys_page (struct xgate_page_info *, bfd_vma);
-
-bfd_reloc_status_type xgate_elf_ignore_reloc
-  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
-bfd_reloc_status_type xgate_elf_special_reloc
-  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
-
-bfd_boolean elf32_xgate_check_relocs
-  (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
-bfd_boolean elf32_xgate_relocate_section
-  (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
-   Elf_Internal_Rela *, Elf_Internal_Sym *, asection **);
-
-bfd_boolean elf32_xgate_add_symbol_hook
-  (bfd *, struct bfd_link_info *, Elf_Internal_Sym *, const char **,
-   flagword *, asection **, bfd_vma *);
-
-/* Tweak the OSABI field of the elf header.  */
-extern void elf32_xgate_post_process_headers (bfd *, struct bfd_link_info *);
-
-int elf32_xgate_setup_section_lists (bfd *, struct bfd_link_info *);
-
-bfd_boolean elf32_xgate_size_stubs
-  (bfd *, bfd *, struct bfd_link_info *,
-   asection * (*) (const char *, asection *));
-
-bfd_boolean elf32_xgate_build_stubs (bfd * abfd, struct bfd_link_info *);
-
-#endif /* _ELF32_XGATE_H */
diff --git a/ld/emulparams/xgateelf.sh b/ld/emulparams/xgateelf.sh
index 1f9253e805..fa2e60ae1c 100644
--- a/ld/emulparams/xgateelf.sh
+++ b/ld/emulparams/xgateelf.sh
@@ -1,4 +1,6 @@ 
 MACHINE=
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 SCRIPT_NAME=elfxgate
 OUTPUT_FORMAT="elf32-xgate"
 ROM_START_ADDR=0x08000
@@ -14,5 +16,3 @@  ARCH=xgate
 MAXPAGESIZE=32
 EMBEDDED=yes
 GENERIC_BOARD=no
-TEMPLATE_NAME=elf32
-EXTRA_EM_FILE=