问题界面正在标记许多“可能已经有你答案的问题”,但我试图尽职尽责地检查是否有人问我到底在哪里。 如果这是重复,我道歉。
假设我有以下不正确的程序:
extern void undefined_function(void); int main(int argc, char **argv) { undefined_function(); undeclared_function(); exit(0); }用gcc编译给出:
$ gcc warnings.c warnings.c: In function ‘main’: warnings.c:6:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default] /tmp/ccVzjkvX.o: In function `main': warnings.c:(.text+0x15): undefined reference to `undefined_function' warnings.c:(.text+0x1f): undefined reference to `undeclared_function' collect2: ld returned 1 exit status $我知道为什么会发出这些警告,以及如何纠正它们 - 这不是我的问题。
从输出中可以清楚地看出,gcc正在将exit()与其他未定义/未声明的函数区别对待,因为它认为它是“内置函数”
对于给定的gcc,我如何判断gcc认为是“内置函数”的函数列表是什么? 它是c标准库函数列表还是别的?
我考虑做nm libc.so ,但是在我的Ubuntu VM上,这个glibc似乎被剥离了,所以在这方面没有有用的信息:
$ nm /lib/x86_64-linux-gnu/libc.so.6 nm: /lib/x86_64-linux-gnu/libc.so.6: no symbols $The question-asking interface is flagging many "Questions that may already have your answer", but I have attempted to do due diligence to check if any are asking exactly what I am here. My apologies if this is a duplicate.
Suppose I have the following incorrect program:
extern void undefined_function(void); int main(int argc, char **argv) { undefined_function(); undeclared_function(); exit(0); }Compiling with gcc gives:
$ gcc warnings.c warnings.c: In function ‘main’: warnings.c:6:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default] /tmp/ccVzjkvX.o: In function `main': warnings.c:(.text+0x15): undefined reference to `undefined_function' warnings.c:(.text+0x1f): undefined reference to `undeclared_function' collect2: ld returned 1 exit status $I know why these warnings are emitted, and how to correct them - that is not my question.
From the output, it is clear that gcc is treating exit() differently to the other undefined/undeclared functions, because it considers it a "built-in function"
For a given gcc, how can I tell what the list of functions is that gcc considers to be "built-in functions"? Is it exactly the list of c standard library functions or something else?
I considered doing nm libc.so, but on my Ubuntu VM, this glibc appears to be stripped, so there is no useful information there in this regard:
$ nm /lib/x86_64-linux-gnu/libc.so.6 nm: /lib/x86_64-linux-gnu/libc.so.6: no symbols $最满意答案
该列表很长,而且非常特定于平台。 C标准库中的许多(但并非全部)函数(有时)被视为内置函数。 但是,还有一大堆与特定处理器指令和其他硬件功能相关的内置函数。 它们记录在从这里链接的各种页面中; 特别是,请看这里, 这里, 这里, 这里和这里。
The list is quite long, and quite platform-specific. Many (but by no means all) of the functions in the C standard library are (sometimes) treated as built-ins. But there are also a raft of built-in functions that relate to specific processor instructions and other hardware features. They're documented in various pages linked from here; in particular, see here, here, here, here, and here.
更多推荐
发布评论