Re: alias of structure members

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 13/02/12 02:13, Ian Lance Taylor wrote:
> The linker tends to only complain if an undefined symbol is used.  I
> don't know if that explains what you are seeing, but perhaps it does.
>
> Ian
It does. The appearance of working on gcc3 was indeed misleading.
Adding an assignment to Localfoo it relents to produces
 [Linker error] undefined reference to `Foo.Foodata' 


I was finally able to perform the aliasing doing it directly in assembler.
 
For reference , this is what worked for me
#define ALIAS_MEMBER(name, instance,member) \
 static void instance ## __ ## alias__ ## member ## __ ## function
(void) __attribute__((used)); \
 static void instance ## __ ## alias__ ## member ## __ ## function
(void) { \
 const size_t member_offset = offsetof(typeof(instance), member); \
 asm(".global " # member "\n" "\t.set " #name "," #instance " +  %0\n" : \
     /* No output */ : /* input */ "g" ( member_offset ) ); } \
 extern typeof(instance.member) name;
 
Some notes:
 - You need to enable optimizations, so the constant is converted into a
literal (doesn't work in -O0)
 - The instance shall have an initialiser (even if you don't care about
the value), so that
 the variable it's placed in .bss, and not as a .comm (it may produce a
'can't be equated to 
 common symbol' error or silently skip your symbol)
 - It doesn't seem to work for all targets. YMMV.
 


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux