score and mmix target_id

Message ID Z2AHwAYI0cF3dS0K@squeak.grove.modra.org
State New
Headers
Series score and mmix target_id |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Dec. 16, 2024, 10:58 a.m. UTC
  These targets currently use GENERIC_ELF_DATA as their target_id, but
that isn't exactly correct.  While their bfd tdata is generic elf,
their elf_section_data is extended with extra target data.  Add
MMIX_ELF_DATA and SCORE_ELF_DATA.
  

Comments

Hans-Peter Nilsson Dec. 17, 2024, 2:03 a.m. UTC | #1
On Mon, 16 Dec 2024, Alan Modra wrote:

> These targets currently use GENERIC_ELF_DATA as their target_id, but
> that isn't exactly correct.  While their bfd tdata is generic elf,
> their elf_section_data is extended with extra target data.  Add
> MMIX_ELF_DATA and SCORE_ELF_DATA.

This patch broke 29 ld-mmix tests, the first being
ld-mmix/bpo-1.

brgds, H-P
  
Alan Modra Dec. 17, 2024, 3:58 a.m. UTC | #2
On Mon, Dec 16, 2024 at 09:03:03PM -0500, Hans-Peter Nilsson wrote:
> On Mon, 16 Dec 2024, Alan Modra wrote:
> 
> > These targets currently use GENERIC_ELF_DATA as their target_id, but
> > that isn't exactly correct.  While their bfd tdata is generic elf,
> > their elf_section_data is extended with extra target data.  Add
> > MMIX_ELF_DATA and SCORE_ELF_DATA.
> 
> This patch broke 29 ld-mmix tests, the first being
> ld-mmix/bpo-1.

Huh, so it did.  elflink.c compares the hash table and object ids in a
number of places.  The patch below fixes commit 64a91215cd, but you
might like to look into the segfaults due to mmix_final_link_relocate
being called from mmix_elf_relocate_section with a NULL error_message.

I'll likely commit another fix on top of this one, because it occurs
to me that it would be better to remove the last param of
_bfd_elf_link_hash_table_init.  The target_id can then be retrieved
inside _bfd_elf_link_hash_table_init from elf_backend_data.


diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c
index d22d92d1748..6c6de3488f3 100644
--- a/bfd/elf32-score.c
+++ b/bfd/elf32-score.c
@@ -4366,7 +4366,7 @@ elf32_score_link_hash_table_create (bfd *abfd)
 
   if (!_bfd_elf_link_hash_table_init (ret, abfd, score_elf_link_hash_newfunc,
 				      sizeof (struct score_elf_link_hash_entry),
-				      GENERIC_ELF_DATA))
+				      SCORE_ELF_DATA))
     {
       free (ret);
       return NULL;
diff --git a/bfd/elflink.c b/bfd/elflink.c
index ef159dafd55..2b9e8b9ea30 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -8354,7 +8354,7 @@ _bfd_elf_link_hash_table_create (bfd *abfd)
 
   if (! _bfd_elf_link_hash_table_init (ret, abfd, _bfd_elf_link_hash_newfunc,
 				       sizeof (struct elf_link_hash_entry),
-				       GENERIC_ELF_DATA))
+				       get_elf_backend_data (abfd)->target_id))
     {
       free (ret);
       return NULL;
  

Patch

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index b756e73736e..2f11bc2d2e6 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -556,6 +556,7 @@  enum elf_target_id
   METAG_ELF_DATA,
   MICROBLAZE_ELF_DATA,
   MIPS_ELF_DATA,
+  MMIX_ELF_DATA,
   MN10300_ELF_DATA,
   NDS32_ELF_DATA,
   OR1K_ELF_DATA,
@@ -563,6 +564,7 @@  enum elf_target_id
   PPC64_ELF_DATA,
   PRU_ELF_DATA,
   S390_ELF_DATA,
+  SCORE_ELF_DATA,
   SH_ELF_DATA,
   SPARC_ELF_DATA,
   SPU_ELF_DATA,
diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c
index 30d6dc85e22..03ea71d150e 100644
--- a/bfd/elf32-score.c
+++ b/bfd/elf32-score.c
@@ -4447,6 +4447,7 @@  _bfd_score_elf_common_definition (Elf_Internal_Sym *sym)
 #define ELF_ARCH			bfd_arch_score
 #define ELF_MACHINE_CODE		EM_SCORE
 #define ELF_MACHINE_ALT1		EM_SCORE_OLD
+#define ELF_TARGET_ID			SCORE_ELF_DATA
 #define ELF_MAXPAGESIZE			0x8000
 
 #define elf_info_to_howto		NULL
diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
index 43a46e52c5b..4e7fbda38b4 100644
--- a/bfd/elf64-mmix.c
+++ b/bfd/elf64-mmix.c
@@ -2861,6 +2861,7 @@  mmix_elf_relax_section (bfd *abfd,
 
 #define ELF_ARCH		bfd_arch_mmix
 #define ELF_MACHINE_CODE	EM_MMIX
+#define ELF_TARGET_ID		MMIX_ELF_DATA
 
 /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
    However, that's too much for something somewhere in the linker part of