This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch to add ARM Mapping symbols


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]