This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

RE: Gnu assembler question for ARM


On 07 May 2007 08:49, Ciaccia wrote:

> Thanks for the help. I see now the analogy between a normal .text section
> and a .struct one. From what I understand, in both of them is possible to
> define symbols using directives such as ".int" or ".balign", but the
> ".struct" does not generate asm output, while ".text" does... right?   

  Yes, basically, .struct pretends to switch to the absolute section (denoted
by "*ABS*" in output from nm), which is an imaginary section that has a base
address of zero and isn't subject to relocation.  Then the various lines where
you have .int or whatever directives emit symbols and advance the supposed PC
value, so the result is you get absolute symbols for your structure offsets
starting at zero.  These can then be used in operands in the rest of your
regular code.

> Apart from that, I find strange that there is almost no documentation nor
> examples online. I tried with google (standard search, groups, codesearch)
> and koders, but I did not find an example on how to use it. I wonder if
> this feature should not be explained  better...   

  I agree, the documentation is pretty minimal.  Patches would be welcome :)
http://sourceware.org/binutils/docs-2.17/as/Struct.html#Struct

> I still have some unresolved questions (for example, how to nicely nest
> structs, how to sizeof), and an example would really help me. For example,
> what would be the best (cleaner) way to use vector struct defined as
> following?   
> 
> struct point {
>   int x;
>   int y;
> 
>   int z;
> 
> };
> 
> struct vector {
>   struct point v0;
>   struct point v1;
> };


  Well, something like this would work:

	.struct 0
$point$x:	.int	 	0
		.balign	4
$point$y:	.int	 	0
		.balign	4
$point$z:	.int	 	0
		.balign	4
$sz$point$:	.byte	 	0

	.struct 0
$vector$v0:	.skip		$sz$point$
$vector$v1:	.skip		$sz$point$
$sz$vector:	.byte		0


and then you could use expressions like "[R1 + ($vector$v1 + $point$z)]" to
denote struct member access.

  Now it's getting tricky.  What you really want is some automated means in
your build system that would generate the necessary assembler source directly
from the definitions in your header files, so they could never get
out-of-sync.  This could be done in several ways; off the top of my head,
parsing the debug info from the object files, or modifying the compiler to
generate asm fragments that define all the structs would be very comprehensive
approaches to take, or you could come up with a scheme that describes your
structs in text files and uses makefile processing to autogenerate both C
headers with struct definitions and asm includes with the .struct equivalents;
or for a really hacky kludge you could even script gdb to print out loads of
expressions using 'offsetof' and parse the output with sed to make the asm
definitions...



    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


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