c - weak_alias 函数的作用是什么,它在哪里定义

标签 c linux gcc compiler-construction gnu

所以我正在查看 gcc 编译器的源代码,我在 fork.c 中发现了这个:

int
__fork ()
{
  __set_errno (ENOSYS);
  return -1;
}
libc_hidden_def (__fork)
stub_warning (fork)

weak_alias (__fork, fork)
#include <stub-tag.h>

我想弄清楚 weak_alias 的作用。我在 glibc 源文件中使用了 grep 命令来查找所有出现的#define weak_alias:

grep -r "#define weak_alias"

我发现了很多次宏:

#define weak_alias(n, a)

但宏实际上并没有解释任何东西。他们只是定义了那个声明,他们没有显示它是如何被替换的。例如,在 profil.c 中出现了一个:

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

那么知道 weak_alias 的作用以及它的定义位置吗?

提前致谢

最佳答案

来自 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)));

关于弱符号:

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

关于c - weak_alias 函数的作用是什么,它在哪里定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34892601/

相关文章:

c++ - 为什么 SDL 在 Mac 上比 Linux 上慢很多?

c++ - 如何禁用缩小转换警告?

linux - 如何删除文件夹内每个文件上特定颜色的所有像素?

linux - GNU make 中的复杂模式替换

c++ - GCC C++ 名称修改引用

gcc - 为什么这个带有 gcc (clang) 内联汇编的简单 c 程序表现出未定义的行为?

c - 是什么导致程序不遵循循环条件?

c - long long int 初始化警告

c - 了解特定 C 指针定义的学校作业

c - 服务器无法读取给定 HTTP POST 的负载