2006-02-07 Paul Brook <paul@codesourcery.com>
[external/binutils.git] / ld / emultempl / armelf.em
index 886cf8b..bd74ab5 100644 (file)
 #
 # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 #
 
 # This file is sourced from elf32.em, and defines extra arm-elf
 # specific routines.
 #
-test -z $TARGET2_TYPE && TARGET2_TYPE="rel"
+test -z "$TARGET2_TYPE" && TARGET2_TYPE="rel"
 cat >>e${EMULATION_NAME}.c <<EOF
 
+#include "elf/arm.h"
+
 static char *thumb_entry_symbol = NULL;
 static bfd *bfd_for_interwork;
 static int byteswap_code = 0;
 static int target1_is_rel = 0${TARGET1_IS_REL};
 static char *target2_type = "${TARGET2_TYPE}";
 static int fix_v4bx = 0;
+static int use_blx = 0;
 
 static void
 gld${EMULATION_NAME}_before_parse (void)
@@ -70,24 +73,27 @@ arm_elf_after_open (void)
 static void
 arm_elf_set_bfd_for_interworking (lang_statement_union_type *statement)
 {
-  if (statement->header.type == lang_input_section_enum
-      && !statement->input_section.ifile->just_syms_flag
-      && (statement->input_section.section->flags & SEC_EXCLUDE) == 0)
+  if (statement->header.type == lang_input_section_enum)
     {
       asection *i = statement->input_section.section;
-      asection *output_section = i->output_section;
-
-      ASSERT (output_section->owner == output_bfd);
 
-      /* Don't attach the interworking stubs to a dynamic object, to
-        an empty section, etc.  */
-      if ((output_section->flags & SEC_HAS_CONTENTS) != 0
-         && (i->flags & SEC_NEVER_LOAD) == 0
-         && ! (i->owner->flags & DYNAMIC)
-         && ! i->owner->output_has_begun)
+      if (!((lang_input_statement_type *) i->owner->usrdata)->just_syms_flag
+         && (i->flags & SEC_EXCLUDE) == 0)
        {
-         bfd_for_interwork = i->owner;
-         bfd_for_interwork->output_has_begun = TRUE;
+         asection *output_section = i->output_section;
+
+         ASSERT (output_section->owner == output_bfd);
+
+         /* Don't attach the interworking stubs to a dynamic object, to
+            an empty section, etc.  */
+         if ((output_section->flags & SEC_HAS_CONTENTS) != 0
+             && (i->flags & SEC_NEVER_LOAD) == 0
+             && ! (i->owner->flags & DYNAMIC)
+             && ! i->owner->output_has_begun)
+           {
+             bfd_for_interwork = i->owner;
+             bfd_for_interwork->output_has_begun = TRUE;
+           }
        }
     }
 }
@@ -146,11 +152,25 @@ arm_elf_finish (void)
   /* Call the elf32.em routine.  */
   gld${EMULATION_NAME}_finish ();
 
-  if (thumb_entry_symbol == NULL)
-    return;
+  if (thumb_entry_symbol)
+    {
+      h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
+                               FALSE, FALSE, TRUE);
+    }
+  else
+    {
+      struct elf_link_hash_entry * eh;
+
+      if (!entry_symbol.name)
+       return;
+
+      h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name,
+                               FALSE, FALSE, TRUE);
+      eh = (struct elf_link_hash_entry *)h;
+      if (!h || ELF_ST_TYPE(eh->type) != STT_ARM_TFUNC)
+       return;
+    }
 
-  h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
-                           FALSE, FALSE, TRUE);
 
   if (h != (struct bfd_link_hash_entry *) NULL
       && (h->type == bfd_link_hash_defined
@@ -176,7 +196,8 @@ arm_elf_finish (void)
 
       sprintf_vma (buffer + 2, val);
 
-      if (entry_symbol.name != NULL && entry_from_cmdline)
+      if (thumb_entry_symbol != NULL && entry_symbol.name != NULL
+         && entry_from_cmdline)
        einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
               thumb_entry_symbol, entry_symbol.name);
       entry_symbol.name = buffer;
@@ -192,7 +213,7 @@ static void
 arm_elf_create_output_section_statements (void)
 {
   bfd_elf32_arm_set_target_relocs (&link_info, target1_is_rel, target2_type,
-                                   fix_v4bx);
+                                   fix_v4bx, use_blx);
 }
 
 EOF
@@ -206,7 +227,8 @@ PARSE_AND_LIST_PROLOGUE='
 #define OPTION_TARGET1_REL             303
 #define OPTION_TARGET1_ABS             304
 #define OPTION_TARGET2                 305
-#define OPTION_FIX_V4BX                 306
+#define OPTION_FIX_V4BX                        306
+#define OPTION_USE_BLX                 307
 '
 
 PARSE_AND_LIST_SHORTOPTS=p
@@ -219,6 +241,7 @@ PARSE_AND_LIST_LONGOPTS='
   { "target1-abs", no_argument, NULL, OPTION_TARGET1_ABS},
   { "target2", required_argument, NULL, OPTION_TARGET2},
   { "fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
+  { "use-blx", no_argument, NULL, OPTION_USE_BLX},
 '
 
 PARSE_AND_LIST_OPTIONS='
@@ -228,6 +251,7 @@ PARSE_AND_LIST_OPTIONS='
   fprintf (file, _("     --target1=abs            Interpret R_ARM_TARGET1 as R_ARM_ABS32\n"));
   fprintf (file, _("     --target2=<type>         Specify definition of R_ARM_TARGET2\n"));
   fprintf (file, _("     --fix-v4bx               Rewrite BX rn as MOV pc, rn for ARMv4\n"));
+  fprintf (file, _("     --use-blx                Enable use of BLX instructions\n"));
 '
 
 PARSE_AND_LIST_ARGS_CASES='
@@ -258,6 +282,10 @@ PARSE_AND_LIST_ARGS_CASES='
     case OPTION_FIX_V4BX:
       fix_v4bx = 1;
       break;
+
+    case OPTION_USE_BLX:
+      use_blx = 1;
+      break;
 '
 
 # We have our own after_open and before_allocation functions, but they call