问题
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