What the weak_alias function does and where it is defined

So, I am browsing the source of the gcc compiler, and I came this way in fork.c:

int __fork () { __set_errno (ENOSYS); return -1; } libc_hidden_def (__fork) stub_warning (fork) weak_alias (__fork, fork) #include <stub-tag.h> 

I'm trying to figure out what weak_alias does. I used the grep command inside the glibc source files to find all occurrences of #define weak_alias:

 grep -r "#define weak_alias" 

I found many macro entries:

 #define weak_alias(n, a) 

but macros do not explain anything. They simply define this statement that they do not show how to replace it. For example, one event occurs in the .c profile:

 /* Turn off the attempt to generate ld aliasing records. */ #undef weak_alias #define weak_alias(a,b) 

So, any ideas what weak_alias does and where are they defined?

Thank you in advance

+5
source share
1 answer

from https://github.com/lattera/glibc/blob/master/include/libc-symbols.h

 /* Define ALIASNAME as a weak alias for NAME. If weak aliases are not available, this defines a strong alias. */ # define weak_alias(name, aliasname) _weak_alias (name, aliasname) # define _weak_alias(name, aliasname) \ extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); 

About the weak character:

https://en.wikipedia.org/wiki/Weak_symbol

+8
source

Source: https://habr.com/ru/post/1240986/


All Articles