如何提供的libc职能,两个人的名字? [英] How does libc provide functions with two names?

查看:144
本文介绍了如何提供的libc职能,两个人的名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在直接结合(-B直接)libc中的出现提供了许多
         有两个名字的功能。例如,的getpwent()和_getpwent()。
         这两个名字所指正是libc中的相同的功能。

Before the advent of direct binding (-B direct) libc provided many functions with two names. For example, getpwent() and _getpwent(). These two names referred to exactly the same function in libc.

如何libc中提出两个函数名指向相同的实现?

How does libc make two function names point to the same implementation?

我觉得应该不会像写作一样code虽然两次一样容易。

I think it should not be as easy as writing the same code twice though.

推荐答案

它可以通过完成的弱别名的一个非标准连接把戏,一直围绕年初以来,Unix系统,并可以被所有UNIX编译器/连接器支持我知道。它基本上做的:

It's done via weak aliases a "nonstandard" linker trick that's been around since early unices and that's supported by all unix compilers/linkers I know of. It's basically done as:

void __foo(void);
void foo(void) __attribute__((weak, alias("__foo")));

经常与宏抽象的那么一点点。这使得它,因此象征将具有相同的地址和类型符号 __富默认,但允许它由强的定义在别处被覆盖。

often with macros to abstract it a little bit. This makes it so the symbol foo will have the same address and type as the symbol __foo by default, but allows it to be overridden by a "strong" definition somewhere else.

这篇关于如何提供的libc职能,两个人的名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆