In the following question I was asked to fill the symbol table, I understand and agree with everything except...
What is that Value field, what it means, why it's always 0 in this example and can someone kindly show a situation where it's not 0?
CodePudding user response:
The Value
is relative to the section (Ndx
) they are defined within, so I think of it is an offset (section relative).
The reason these symbols have value 0 is because they are each the first symbol in the section that they are in!! It is just a coincidence and artifact of these being very small examples.
- In a.asm,
spam
is the first in the data section, so offset 0. - In a.asm,
bar
is the first in the text section, so offset 0. - In b.asm,
spam
is again the first in the data section, so offset 0. - In b.asm,
_start
is the first in the text section, so offset 0. - In b.asm,
bar
is undefined, and so marked in section. There's no meaning to theValue
for something that is undefined, or something that is external.
These symbols are defined as global, which means that the linker can see them and bind imports to exports. However, it does not appear that a.o and b.o are intended to work together, since they each define symbol spam
, which would result in a linkage error if they were linked together into a program.
This example has no imports (but does have an undefined entry, bar
in b.o, though let's note that bar
is not .global or otherwise noted as imported).
(Relocations are another matter but this question doesn't show or ask about them.)
If you had two (or more) symbols where there was least one or more bytes (in any one section, data or text) between them then all symbols beyond the first would have a non-zero Value
.