[patch][rfc] Complex Relocations gas and bfd

Dave Brolley brolley@redhat.com
Fri Jan 12 23:08:00 GMT 2007


Hi,

The attached patch contains work which is used by the 
soon-to-be-submitted port for Toshiba's MeP architecture, however, it is 
general enough to be considered separately. It is an implementation of 
so-called 'complex relocations'. It allows a fairly rich set of 
expressions on symbols to be specified in the assembler and resolved by 
the linker. Below are some notes which were written by Graydon Hoare, 
the author of the work.

I'm seeking approval to commit.

Dave
----------------------------------------------------------------------------------------------------------------------

the assembler and linker have been modified to support "IEE695-like"
relocations. these are intended to permit arbitrary assembly
expressions, rather than classical symbol+offset relocs, to be saved
for the linker and evaluated at link time.

* the expressions are necessarily communicated by two channels:

** #1: BFD_RELOC_RELC (unsigned) and BFD_RELOC_SRELC (signed) relocs
   themslelves, which we call "complex relocs", which specify the
   beginning bit number, width, word size, chunk size, truncation
   flag, lsb0 value, etc. which are values of the target bit field the
   reloc is supposed to act on.

*** these values are encoded, packed, in the "addend" word (32 bits)
    of a classical ELF reloc with an external reloc type R_RELC or
    R_SRELC.

** #2: the BSF_RELC / STT_RELC (unsigned) and BSF_SRELC / STT_SRELC
   (signed) symbol types, which we call "complex symbols", which
   encode the expression *in* the symbol name as a prefix-notation
   string.

*** the encoding grammar is as follows:

   <node> := <literal>
          |  <unary-operator> ':' <node>
          |  <binary-operator> ':' <node> ':' <node>
	  ;

   <literal> := 's' <digits=N> ':' <N character symbol name>
             |  'S' <digits=N> ':' <N character section name>
	     |  '#' <hexdigits>
	     ;

** these can be combined 3 ways:

*** complex relocs can refer to complex symbols

*** complex relocs can refer to "normal" ELF symbols

*** "normal" ELF relocs can refer to complex symbols

* the actual preservation of expressions as symbols and relocs is done
  in gas/symbols.c and gas/cgen.c. the extraction and evaluation of
  symbols and relocs is done in bfd/elflink.h. the evaluator is simple
  recursive calculator.

* the assembler has been modified to accept "percent functions" of the
form %foo(bleh,blah) which expand to more complex expressions.

* we decided to add a textual substitution pass (macro expansion) to
  the assembly loop. the bodies of the macros are stored in a static
  string table in cgen/cpu/mep.opc and can easily be extended. the
  macro expander is hard-coded into the opc file.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: relc.ChangeLog
URL: <https://sourceware.org/pipermail/binutils/attachments/20070112/67f58df9/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: relc.patch.txt
URL: <https://sourceware.org/pipermail/binutils/attachments/20070112/67f58df9/attachment.txt>


More information about the Binutils mailing list