This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ncurses link problem...


On Wed, Jun 26, 2002 at 12:36:28PM -0500, Peter Bergner wrote:
[On powerpc64-linux-ld accidentally picking up 32 bit shared libs]
>  /opt/ppc64-20020625/lib/gcc-lib/powerpc64-linux/3.1.1/collect2 
>[snip]
> /usr/lib/libncurses.so: could not read symbols: Invalid operation

Uh oh, elfcode.h:elf_object_p calls bfd_default_set_arch_mach, which
merrily decides the input file arch_info is the 64 bit one.  We test
arch_info later to see whether the file is compatible...  The same
thing can happen with a powerpc-linux linker if 64 bit objects are
accidentally loaded.  Fortunately, there's an easy way to tweak the
arch_info via elf_backend_object_p.

	* cpu-powerpc.c: Comment on ordering of arch_info.
	* elf32-ppc.c (ppc_elf_object_p): New function.
	(elf_backend_object_p): Define.
	* elf64-ppc.c (ppc64_elf_object_p): New function.
	(elf_backend_object_p): Define.

Committing.

Index: bfd/cpu-powerpc.c
===================================================================
RCS file: /cvs/src/src/bfd/cpu-powerpc.c,v
retrieving revision 1.9
diff -u -p -r1.9 cpu-powerpc.c
--- bfd/cpu-powerpc.c	20 Apr 2002 02:54:26 -0000	1.9
+++ bfd/cpu-powerpc.c	27 Jun 2002 10:45:17 -0000
@@ -50,7 +50,8 @@ powerpc_compatible (a,b)
 
 const bfd_arch_info_type bfd_powerpc_archs[] =
 {
-#if BFD_DEFAULT_TARGET_SIZE == 64 /* default arch must come first.  */
+#if BFD_DEFAULT_TARGET_SIZE == 64
+  /* Default arch must come first.  */
   {
     64,	/* 64 bits in a word */
     64,	/* 64 bits in an address */
@@ -65,6 +66,8 @@ const bfd_arch_info_type bfd_powerpc_arc
     bfd_default_scan,
     &bfd_powerpc_archs[1]
   },
+  /* elf32-ppc:ppc_elf_object_p relies on the default 32 bit arch
+     being immediately after the 64 bit default.  */
   {
     32,	/* 32 bits in a word */
     32,	/* 32 bits in an address */
@@ -80,6 +83,7 @@ const bfd_arch_info_type bfd_powerpc_arc
     &bfd_powerpc_archs[2],
   },
 #else
+  /* Default arch must come first.  */
   {
     32,	/* 32 bits in a word */
     32,	/* 32 bits in an address */
@@ -94,6 +98,8 @@ const bfd_arch_info_type bfd_powerpc_arc
     bfd_default_scan,
     &bfd_powerpc_archs[1],
   },
+  /* elf64-ppc:ppc64_elf_object_p relies on the default 64 bit arch
+     being immediately after the 32 bit default.  */
   {
     64,	/* 64 bits in a word */
     64,	/* 64 bits in an address */
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.46
diff -u -p -r1.46 elf32-ppc.c
--- bfd/elf32-ppc.c	25 Jun 2002 06:21:52 -0000	1.46
+++ bfd/elf32-ppc.c	27 Jun 2002 10:45:27 -0000
@@ -43,6 +43,7 @@ static boolean ppc_elf_relax_section
   PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));
 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
+static boolean ppc_elf_object_p PARAMS ((bfd *));
 static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
 static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
 
@@ -1380,6 +1381,27 @@ ppc_elf_addr16_ha_reloc (abfd, reloc_ent
   return bfd_reloc_continue;
 }
 
+/* Fix bad default arch selected for a 32 bit input bfd when the
+   default is 64 bit.  */
+
+static boolean
+ppc_elf_object_p (abfd)
+     bfd *abfd;
+{
+  if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
+    {
+      Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
+
+      if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
+	{
+	  /* Relies on arch after 64 bit default being 32 bit default.  */
+	  abfd->arch_info = abfd->arch_info->next;
+	  BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
+	}
+    }
+  return true;
+}
+
 /* Function to set whether a module needs the -mrelocatable bit set.  */
 
 static boolean
@@ -3797,6 +3819,7 @@ ppc_elf_grok_psinfo (abfd, note)
 #define bfd_elf32_bfd_set_private_flags		ppc_elf_set_private_flags
 #define bfd_elf32_bfd_final_link		_bfd_elf32_gc_common_final_link
 
+#define elf_backend_object_p			ppc_elf_object_p
 #define elf_backend_gc_mark_hook		ppc_elf_gc_mark_hook
 #define elf_backend_gc_sweep_hook		ppc_elf_gc_sweep_hook
 #define elf_backend_section_from_shdr		ppc_elf_section_from_shdr
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.53
diff -u -p -r1.53 elf64-ppc.c
--- bfd/elf64-ppc.c	25 Jun 2002 09:40:43 -0000	1.53
+++ bfd/elf64-ppc.c	27 Jun 2002 10:45:31 -0000
@@ -57,6 +57,8 @@ static bfd_reloc_status_type ppc64_elf_u
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
 static void ppc64_elf_get_symbol_info
   PARAMS ((bfd *, asymbol *, symbol_info *));
+static boolean ppc64_elf_object_p
+  PARAMS ((bfd *));
 static boolean ppc64_elf_set_private_flags
   PARAMS ((bfd *, flagword));
 static boolean ppc64_elf_merge_private_bfd_data
@@ -1649,6 +1651,27 @@ ppc64_elf_get_symbol_info (abfd, symbol,
     ret->type = (symbol->flags & BSF_GLOBAL) != 0 ? 'D' : 'd';
 }
 
+/* Fix bad default arch selected for a 64 bit input bfd when the
+   default is 32 bit.  */
+
+static boolean
+ppc64_elf_object_p (abfd)
+     bfd *abfd;
+{
+  if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32)
+    {
+      Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
+
+      if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
+	{
+	  /* Relies on arch after 32 bit default being 64 bit default.  */
+	  abfd->arch_info = abfd->arch_info->next;
+	  BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
+	}
+    }
+  return true;
+}
+
 /* Function to set whether a module needs the -mrelocatable bit set.  */
 
 static boolean
@@ -6140,6 +6163,7 @@ ppc64_elf_finish_dynamic_sections (outpu
 #define bfd_elf64_bfd_link_hash_table_free    ppc64_elf_link_hash_table_free
 #define bfd_elf64_get_symbol_info	      ppc64_elf_get_symbol_info
 
+#define elf_backend_object_p		      ppc64_elf_object_p
 #define elf_backend_section_from_shdr	      ppc64_elf_section_from_shdr
 #define elf_backend_create_dynamic_sections   ppc64_elf_create_dynamic_sections
 #define elf_backend_copy_indirect_symbol      ppc64_elf_copy_indirect_symbol


-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]