|
From: Paul M. <pa...@sa...> - 2008-05-17 05:57:08
|
Florian Krohm writes:
> On Thursday 15 May 2008 2:20:50 pm Bart Van Assche wrote:
> > On Wed, May 14, 2008 at 10:41 PM, Florian Krohm <br...@ac...> wrote:
> > > But, the more I think of it the more I get convinced that these
> > > OFFSETs need to be computed by the target compiler.
> >
> > I agree. But I can't imagine any way to get offsetof() values out of a
> > cross-compiler in a portable way (i.e. without relying on nm or
> > libbfd).
>
> Correct.
I missed Bart's message so I'll respond to this one.
It can be done if you're willing to require the use of gcc (or
compilers that implement gcc-style asm statements) when
cross-compiling.
Basically you use a macro like this:
#define DEFINE(sym, val) \
asm volatile("\n#define " #sym " %0\n" #val : : "i" (val))
then have a file that contains a string of DEFINE calls:
int x(void)
{
DEFINE(FOO, offsetof(struct bar, foo));
}
then compile to assembly, then grep the lines starting with "#define"
from the generated .s file.
Paul.
|