Patch: HP-UX specific IA64 vector.

Steve Ellcey sje@cup.hp.com
Tue Dec 18 10:58:00 GMT 2001


> > 	* elfxx-ia64.c: Include alloca.h when HAVE_ALLOCA_H is set.
> 
> This bit isn't OK.  Instead, please look at removing uses of alloca in
> elfxx-ia64.c.
> See http://sources.redhat.com/ml/binutils/2001-08/msg00532.html

Thanks for looking at this Alan, I modified elfxx-ia64.c to remove the
two uses of alloca and replaced them with bfd_malloc (and free).  Here
is the modified patch:


2001-12-11  Steve Ellcey  <sje@cup.hp.com>

        * config.bfd (bfd_elf32_ia64_hpux_big_vec, bfd_elf64_ia64_hpux_big_vec):
          New Vectors for ia64*-*-hpux* target.
        * targets.c: Ditto.
        * configure.in: Ditto.
        * configure: Regenerate
        * elfxx-ia64.c: Replace use of alloca with bfd_malloc.
          Set hp-ux specific values for IA64 HP-UX vector.
          (elfNN_hpux_post_process_headers): New function.


--- orig/src/bfd/config.bfd	Tue Dec 18 10:11:34 2001
+++ src/bfd/config.bfd	Tue Dec 18 10:11:53 2001
@@ -99,8 +99,8 @@ case "${targ}" in
     targ_selvecs="bfd_elf64_ia64_big_vec bfd_efi_app_ia64_vec"
     ;;
   ia64*-*-hpux*)
-    targ_defvec=bfd_elf64_ia64_big_vec
-    targ_selvecs="bfd_elf32_ia64_big_vec"
+    targ_defvec=bfd_elf32_ia64_hpux_big_vec
+    targ_selvecs="bfd_elf64_ia64_hpux_big_vec"
     ;;
   sparc64-*-freebsd* | sparc64-*-netbsd*)
     targ_defvec=bfd_elf64_sparc_vec
--- orig/src/bfd/configure.in	Tue Dec 18 10:11:34 2001
+++ src/bfd/configure.in	Tue Dec 18 10:11:53 2001
@@ -554,6 +554,7 @@ do
     bfd_elf32_i860_vec)		tb="$tb elf32-i860.lo elf32.lo $elf" ;;
     bfd_elf32_i960_vec)		tb="$tb elf32-i960.lo elf32.lo $elf" ;;
     bfd_elf32_ia64_big_vec)	tb="$tb elf32-ia64.lo elf32.lo $elf" ;;
+    bfd_elf32_ia64_hpux_big_vec) tb="$tb elf32-ia64.lo elf32.lo $elf";;
     bfd_elf32_little_generic_vec) tb="$tb elf32-gen.lo elf32.lo $elf" ;;
     bfd_elf32_littlearc_vec)	tb="$tb elf32-arc.lo elf32.lo $elf" ;;
     bfd_elf32_littlearm_oabi_vec) tb="$tb elfarm-oabi.lo elf32.lo $elf" ;;
@@ -592,6 +593,7 @@ do
     bfd_elf64_ia64_aix_big_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_aix_little_vec) tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_big_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
+    bfd_elf64_ia64_hpux_big_vec) tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_little_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_little_generic_vec) tb="$tb elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_littlemips_vec) 	tb="$tb elf64-mips.lo elf64.lo elf32-mips.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
--- orig/src/bfd/targets.c	Tue Dec 18 10:11:34 2001
+++ src/bfd/targets.c	Tue Dec 18 10:11:53 2001
@@ -525,6 +525,7 @@ extern const bfd_target bfd_elf32_i860_l
 extern const bfd_target bfd_elf32_i860_vec;
 extern const bfd_target bfd_elf32_i960_vec;
 extern const bfd_target bfd_elf32_ia64_big_vec;
+extern const bfd_target bfd_elf32_ia64_hpux_big_vec;
 extern const bfd_target bfd_elf32_little_generic_vec;
 extern const bfd_target bfd_elf32_littlearc_vec;
 extern const bfd_target bfd_elf32_littlearm_oabi_vec;
@@ -563,6 +564,7 @@ extern const bfd_target bfd_elf64_hppa_v
 extern const bfd_target bfd_elf64_ia64_aix_big_vec;
 extern const bfd_target bfd_elf64_ia64_aix_little_vec;
 extern const bfd_target bfd_elf64_ia64_big_vec;
+extern const bfd_target bfd_elf64_ia64_hpux_big_vec;
 extern const bfd_target bfd_elf64_ia64_little_vec;
 extern const bfd_target bfd_elf64_little_generic_vec;
 extern const bfd_target bfd_elf64_littlemips_vec;
--- orig/src/bfd/elfxx-ia64.c	Tue Dec 18 10:11:34 2001
+++ src/bfd/elfxx-ia64.c	Tue Dec 18 10:15:23 2001
@@ -309,6 +309,8 @@ static boolean elfNN_ia64_print_private_
   PARAMS ((bfd *abfd, PTR ptr));
 static enum elf_reloc_type_class elfNN_ia64_reloc_type_class
   PARAMS ((const Elf_Internal_Rela *));
+static void elfNN_hpux_post_process_headers
+  PARAMS ((bfd *abfd, struct bfd_link_info *info));
 
 /* ia64-specific relocation */
 
@@ -1104,11 +1106,15 @@ elfNN_ia64_final_write_processing (abfd,
 	    {
 	      /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.t.FOO */
 	      size_t len2 = sizeof (".gnu.linkonce.t.") - 1;
-	      char *once_name = alloca (len2 + strlen (sname) - len + 1);
+	      char *once_name = bfd_malloc (len2 + strlen (sname) - len + 1);
 
-	      memcpy (once_name, ".gnu.linkonce.t.", len2);
-	      strcpy (once_name + len2, sname + len);
-	      text_sect = bfd_get_section_by_name (abfd, once_name);
+	      if (once_name != NULL)
+		{
+		  memcpy (once_name, ".gnu.linkonce.t.", len2);
+		  strcpy (once_name + len2, sname + len);
+		  text_sect = bfd_get_section_by_name (abfd, once_name);
+		  free (once_name);
+		}
 	    }
 	  else
 	    /* last resort: fall back on .text */
@@ -1736,6 +1742,7 @@ get_local_sym_hash (ia64_info, abfd, rel
 {
   char *addr_name;
   size_t len;
+  struct elfNN_ia64_local_hash_entry *ret;
 
   /* Construct a string for use in the elfNN_ia64_local_hash_table.
      name describes what was once anonymous memory.  */
@@ -1743,13 +1750,17 @@ get_local_sym_hash (ia64_info, abfd, rel
   len = sizeof (void*)*2 + 1 + sizeof (bfd_vma)*4 + 1 + 1;
   len += 10;	/* %p slop */
 
-  addr_name = alloca (len);
+  addr_name = bfd_malloc (len);
+  if (addr_name == NULL)
+    return 0;
   sprintf (addr_name, "%p:%lx",
 	   (void *) abfd, (unsigned long) ELFNN_R_SYM (rel->r_info));
 
   /* Collect the canonical entry data for this address.  */
-  return elfNN_ia64_local_hash_lookup (&ia64_info->loc_hash_table,
-				       addr_name, create, create);
+  ret = elfNN_ia64_local_hash_lookup (&ia64_info->loc_hash_table,
+				      addr_name, create, create);
+  free (addr_name);
+  return ret;
 }
 
 /* Find and/or create a descriptor for dynamic symbol info.  This will
@@ -4390,6 +4401,17 @@ elfNN_ia64_reloc_type_class (rela)
       return reloc_class_normal;
     }
 }
+
+static void
+elfNN_hpux_post_process_headers (abfd, info)
+	bfd *abfd;
+	struct bfd_link_info *info ATTRIBUTE_UNUSED;
+{
+  Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
+
+  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX;
+  i_ehdrp->e_ident[EI_ABIVERSION] = 1;
+}
 
 #define TARGET_LITTLE_SYM		bfd_elfNN_ia64_little_vec
 #define TARGET_LITTLE_NAME		"elfNN-ia64-little"
@@ -4488,5 +4510,25 @@ elfNN_ia64_reloc_type_class (rela)
 #define bfd_elfNN_bfd_link_add_symbols 	elfNN_ia64_aix_link_add_symbols
 
 #define elfNN_bed elfNN_ia64_aix_bed
+
+#include "elfNN-target.h"
+
+/* HPUX-specific vectors.  */
+
+#undef  TARGET_LITTLE_SYM
+#undef  TARGET_LITTLE_NAME
+#undef  TARGET_BIG_SYM
+#define TARGET_BIG_SYM                  bfd_elfNN_ia64_hpux_big_vec
+#undef  TARGET_BIG_NAME
+#define TARGET_BIG_NAME                 "elfNN-ia64-hpux-big"
+
+#undef  elf_backend_post_process_headers
+#define elf_backend_post_process_headers elfNN_hpux_post_process_headers
+
+#undef  ELF_MAXPAGESIZE
+#define ELF_MAXPAGESIZE                 0x1000  /* 1K */
+
+#undef  elfNN_bed
+#define elfNN_bed elfNN_ia64_hpux_bed
 
 #include "elfNN-target.h"



More information about the Binutils mailing list