- 论坛徽章:
- 0
|
本帖最后由 l4rmbr 于 2014-04-23 14:31 编辑
palm008 发表于 2014-04-21 17:59 ![]()
0.11内核中文件Sys.h中定义了一个 fn_ptr sys_call_table[] ={}数组,在System_call.s文件中发现了 call _ ...
Hi, palm008,
简单说,在编译时,编译单元(每一个.c文件, .h文件在预处理阶段已经展开在.c文件里)中的所有全局符号都会保存在符号表里,最终
在链接时根据符号表解析跨单元之间的符号引用。
GCC在生成符号表时,会在每个符号前加一下划线,这个加了下划线的版本,将是在链接阶段看到的版本。GCC有两个选项可以控制这个行为:- -fleading-underscore
- This option and its counterpart, -fno-leading-underscore, forcibly change the way C symbols are represented in the object file. One use is to help link with legacy assembly code.
- Warning: the -fleading-underscore switch causes GCC to generate code that is not binary compatible with code generated without that switch. Use it to conform to a non-default application binary interface. Not all targets provide complete support for this switch.
复制代码 至于为什么要这么做,不直接采用源文件中的符号名。
原因可能是早期,C刚诞生时(用来写unix), 经常要处理与汇编的互动。C源文件单独编译,汇编文件单独编译,最后再链接起来,加个下划线可以有效防止两个名字空间中变量的冲突。 |
|