/*
weakref
weakref ("target")
The weakref attribute marks a declaration as a weak reference. Without arguments, it should be accompanied by an alias attribute naming the target symbol. Optionally, the target may be given as an argument to weakref itself. In either case, weakref implicitly marks the declaration as weak. Without a target, given as an argument to weakref or to alias, weakref is equivalent to weak.
static int x() __attribute__ ((weakref ("y")));
// is equivalent to...
static int x() __attribute__ ((weak, weakref, alias ("y")));
// and to...
static int x() __attribute__ ((weakref));
static int x() __attribute__ ((alias ("y")));
A weak reference is an alias that does not by itself require a definition to be given for the target symbol. If the target symbol is only referenced through weak references, then it becomes a weak undefined symbol. If it is directly referenced, however, then such strong references prevail, and a definition is required for the symbol, not necessarily in the same translation unit.
The effect is equivalent to moving all references to the alias to a separate translation unit, renaming the alias to the aliased symbol, declaring it as weak, compiling the two separate translation units and performing a reloadable link on them.
At present, a declaration to which weakref is attached can only be static.
*/
// https://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Function-Attributes.html
// demo.c
//static int foo() __attribute__ ((weakref ("y")));
int foo() __attribute__ ((alias ("y")));
//__attribute__ ((weak)) int foo();
int y(){
puts("xxx");
}
int main()
{
if (foo)
foo();
return 0;
}