public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Patch to add ARM Mapping symbols
@ 2000-07-07  2:18 Keith.Walker
  0 siblings, 0 replies; 3+ messages in thread
From: Keith.Walker @ 2000-07-07  2:18 UTC (permalink / raw)
  To: binutils

Attached is a patch which generates the ARM Mapping Symbols, defined in the
ARM ELF Specification, which can be used to determine which areas of a
section contain ARM code, Thumb code or data.

Keith
This patch to the binutils packag provides the ability to create the
ARM Mapping symbols defined in section 5.4.6 in the ARM ELF specification
(which can be found at http://www.arm.com/Documentation/ISTSpecs/ ).

This facility is included by defining the pre-processor symbol
ARM_MAPPING_SYMBOLS.

[The sorting of mapping symbols to before the local symbols (are required
in the ARM ELD specification) is, unfortunately, included in what is
effectively generic code rather than ARM specific code.  Someone who
is more proficient with the source can hopefully identify if there
is a more appropriate place for this code.]


Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.37
diff -c -r1.37 elf.c
*** elf.c	2000/06/19 01:22:37	1.37
--- elf.c	2000/07/05 10:22:52
***************
*** 2130,2135 ****
--- 2130,2160 ----
  	}
      }
  
+ #ifdef ARM_MAPPING_SYMBOLS
+   /* sort mapping symbols before normal local symbols */
+   {
+     int changed;
+     do
+       {
+       changed = 0;
+       for (idx=0; idx <num_locals-1; idx++)
+ 	{
+ 	  if (new_syms[idx]->name[0] != new_syms[idx+1]->name[0]
+ 	    && new_syms[idx+1]->name[0] == '$'
+ 	    && new_syms[idx+1]->name[2] == '\0')
+ 	    {
+ 	      asymbol *sym = new_syms[idx];
+ 	      new_syms[idx] = new_syms[idx+1];
+ 	      new_syms[idx+1] = sym;
+ 	      new_syms[idx]->udata.i = idx+1;
+ 	      new_syms[idx+1]->udata.i = idx+2;
+ 	      changed++;
+ 	    }
+ 	}
+       } while (changed);
+   }
+ #endif
+ 
    bfd_set_symtab (abfd, new_syms, num_locals + num_globals);
  
    elf_num_locals (abfd) = num_locals;
Index: gas/config/tc-arm.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.c,v
retrieving revision 1.49
diff -c -r1.49 tc-arm.c
*** tc-arm.c	2000/07/04 05:49:04	1.49
--- tc-arm.c	2000/07/05 10:22:58
***************
*** 1407,1412 ****
--- 1407,1461 ----
    demand_empty_rest_of_line ();
  }
  
+ #ifdef ARM_MAPPING_SYMBOLS
+ enum mstate { MAP_DATA, MAP_ARM, MAP_THUMB, MAP_THUMB_BL };
+ mapping_state(state)
+      enum mstate state;
+ {
+   static enum mstate mapstate = MAP_DATA;
+   symbolS *symbolP;
+   const char *symname;
+   int type;
+ 
+   switch (state)
+     {
+     case MAP_DATA:
+     case MAP_ARM:
+     case MAP_THUMB:
+       if (mapstate == state)
+ 	return;
+       mapstate = state;
+       break;
+     }
+ 
+   switch (state)
+     {
+     case MAP_DATA:
+       symname = "$d";
+       type = BSF_OBJECT;
+       break;
+     case MAP_ARM:
+       symname = "$a";
+       type = BSF_FUNCTION;
+       break;
+     case MAP_THUMB:
+       symname = "$t";
+       type = BSF_FUNCTION;
+       break;
+     case MAP_THUMB_BL:
+       symname = "$b";
+       type = BSF_FUNCTION;
+       break;
+     default:
+       return;
+     }
+ 
+   symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix(), frag_now);
+   symbol_table_insert (symbolP);
+   symbol_get_bfdsym (symbolP)->flags |= type;
+ }
+ #endif
+ 
  static void
  s_thumb_func (ignore)
       int ignore ATTRIBUTE_UNUSED;
***************
*** 1419,1424 ****
--- 1468,1476 ----
    label_is_thumb_function_name = true;
  
    demand_empty_rest_of_line ();
+ #ifdef ARM_MAPPING_SYMBOLS
+   mapping_state (MAP_THUMB);
+ #endif
  }
  
  /* Perform a .set directive, but also mark the alias as
***************
*** 1576,1581 ****
--- 1628,1636 ----
               coming from ARM mode, which is word-aligned. */
            record_alignment (now_seg, 1);
  	}
+ #ifdef ARM_MAPPING_SYMBOLS
+ 	mapping_state (MAP_THUMB);
+ #endif
        break;
  
      case 32:
***************
*** 1588,1593 ****
--- 1643,1651 ----
              frag_align (2, 0, 0);
            record_alignment (now_seg, 1);
  	}
+ #ifdef ARM_MAPPING_SYMBOLS
+ 	mapping_state (MAP_ARM);
+ #endif
        break;
  
      default:
***************
*** 4839,4844 ****
--- 4897,4906 ----
    if (my_get_expression (& inst.reloc.exp, & str))
      return;
    
+ #ifdef ARM_MAPPING_SYMBOLS
+   mapping_state (MAP_THUMB_BL);
+ #endif
+ 
    inst.reloc.type   = BFD_RELOC_THUMB_PCREL_BRANCH23;
    inst.reloc.pc_rel = 1;
    end_of_line (str);
***************
*** 7338,7343 ****
--- 7400,7409 ----
  
  #ifdef md_cons_align
    md_cons_align (nbytes);
+ #endif
+ 
+ #ifdef ARM_MAPPING_SYMBOLS
+   mapping_state (MAP_DATA);
  #endif
  
    do
Index: gas/config/tc-arm.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.h,v
retrieving revision 1.5
diff -c -r1.5 tc-arm.h
*** tc-arm.h	1999/10/27 18:12:32	1.5
--- tc-arm.h	2000/07/05 10:23:01
***************
*** 208,211 ****
--- 208,212 ----
  #define GLOBAL_OFFSET_TABLE_NAME "__GLOBAL_OFFSET_TABLE_"
  #endif
       
+ #define ARM_MAPPING_SYMBOLS
  /* end of tc-arm.h */

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

* Re: Patch to add ARM Mapping symbols
  2000-07-07 12:33 Nick Clifton
@ 2000-07-10  2:18 ` Keith.Walker
  0 siblings, 0 replies; 3+ messages in thread
From: Keith.Walker @ 2000-07-10  2:18 UTC (permalink / raw)
  To: Nick Clifton, rearnshaw; +Cc: binutils

Nick,

>Thanks very much for submitting this patch.  I have generated a
>slightly tweaked version of the patch (see below) which has two main
>changes:

Thanks for looking at the changes to the mapping symbol patch and making
improvements on them.

>There is one other thng to check though - Keith does the FSF have a
>copyright assignment from you ?  If not then we cannot accept your
>patch :-(

I'm afraid that I hadn't realised the requirement for this when I submitted
this patch .... but Richard has already informed me that I needed to get
one.     Hopefully this will be forthcoming provided once I have been
authorised to sign such an undertaking.

Sorry about that .... I'll let you know as soon as I know what the
situation is.

Keith
Keith Walker		keith.walker@arm.com		Tel:+44 (1628) 427732
ARM Ltd		http://www.arm.com

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

* Re: Patch to add ARM Mapping symbols
@ 2000-07-07 12:33 Nick Clifton
  2000-07-10  2:18 ` Keith.Walker
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2000-07-07 12:33 UTC (permalink / raw)
  To: Keith.Walker, rearnshaw; +Cc: binutils

Hi Keith,

: Attached is a patch which generates the ARM Mapping Symbols, defined
: in the ARM ELF Specification, which can be used to determine which
: areas of a section contain ARM code, Thumb code or data.

Thanks very much for submitting this patch.  I have generated a
slightly tweaked version of the patch (see below) which has two main
changes:

  * The new mapoping symbols are only enabled for the arm-elf
    toolchain, not the arm-coff, or arm-pe or arm-aout toolchains.

  * The new mapping symbols also have the current ARM or Thumb
    attribute set, so that the disassembler can correctly decode the
    resulting binaries.

I am running the testsuites now to see if the patch causes any
unexpected problems, but assuming that these tests pass OK, and unless
anyone has any objections, I would like check the patch in this
weekend.

There is one other thng to check though - Keith does the FSF have a
copyright assignment from you ?  If not then we cannot accept your
patch :-(

Cheers
	Nick


bfd/ChangeLog
2000-07-07  Keith Walker  <Keith.Walker@arm.com>

	* elf.c (elf_map_symbols): Move ARM local mapping symbols
	before other local symbols.

gas/ChangeLog
2000-07-07  Keith Walker  <Keith.Walker@arm.com>

	* config/tc-arm.h (ARM_MAPPING_SYMBOLS): Define if OBJ_ELF.

	* config/tc-arm.c (enum mstate): New enum: mapping state for
	generation of local mapping symbols.
	(mapping_state): New function: Generate a new mapping local
	symbol if the mapping state changes.
	(opcode_select): Call mapping_state.
	(s_thumb_func): Call mapping_state.
	(do_t_branch23): Call mapping_state.
	(s_arm_elf_cons): Call mapping_state.


Index: bfd/elf.c
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elf.c,v
retrieving revision 1.257
diff -p -r1.257 elf.c
*** elf.c	2000/05/31 15:50:13	1.257
--- elf.c	2000/07/07 19:20:31
*************** elf_map_symbols (abfd)
*** 2124,2129 ****
--- 2124,2159 ----
  	}
      }
  
+ #ifdef ARM_MAPPING_SYMBOLS
+   /* Move mapping symbols before normal local symbols.  */
+   {
+     int changed;
+     
+     do
+       {
+ 	changed = 0;
+ 	
+ 	for (idx = 0; idx < num_locals - 1; idx ++)
+ 	  {
+ 	    if (new_syms[idx]->name[0] != new_syms[idx + 1]->name[0]
+ 		&& new_syms[idx + 1]->name[0] == '$'
+ 		&& new_syms[idx + 1]->name[2] == '\0')
+ 	      {
+ 		asymbol * sym = new_syms[idx];
+ 		
+ 		new_syms[idx] = new_syms[idx + 1];
+ 		new_syms[idx + 1] = sym;
+ 		new_syms[idx]->udata.i = idx + 1;
+ 		new_syms[idx + 1]->udata.i = idx + 2;
+ 		
+ 		changed ++;
+ 	      }
+ 	  }
+       }
+     while (changed);
+   }
+ #endif
+ 
    bfd_set_symtab (abfd, new_syms, num_locals + num_globals);
  
    elf_num_locals (abfd) = num_locals;

Index: gas/config/tc-arm.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gas/config/tc-arm.c,v
retrieving revision 1.140
diff -p -r1.140 tc-arm.c
*** tc-arm.c	2000/07/06 01:01:39	1.140
--- tc-arm.c	2000/07/07 19:20:32
*************** validate_offset_imm (val, hwse)
*** 1580,1585 ****
--- 1580,1674 ----
    return val;
  }
  
+ #ifdef ARM_MAPPING_SYMBOLS
+ enum mstate
+ {
+   MAP_DATA,
+   MAP_ARM,
+   MAP_THUMB,
+   MAP_THUMB_BL
+ };
+ 
+ static void mapping_state PARAMS ((enum mstate));
+ 
+ static void
+ mapping_state (state)
+      enum mstate state;
+ {
+   static enum mstate mapstate = MAP_DATA;
+   symbolS * symbolP;
+   const char * symname;
+   int type;
+ 
+   switch (state)
+     {
+     case MAP_DATA:
+     case MAP_ARM:
+     case MAP_THUMB:
+       if (mapstate == state)
+ 	return;
+       mapstate = state;
+       break;
+       
+     case MAP_THUMB_BL:
+       /* Create a $b symbol for every branch.  */
+       break;
+       
+     default:
+       abort ();
+     }
+ 
+   switch (state)
+     {
+     case MAP_DATA:
+       symname = "$d";
+       type = BSF_OBJECT;
+       break;
+     case MAP_ARM:
+       symname = "$a";
+       type = BSF_FUNCTION;
+       break;
+     case MAP_THUMB:
+       symname = "$t";
+       type = BSF_FUNCTION;
+       break;
+     case MAP_THUMB_BL:
+       symname = "$b";
+       type = BSF_FUNCTION;
+       break;
+     default:
+       return;
+     }
+ 
+   symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
+   symbol_table_insert (symbolP);
+   symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
+   
+   switch (state)
+     {
+     case MAP_ARM:
+       THUMB_SET_FUNC (symbolP, 0);
+       ARM_SET_THUMB (symbolP, 0);
+       ARM_SET_INTERWORK (symbolP, support_interwork);
+       break;
+       
+     case MAP_THUMB:
+       THUMB_SET_FUNC (symbolP, 1);
+       ARM_SET_THUMB (symbolP, 1);
+       ARM_SET_INTERWORK (symbolP, support_interwork);
+       break;
+       
+     case MAP_THUMB_BL:
+       ARM_SET_THUMB (symbolP, thumb_mode);
+       break;
+       
+     case MAP_DATA:
+     default:
+       return;
+     }
+ 
+ }
+ #endif /* ARM_MAPPING_SYMBOLS */
      
  static void
  s_req (a)
*************** s_force_thumb (ignore)
*** 1703,1722 ****
    demand_empty_rest_of_line ();
  }
  
- static void
- s_thumb_func (ignore)
-      int ignore ATTRIBUTE_UNUSED;
- {
-   if (! thumb_mode)
-     opcode_select (16);
-   
-   /* The following label is the name/address of the start of a Thumb function.
-      We need to know this for the interworking support.  */
-   label_is_thumb_function_name = true;
-   
-   demand_empty_rest_of_line ();
- }
- 
  /* Perform a .set directive, but also mark the alias as
     being a thumb function.  */
  
--- 1792,1797 ----
*************** opcode_select (width)
*** 1867,1877 ****
  	{
  	  if (! (cpu_variant & ARM_THUMB))
  	    as_bad (_("selected processor does not support THUMB opcodes"));
  	  thumb_mode = 1;
            /* No need to force the alignment, since we will have been
!              coming from ARM mode, which is word-aligned. */
            record_alignment (now_seg, 1);
  	}
        break;
  
      case 32:
--- 1942,1958 ----
  	{
  	  if (! (cpu_variant & ARM_THUMB))
  	    as_bad (_("selected processor does not support THUMB opcodes"));
+ 	  
  	  thumb_mode = 1;
+ 	  
            /* No need to force the alignment, since we will have been
!              coming from ARM mode, which is word-aligned.  */
            record_alignment (now_seg, 1);
  	}
+       
+ #ifdef ARM_MAPPING_SYMBOLS
+       mapping_state (MAP_THUMB);
+ #endif
        break;
  
      case 32:
*************** opcode_select (width)
*** 1879,1889 ****
--- 1960,1977 ----
  	{
            if ((cpu_variant & ARM_ANY) == ARM_THUMB)
  	    as_bad (_("selected processor does not support ARM opcodes"));
+ 	  
  	  thumb_mode = 0;
+ 	  
            if (!need_pass_2)
              frag_align (2, 0, 0);
+ 	  
            record_alignment (now_seg, 1);
  	}
+       
+ #ifdef ARM_MAPPING_SYMBOLS
+       mapping_state (MAP_ARM);
+ #endif
        break;
  
      default:
*************** s_code (unused)
*** 1927,1932 ****
--- 2015,2038 ----
  }
  
  static void
+ s_thumb_func (ignore)
+      int ignore ATTRIBUTE_UNUSED;
+ {
+   if (! thumb_mode)
+     opcode_select (16);
+   
+   /* The following label is the name/address of the start of a Thumb function.
+      We need to know this for the interworking support.  */
+   label_is_thumb_function_name = true;
+   
+   demand_empty_rest_of_line ();
+   
+ #ifdef ARM_MAPPING_SYMBOLS
+   mapping_state (MAP_THUMB);
+ #endif
+ }
+ 
+ static void
  end_of_line (str)
       char * str;
  {
*************** do_t_branch23 (str)
*** 6747,6752 ****
--- 6853,6862 ----
    if (my_get_expression (& inst.reloc.exp, & str))
      return;
    
+ #ifdef ARM_MAPPING_SYMBOLS
+   mapping_state (MAP_THUMB_BL);
+ #endif
+ 
    inst.reloc.type   = BFD_RELOC_THUMB_PCREL_BRANCH23;
    inst.reloc.pc_rel = 1;
    end_of_line (str);
*************** s_arm_elf_cons (nbytes)
*** 9309,9314 ****
--- 9419,9428 ----
    md_cons_align (nbytes);
  #endif
  
+ #ifdef ARM_MAPPING_SYMBOLS
+   mapping_state (MAP_DATA);
+ #endif
+   
    do
      {
        bfd_reloc_code_real_type reloc;

Index: gas/config/tc-arm.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gas/config/tc-arm.h,v
retrieving revision 1.40
diff -p -r1.40 tc-arm.h
*** tc-arm.h	1999/10/27 11:08:07	1.40
--- tc-arm.h	2000/07/07 19:20:32
*************** void armelf_frob_symbol PARAMS ((symbolS
*** 204,209 ****
--- 204,210 ----
       
  #ifdef OBJ_ELF
  #define GLOBAL_OFFSET_TABLE_NAME "_GLOBAL_OFFSET_TABLE_"
+ #define ARM_MAPPING_SYMBOLS
  #else
  #define GLOBAL_OFFSET_TABLE_NAME "__GLOBAL_OFFSET_TABLE_"
  #endif

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

end of thread, other threads:[~2000-07-10  2:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-07  2:18 Patch to add ARM Mapping symbols Keith.Walker
2000-07-07 12:33 Nick Clifton
2000-07-10  2:18 ` Keith.Walker

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).