What is absolute symbol and how to define it in C?

房东的猫 提交于 2019-12-01 23:13:45

问题


In the man page of nm. It says

“A” The symbol's value is absolute, and will not be changed by further linking.

However, I don't know what that means. How can I define a variable or something else to make its value absolute in C?

If I declare a variable in test.c in its file scope

int a;

Then in the output of nm, the entry for a will be the following on my machine

0000000000000004 C a

So I'm wondering what can I do to make the nm output “A” for a variable. And I don't know what “absolute” means.


回答1:


When C compiler compiles your program, it produces a list of symbols in addition to the binary code of your program. The most common types that you are going to see are Us (for "undefined"), Ds and Ss (for global data), and Ts (for "text" segment, which is where the executable code goes).

As, or absolute (un-moveable) symbols are there to support embedded development, where placement of things at absolute addresses in memory is required. Normally you would produce such symbols only when cross-compiling for an embedded system, using C language extensions that let you specify the absolute address. A typical syntax would look like this:

unsigned char buf[128]@0x2000;

This is not a standard C, though, it's an extension for embedded systems. The code like this would produce an absolute symbol buf set at address 0x2000, which cannot be moved by linker.



来源:https://stackoverflow.com/questions/33324076/what-is-absolute-symbol-and-how-to-define-it-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!