gdb/
[deliverable/binutils-gdb.git] / bfd / elf32-sh-symbian.c
index 477cf243e708a7e6e52e61050ce3cb68d911f622..1f03dbc40e5d3c252707058c40f186780d4ff206 100644 (file)
@@ -1,5 +1,5 @@
 /* Renesas / SuperH specific support for Symbian 32-bit ELF files
 /* Renesas / SuperH specific support for Symbian 32-bit ELF files
-   Copyright 2004, 2005
+   Copyright 2004, 2005, 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Red Hat
 
    Free Software Foundation, Inc.
    Contributed by Red Hat
 
@@ -7,7 +7,7 @@
 
    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
 
    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 2 of the License, or
+   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,
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -17,7 +17,9 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
 
    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.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
 
 /* Stop elf32-sh.c from defining any target vectors.  */
 #define SH_TARGET_ALREADY_DEFINED
 
 /* Stop elf32-sh.c from defining any target vectors.  */
 #define SH_TARGET_ALREADY_DEFINED
@@ -26,8 +28,8 @@
 #include "elf32-sh.c"
 
 
 #include "elf32-sh.c"
 
 
-//#define DEBUG 1
-#define DEBUG 0
+//#define SYMBIAN_DEBUG 1
+#define SYMBIAN_DEBUG 0
 
 #define DIRECTIVE_HEADER       "#<SYMEDIT>#\n"
 #define DIRECTIVE_IMPORT       "IMPORT "
 
 #define DIRECTIVE_HEADER       "#<SYMEDIT>#\n"
 #define DIRECTIVE_IMPORT       "IMPORT "
@@ -36,7 +38,7 @@
 
 /* Macro to advance 's' until either it reaches 'e' or the
    character pointed to by 's' is equal to 'c'.  If 'e' is
 
 /* Macro to advance 's' until either it reaches 'e' or the
    character pointed to by 's' is equal to 'c'.  If 'e' is
-   reached and DEBUG is enabled then the error message 'm'
+   reached and SYMBIAN_DEBUG is enabled then the error message 'm'
    is displayed.  */
 #define SKIP_UNTIL(s,e,c,m)                                    \
   do                                                           \
    is displayed.  */
 #define SKIP_UNTIL(s,e,c,m)                                    \
   do                                                           \
@@ -45,7 +47,7 @@
        ++ s;                                                   \
       if (s >= e)                                              \
        {                                                       \
        ++ s;                                                   \
       if (s >= e)                                              \
        {                                                       \
-          if (DEBUG)                                           \
+          if (SYMBIAN_DEBUG)                                   \
            fprintf (stderr, "Corrupt directive: %s\n", m);     \
          result = FALSE;                                       \
        }                                                       \
            fprintf (stderr, "Corrupt directive: %s\n", m);     \
          result = FALSE;                                       \
        }                                                       \
@@ -63,7 +65,7 @@
        ++ s;                                                   \
       if (s >= e)                                              \
        {                                                       \
        ++ s;                                                   \
       if (s >= e)                                              \
        {                                                       \
-          if (DEBUG)                                           \
+          if (SYMBIAN_DEBUG)                                   \
            fprintf (stderr, "Corrupt directive: %s\n", m);     \
          result = FALSE;                                       \
        }                                                       \
            fprintf (stderr, "Corrupt directive: %s\n", m);     \
          result = FALSE;                                       \
        }                                                       \
@@ -74,7 +76,7 @@
 
 /* Macro to advance 's' until either it reaches 'e' or the
    character pointed to by 's' is not equal to 'c'.  If 'e'
 
 /* Macro to advance 's' until either it reaches 'e' or the
    character pointed to by 's' is not equal to 'c'.  If 'e'
-   is reached and DEBUG is enabled then the error message
+   is reached and SYMBIAN_DEBUG is enabled then the error message
    'm' is displayed.  */
 #define SKIP_WHILE(s,e,c,m)                                    \
   do                                                           \
    'm' is displayed.  */
 #define SKIP_WHILE(s,e,c,m)                                    \
   do                                                           \
@@ -83,7 +85,7 @@
        ++ s;                                                   \
       if (s >= e)                                              \
        {                                                       \
        ++ s;                                                   \
       if (s >= e)                                              \
        {                                                       \
-          if (DEBUG)                                           \
+          if (SYMBIAN_DEBUG)                                   \
            fprintf (stderr, "Corrupt directive: %s\n", m);     \
          result = FALSE;                                       \
        }                                                       \
            fprintf (stderr, "Corrupt directive: %s\n", m);     \
          result = FALSE;                                       \
        }                                                       \
@@ -114,7 +116,7 @@ sh_symbian_import_as (struct bfd_link_info *info, bfd * abfd,
   struct elf_link_hash_entry * new_hash;
   symbol_rename * node;
 
   struct elf_link_hash_entry * new_hash;
   symbol_rename * node;
 
-  if (DEBUG)
+  if (SYMBIAN_DEBUG)
     fprintf (stderr, "IMPORT '%s' AS '%s'\n", current_name, new_name);
 
   for (node = rename_list; node; node = node->next)
     fprintf (stderr, "IMPORT '%s' AS '%s'\n", current_name, new_name);
 
   for (node = rename_list; node; node = node->next)
@@ -132,14 +134,14 @@ sh_symbian_import_as (struct bfd_link_info *info, bfd * abfd,
 
   if ((node = bfd_malloc (sizeof * node)) == NULL)
     {
 
   if ((node = bfd_malloc (sizeof * node)) == NULL)
     {
-      if (DEBUG)
+      if (SYMBIAN_DEBUG)
        fprintf (stderr, "IMPORT AS: No mem for new rename node\n");
       return FALSE;
     }
 
   if ((node->current_name = bfd_malloc (strlen (current_name) + 1)) == NULL)
     {
        fprintf (stderr, "IMPORT AS: No mem for new rename node\n");
       return FALSE;
     }
 
   if ((node->current_name = bfd_malloc (strlen (current_name) + 1)) == NULL)
     {
-      if (DEBUG)
+      if (SYMBIAN_DEBUG)
        fprintf (stderr, "IMPORT AS: No mem for current name field in rename node\n");
       free (node);
       return FALSE;
        fprintf (stderr, "IMPORT AS: No mem for current name field in rename node\n");
       free (node);
       return FALSE;
@@ -149,7 +151,7 @@ sh_symbian_import_as (struct bfd_link_info *info, bfd * abfd,
   
   if ((node->new_name = bfd_malloc (strlen (new_name) + 1)) == NULL)
     {
   
   if ((node->new_name = bfd_malloc (strlen (new_name) + 1)) == NULL)
     {
-      if (DEBUG)
+      if (SYMBIAN_DEBUG)
        fprintf (stderr, "IMPORT AS: No mem for new name field in rename node\n");
       free (node->current_name);
       free (node);
        fprintf (stderr, "IMPORT AS: No mem for new name field in rename node\n");
       free (node->current_name);
       free (node);
@@ -175,7 +177,7 @@ sh_symbian_import_as (struct bfd_link_info *info, bfd * abfd,
 static bfd_boolean
 sh_symbian_import (bfd * abfd ATTRIBUTE_UNUSED, char * name)
 {
 static bfd_boolean
 sh_symbian_import (bfd * abfd ATTRIBUTE_UNUSED, char * name)
 {
-  if (DEBUG)
+  if (SYMBIAN_DEBUG)
     fprintf (stderr, "IMPORT '%s'\n", name);
 
   /* XXX: Generate an import somehow ?  */
     fprintf (stderr, "IMPORT '%s'\n", name);
 
   /* XXX: Generate an import somehow ?  */
@@ -186,7 +188,7 @@ sh_symbian_import (bfd * abfd ATTRIBUTE_UNUSED, char * name)
 static bfd_boolean
 sh_symbian_export (bfd * abfd ATTRIBUTE_UNUSED, char * name)
 {
 static bfd_boolean
 sh_symbian_export (bfd * abfd ATTRIBUTE_UNUSED, char * name)
 {
-  if (DEBUG)
+  if (SYMBIAN_DEBUG)
     fprintf (stderr, "EXPORT '%s'\n", name);
 
   /* XXX: Generate an export somehow ?  */
     fprintf (stderr, "EXPORT '%s'\n", name);
 
   /* XXX: Generate an export somehow ?  */
@@ -225,7 +227,7 @@ sh_symbian_process_embedded_commands (struct bfd_link_info *info, bfd * abfd,
          break;
 
        case 'I':
          break;
 
        case 'I':
-         if (strncmp (s, DIRECTIVE_IMPORT, strlen (DIRECTIVE_IMPORT)))
+         if (! CONST_STRNEQ (s, DIRECTIVE_IMPORT))
            result = FALSE;
          else
            {
            result = FALSE;
          else
            {
@@ -261,12 +263,12 @@ sh_symbian_process_embedded_commands (struct bfd_link_info *info, bfd * abfd,
              name_end_char = * new_name_end;
              * new_name_end = 0;
 
              name_end_char = * new_name_end;
              * new_name_end = 0;
 
-             /* Check to see if 'AS '... is present.  If se we have an IMPORT AS
-                directive, otherwise we have an IMPORT directive.  */
-             if (strncmp (s, DIRECTIVE_AS, strlen (DIRECTIVE_AS)))
+             /* Check to see if 'AS '... is present.  If so we have an
+                IMPORT AS directive, otherwise we have an IMPORT directive.  */
+             if (! CONST_STRNEQ (s, DIRECTIVE_AS))
                {
                  /* Skip the new-line at the end of the name.  */
                {
                  /* Skip the new-line at the end of the name.  */
-                 if (DEBUG && name_end_char != '\n')
+                 if (SYMBIAN_DEBUG && name_end_char != '\n')
                    fprintf (stderr, "IMPORT: No newline at end of directive\n");
                  else
                    s ++;
                    fprintf (stderr, "IMPORT: No newline at end of directive\n");
                  else
                    s ++;
@@ -276,7 +278,7 @@ sh_symbian_process_embedded_commands (struct bfd_link_info *info, bfd * abfd,
                  /* Skip past the NUL character.  */
                  if (* s ++ != 0)
                    {
                  /* Skip past the NUL character.  */
                  if (* s ++ != 0)
                    {
-                     if (DEBUG)
+                     if (SYMBIAN_DEBUG)
                        fprintf (stderr, "IMPORT: No NUL at end of directive\n");
                    }
                }
                        fprintf (stderr, "IMPORT: No NUL at end of directive\n");
                    }
                }
@@ -300,7 +302,7 @@ sh_symbian_process_embedded_commands (struct bfd_link_info *info, bfd * abfd,
                  SKIP_WHILE (s, e, ' ', "IMPORT AS: Current name just followed by spaces");
                  /* Skip past the newline character.  */
                  if (* s ++ != '\n')
                  SKIP_WHILE (s, e, ' ', "IMPORT AS: Current name just followed by spaces");
                  /* Skip past the newline character.  */
                  if (* s ++ != '\n')
-                   if (DEBUG)
+                   if (SYMBIAN_DEBUG)
                      fprintf (stderr, "IMPORT AS: No newline at end of directive\n");
 
                  /* Terminate the current name after having performed the skips.  */
                      fprintf (stderr, "IMPORT AS: No newline at end of directive\n");
 
                  /* Terminate the current name after having performed the skips.  */
@@ -311,7 +313,7 @@ sh_symbian_process_embedded_commands (struct bfd_link_info *info, bfd * abfd,
                  /* The next character should be a NUL.  */
                  if (* s != 0)
                    {
                  /* The next character should be a NUL.  */
                  if (* s != 0)
                    {
-                     if (DEBUG)
+                     if (SYMBIAN_DEBUG)
                        fprintf (stderr, "IMPORT AS: Junk at end of directive\n");
                      result = FALSE;
                    }
                        fprintf (stderr, "IMPORT AS: Junk at end of directive\n");
                      result = FALSE;
                    }
@@ -327,7 +329,7 @@ sh_symbian_process_embedded_commands (struct bfd_link_info *info, bfd * abfd,
          break;
 
        case 'E':
          break;
 
        case 'E':
-         if (strncmp (s, DIRECTIVE_EXPORT, strlen (DIRECTIVE_EXPORT)))
+         if (! CONST_STRNEQ (s, DIRECTIVE_EXPORT))
            result = FALSE;
          else
            {
            result = FALSE;
          else
            {
@@ -355,7 +357,7 @@ sh_symbian_process_embedded_commands (struct bfd_link_info *info, bfd * abfd,
              /* The next character should be a NUL.  */
              if (* s != 0)
                {
              /* The next character should be a NUL.  */
              if (* s != 0)
                {
-                 if (DEBUG)
+                 if (SYMBIAN_DEBUG)
                    fprintf (stderr, "EXPORT: Junk at end of directive\n");
                  result = FALSE;
                }
                    fprintf (stderr, "EXPORT: Junk at end of directive\n");
                  result = FALSE;
                }
@@ -373,7 +375,7 @@ sh_symbian_process_embedded_commands (struct bfd_link_info *info, bfd * abfd,
 
       if (! result)
        {
 
       if (! result)
        {
-         if (DEBUG)
+         if (SYMBIAN_DEBUG)
            fprintf (stderr, "offset into .directive section: %ld\n",
                     (long) (directive - (char *) contents));
          
            fprintf (stderr, "offset into .directive section: %ld\n",
                     (long) (directive - (char *) contents));
          
@@ -390,10 +392,9 @@ sh_symbian_process_embedded_commands (struct bfd_link_info *info, bfd * abfd,
 
 /* Scan a bfd for a .directive section, and if found process it.
    Returns TRUE upon success, FALSE otherwise.  */
 
 /* Scan a bfd for a .directive section, and if found process it.
    Returns TRUE upon success, FALSE otherwise.  */
-bfd_boolean bfd_elf32_sh_symbian_process_directives (struct bfd_link_info *info, bfd * abfd);
 
 
-bfd_boolean
-bfd_elf32_sh_symbian_process_directives (struct bfd_link_info *info, bfd * abfd)
+static bfd_boolean
+sh_symbian_process_directives (bfd *abfd, struct bfd_link_info *info)
 {
   bfd_boolean result = FALSE;
   bfd_byte *  contents;
 {
   bfd_boolean result = FALSE;
   bfd_byte *  contents;
@@ -464,7 +465,7 @@ sh_symbian_relocate_section (bfd *                  output_bfd,
 
          if (ptr->current_hash == NULL)
            {
 
          if (ptr->current_hash == NULL)
            {
-             if (DEBUG)
+             if (SYMBIAN_DEBUG)
                fprintf (stderr, "IMPORT AS: current symbol '%s' does not exist\n", ptr->current_name);
              continue;
            }
                fprintf (stderr, "IMPORT AS: current symbol '%s' does not exist\n", ptr->current_name);
              continue;
            }
@@ -491,11 +492,12 @@ sh_symbian_relocate_section (bfd *                  output_bfd,
              new_sym.st_info  = ELF_ST_INFO (STB_GLOBAL, STT_FUNC);
              new_sym.st_other = ELF_ST_VISIBILITY (STV_DEFAULT);
              new_sym.st_shndx = SHN_UNDEF;
              new_sym.st_info  = ELF_ST_INFO (STB_GLOBAL, STT_FUNC);
              new_sym.st_other = ELF_ST_VISIBILITY (STV_DEFAULT);
              new_sym.st_shndx = SHN_UNDEF;
+             new_sym.st_target_internal = 0;
 
              if (! _bfd_elf_merge_symbol (input_bfd, info,
                                           ptr->new_name, & new_sym,
                                           & psec, & new_value, NULL,
 
              if (! _bfd_elf_merge_symbol (input_bfd, info,
                                           ptr->new_name, & new_sym,
                                           & psec, & new_value, NULL,
-                                          & new_hash, & skip,
+                                          NULL, & new_hash, & skip,
                                           & override, & type_change_ok,
                                           & size_change_ok))
                {
                                           & override, & type_change_ok,
                                           & size_change_ok))
                {
@@ -511,7 +513,7 @@ sh_symbian_relocate_section (bfd *                  output_bfd,
              if (new_hash->dynindx == -1)
                new_hash->def_regular = 1;
 
              if (new_hash->dynindx == -1)
                new_hash->def_regular = 1;
 
-             if (DEBUG)
+             if (SYMBIAN_DEBUG)
                fprintf (stderr, "Created new symbol %s\n", ptr->new_name);
            }
 
                fprintf (stderr, "Created new symbol %s\n", ptr->new_name);
            }
 
@@ -521,7 +523,7 @@ sh_symbian_relocate_section (bfd *                  output_bfd,
              if (* h == new_hash)
                {
                  ptr->new_symndx = h - sym_hashes + num_local_syms;
              if (* h == new_hash)
                {
                  ptr->new_symndx = h - sym_hashes + num_local_syms;
-                 if (DEBUG)
+                 if (SYMBIAN_DEBUG)
                    fprintf (stderr, "Converted new hash to index of %ld\n", ptr->new_symndx);
                  break;
                }
                    fprintf (stderr, "Converted new hash to index of %ld\n", ptr->new_symndx);
                  break;
                }
@@ -539,7 +541,7 @@ sh_symbian_relocate_section (bfd *                  output_bfd,
              new_sym_hashes = bfd_alloc (input_bfd, num_global_syms * sizeof * sym_hashes);
              if (new_sym_hashes == NULL)
                {
              new_sym_hashes = bfd_alloc (input_bfd, num_global_syms * sizeof * sym_hashes);
              if (new_sym_hashes == NULL)
                {
-                 if (DEBUG)
+                 if (SYMBIAN_DEBUG)
                    fprintf (stderr, "Out of memory extending hash table\n");
                  continue;
                }
                    fprintf (stderr, "Out of memory extending hash table\n");
                  continue;
                }
@@ -551,7 +553,7 @@ sh_symbian_relocate_section (bfd *                  output_bfd,
 
              ptr->new_symndx = num_global_syms - 1 + num_local_syms;
 
 
              ptr->new_symndx = num_global_syms - 1 + num_local_syms;
 
-             if (DEBUG)
+             if (SYMBIAN_DEBUG)
                fprintf (stderr, "Extended symbol hash table to insert new symbol as index %ld\n",
                         ptr->new_symndx);
            }
                fprintf (stderr, "Extended symbol hash table to insert new symbol as index %ld\n",
                         ptr->new_symndx);
            }
@@ -601,9 +603,10 @@ sh_symbian_relocate_section (bfd *                  output_bfd,
            if (h == ptr->current_hash)
              {
                BFD_ASSERT (ptr->new_symndx);
            if (h == ptr->current_hash)
              {
                BFD_ASSERT (ptr->new_symndx);
-               if (DEBUG)
+               if (SYMBIAN_DEBUG)
                  fprintf (stderr, "convert reloc %lx from using index %ld to using index %ld\n",
                  fprintf (stderr, "convert reloc %lx from using index %ld to using index %ld\n",
-                          (long) rel->r_info, (long) ELF32_R_SYM (rel->r_info), ptr->new_symndx);
+                          (unsigned long) rel->r_info,
+                          (long) ELF32_R_SYM (rel->r_info), ptr->new_symndx);
                rel->r_info = ELF32_R_INFO (ptr->new_symndx, r_type);
                break;
              }
                rel->r_info = ELF32_R_INFO (ptr->new_symndx, r_type);
                break;
              }
@@ -614,18 +617,12 @@ sh_symbian_relocate_section (bfd *                  output_bfd,
                                  contents, relocs, local_syms, local_sections);
 }
 
                                  contents, relocs, local_syms, local_sections);
 }
 
-static bfd_boolean
-sh_symbian_check_directives (bfd *abfd, struct bfd_link_info *info)
-{
-  return bfd_elf32_sh_symbian_process_directives (info, abfd);
-}
-
 #define TARGET_LITTLE_SYM      bfd_elf32_shl_symbian_vec
 #define TARGET_LITTLE_NAME      "elf32-shl-symbian"
 
 #undef  elf_backend_relocate_section
 #define elf_backend_relocate_section   sh_symbian_relocate_section
 #undef  elf_backend_check_directives
 #define TARGET_LITTLE_SYM      bfd_elf32_shl_symbian_vec
 #define TARGET_LITTLE_NAME      "elf32-shl-symbian"
 
 #undef  elf_backend_relocate_section
 #define elf_backend_relocate_section   sh_symbian_relocate_section
 #undef  elf_backend_check_directives
-#define elf_backend_check_directives    sh_symbian_check_directives
+#define elf_backend_check_directives    sh_symbian_process_directives
 
 #include "elf32-target.h"
 
 #include "elf32-target.h"
This page took 0.031639 seconds and 4 git commands to generate.