assyms.s

M. Warner Losh imp at bsdimp.com
Wed Jul 5 06:14:43 UTC 2006


In message: <2f3a439f0607040654h1983febbhfbceb974e366e855 at mail.gmail.com>
            "Aditya Godbole" <aag.lists at gmail.com> writes:
: I was going through the machine dependant code and found that
: assembler symbols are created using a script that parses symbol names
: taken from an object file. Why is it done this way? Are there any
: advantages of doing this?

genassym is done so that the C compiler can tell us the offsets of
different fields of different structures shared between C and
aseembler code.  This method is done because it doesn't require
execution of a program to determine the offsets.  Once upon a time, it
used to be implemented as something approximating:

	printf("#define FOO_BAR %d\n", offsetof(foo, foo_bar));

but this required execution in the target environment.  When host and
target were the same, this didn't matter.  But when the host is i386
and the target is alpha, for example, the program would produce
different numbers on i386 than on alpha for any data structure that
contained pointers.

The current method of creating a .o file using the target compiler and
then teasing the information out of that .o file generates the same
results on both host and target.  Well, assuming the absense of
compiler bugs for the target compiler running a given host.

Warner


More information about the freebsd-hackers mailing list