public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add support for ARM AAPCS R_ARM_V4BX relocation type
@ 2005-01-28 15:24 Julian Brown
  2005-01-28 15:31 ` Richard Earnshaw
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Julian Brown @ 2005-01-28 15:24 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1469 bytes --]

Hi,

This patch adds support for the R_ARM_V4BX relocation type to bfd and 
ld. This allows objects compiled for the ARMv4 architecture to be 
interworking-safe when linked with other objects compiled for ARMv4t, 
but also allows pure ARMv4 binaries to be built from the same ARMv4 objects.

In the latter case, the switch "--fix-v4bx" must be passed to the 
linker, which causes v4t "BX rM" instructions to be rewritten as "MOV 
PC,rM", since v4 processors do not have a BX instruction.

In the former case, the switch should not be used, and R_ARM_V4BX 
relocations are ignored.

Tested on i686-pc-linux-gnu and arm-none-eabi.

ChangeLog:

	* bfd/bin-in.h (bfd_elf32_arm_set_target_relocs): Update
	prototype.
	* bfd/bin-in2.h (bfd_elf32_arm_set_target_relocs): Update
	prototype.
	* bfd/elf32-arm.c (elf32_arm_link_hash_table): Add fix_v4bx
	flag.
	(bfd_elf32_arm_set_target_relocs): Add formal parameter fix_v4bx
	for passing flag value from ld. Set flag value in global hash
	table entry.
	(elf32_arm_final_link_relocate): Add code to implement
	R_ARM_V4BX relocation.
	* ld/emultempl/armelf.em (fix_v4bx): New variable.
	(arm_elf_create_output_section_statements): Communicate fix_v4bx
	flag value to bfd.
	(PARSE_AND_LIST_PROLOGUE): Add option token OPTION_FIX_V4BX.
	(PARSE_AND_LIST_LONGOPTS): Add option --fix-v4bx.
	(PARSE_AND_LIST_OPTIONS): Add option --fix-v4bx.
	(PARSE_AND_LIST_ARGS_CASES): Add option OPTION_FIX_V4BX.

-- 
Julian Brown
CodeSourcery, LLC

[-- Attachment #2: binutils-patch-2 --]
[-- Type: text/plain, Size: 6333 bytes --]

? bfd/doc/bfd.info
? bfd/doc/bfd.info-1
? gas/doc/as.info
? gas/doc/as.info-1
Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.90
diff -c -p -r1.90 bfd-in.h
*** bfd/bfd-in.h	30 Nov 2004 17:45:53 -0000	1.90
--- bfd/bfd-in.h	27 Jan 2005 21:24:02 -0000
*************** extern bfd_boolean bfd_elf32_arm_process
*** 817,823 ****
    (bfd *, struct bfd_link_info *, int);
  
  void bfd_elf32_arm_set_target_relocs
!   (struct bfd_link_info *, int, char *);
  
  extern bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
    (bfd *, struct bfd_link_info *);
--- 817,823 ----
    (bfd *, struct bfd_link_info *, int);
  
  void bfd_elf32_arm_set_target_relocs
!   (struct bfd_link_info *, int, char *, int);
  
  extern bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
    (bfd *, struct bfd_link_info *);
Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.317
diff -c -p -r1.317 bfd-in2.h
*** bfd/bfd-in2.h	25 Jan 2005 20:22:20 -0000	1.317
--- bfd/bfd-in2.h	27 Jan 2005 21:24:06 -0000
*************** extern bfd_boolean bfd_elf32_arm_process
*** 824,830 ****
    (bfd *, struct bfd_link_info *, int);
  
  void bfd_elf32_arm_set_target_relocs
!   (struct bfd_link_info *, int, char *);
  
  extern bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
    (bfd *, struct bfd_link_info *);
--- 824,830 ----
    (bfd *, struct bfd_link_info *, int);
  
  void bfd_elf32_arm_set_target_relocs
!   (struct bfd_link_info *, int, char *, int);
  
  extern bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
    (bfd *, struct bfd_link_info *);
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.17
diff -c -p -r1.17 elf32-arm.c
*** bfd/elf32-arm.c	26 Jan 2005 06:10:43 -0000	1.17
--- bfd/elf32-arm.c	27 Jan 2005 21:24:21 -0000
*************** struct elf32_arm_link_hash_table
*** 1165,1170 ****
--- 1165,1173 ----
      /* The relocation to use for R_ARM_TARGET2 relocations.  */
      int target2_reloc;
  
+     /* Nonzero to fix BX instructions for ARMv4 targets.  */
+     int fix_v4bx;
+ 
      /* The number of bytes in the initial entry in the PLT.  */
      bfd_size_type plt_header_size;
  
*************** error_return:
*** 1931,1937 ****
  void
  bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
  				 int target1_is_rel,
! 				 char * target2_type)
  {
    struct elf32_arm_link_hash_table *globals;
  
--- 1934,1941 ----
  void
  bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
  				 int target1_is_rel,
! 				 char * target2_type,
!                                  int fix_v4bx)
  {
    struct elf32_arm_link_hash_table *globals;
  
*************** bfd_elf32_arm_set_target_relocs (struct 
*** 1949,1954 ****
--- 1953,1959 ----
        _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
  			  target2_type);
      }
+   globals->fix_v4bx = fix_v4bx;
  }
  #endif
  
*************** elf32_arm_final_link_relocate (reloc_how
*** 2985,2990 ****
--- 2990,3011 ----
      case R_ARM_RBASE:
        return bfd_reloc_notsupported;
  
+     case R_ARM_V4BX:
+       if (globals->fix_v4bx)
+         {
+           bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
+ 
+           /* Ensure that we have a BX instruction.  */
+           BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
+ 
+           /* Preserve Rm (lowest four bits) and the condition code
+              (highest four bits). Other bits encode MOV PC,Rm.  */
+           insn = (insn & 0xf000000f) | 0x01a0f000;
+ 
+           bfd_put_32 (input_bfd, insn, hit_data);
+         }
+       return bfd_reloc_ok;
+ 
      default:
        return bfd_reloc_notsupported;
      }
Index: ld/emultempl/armelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/armelf.em,v
retrieving revision 1.42
diff -c -p -r1.42 armelf.em
*** ld/emultempl/armelf.em	30 Nov 2004 17:45:54 -0000	1.42
--- ld/emultempl/armelf.em	27 Jan 2005 21:24:28 -0000
*************** static bfd *bfd_for_interwork;
*** 30,35 ****
--- 30,36 ----
  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 void
  gld${EMULATION_NAME}_before_parse (void)
*************** arm_elf_finish (void)
*** 189,195 ****
  static void
  arm_elf_create_output_section_statements (void)
  {
!   bfd_elf32_arm_set_target_relocs (&link_info, target1_is_rel, target2_type);
  }
  
  EOF
--- 190,197 ----
  static void
  arm_elf_create_output_section_statements (void)
  {
!   bfd_elf32_arm_set_target_relocs (&link_info, target1_is_rel, target2_type,
!                                    fix_v4bx);
  }
  
  EOF
*************** PARSE_AND_LIST_PROLOGUE='
*** 203,208 ****
--- 205,211 ----
  #define OPTION_TARGET1_REL		303
  #define OPTION_TARGET1_ABS		304
  #define OPTION_TARGET2			305
+ #define OPTION_FIX_V4BX                 306
  '
  
  PARSE_AND_LIST_SHORTOPTS=p
*************** PARSE_AND_LIST_LONGOPTS='
*** 214,219 ****
--- 217,223 ----
    { "target1-rel", no_argument, NULL, OPTION_TARGET1_REL},
    { "target1-abs", no_argument, NULL, OPTION_TARGET1_ABS},
    { "target2", required_argument, NULL, OPTION_TARGET2},
+   { "fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
  '
  
  PARSE_AND_LIST_OPTIONS='
*************** PARSE_AND_LIST_OPTIONS='
*** 222,227 ****
--- 226,232 ----
    fprintf (file, _("     --target1=rel            Interpret R_ARM_TARGET1 as R_ARM_REL32\n"));
    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"));
  '
  
  PARSE_AND_LIST_ARGS_CASES='
*************** PARSE_AND_LIST_ARGS_CASES='
*** 248,253 ****
--- 253,262 ----
      case OPTION_TARGET2:
        target2_type = optarg;
        break;
+ 
+     case OPTION_FIX_V4BX:
+       fix_v4bx = 1;
+       break;
  '
  
  # We have our own after_open and before_allocation functions, but they call

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-01-30  6:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-28 15:24 [PATCH] Add support for ARM AAPCS R_ARM_V4BX relocation type Julian Brown
2005-01-28 15:31 ` Richard Earnshaw
2005-01-28 15:35 ` Ian Lance Taylor
2005-01-28 16:27   ` Julian Brown
2005-01-28 16:35     ` Ian Lance Taylor
2005-01-30  6:29 ` Khem Raj

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).