C函数语法

时间:2015-05-19 03:41:50

标签: assembly glibc

在此页面上:http://www.scs.stanford.edu/histar/src/pkg/uclibc/libc/sysdeps/linux/x86_64/sigaction.c

我看到这两行:

extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
extern void restore (void) asm ("__restore") attribute_hidden;

这是什么语法?是否将restore_rt设置为内联asm("__restore_rt")作为其正文的函数?

谢谢!

2 个答案:

答案 0 :(得分:3)

显然,这是一种替换C函数的符号名称的方法......

  

为了更改函数的名称,您需要一个原型声明,因为编译器不会在函数定义中接受asm关键字:

extern long Calc(void) asm ("CALCULATE");
  

调用函数Calc()将创建汇编程序指令以调用函数CALCULATE。

this document

中搜索“替换C函数的符号名称”

答案 1 :(得分:3)

在函数声明中使用asm是名为GCCClang/LLVM扩展名(也由asm-label支持)。它设置汇编程序和链接器已知的函数名称。

BTW,代码attribute_hidden可能是某些function attribute的宏,可能是__attribute__ ((visibility ("hidden")))

相关问题