Strogian
06-09-2003, 10:07 AM
I'm reading this (http://www.iecc.com/linker/linker03.html), reading about linkers, symbol tables, relocation, etc. Specifically, the Unix a.out format, but it probably doesn't matter.
First question -- in defining a global variable 'static' (in C code; e.g. static int bob=5, put outside any function), I would think that the compiler would basically treat it as global data that is only accessed only from the functions within that file (i.e. no symbol defined for it). But then I looked at an ELF object, and it looks like it actually *does* define a symbol for it. Could anyone tell me what this symbol is for? And if I compile two .o files together with the same "global static" defined, the output will end up having two symbols with the same name!
My second question is about what happens to symbol tables, etc. during linking. Let's say I'm linking two object files together, not to produce an executable, but just to merge the two files. (i.e. producing relocatable output) Well, that probably doesn't matter anyway... Would the relocation and symbol tables of the output just be the two input files' tables put together, but with the addresses in the tables changed to reflect the new positions in the output file? Well, I guess the symbol table would not be that exactly; if the symbol was present in both files, they would be merged into one entry saying whether it was defined in either file. But other than that? That would make sense to me, except for the debugging symbols, because of this line from the book confusing me (the bold line):
...The rest of the bits are the symbol type. The most important types include:
text, data, or bss: A symbol defined in this module. External bit may or may not be on. Value is the relocatable address in the module corresponding to the symbol.
abs: An absolute non-relocatable symbol. (Rare outside of debugger info.) External bit may or may not be on. Value is the absolute value of the symbol.
undefined: A symbol not defined in this module. External bit must be on. Value is usually zero, but see the ``common block hack'' below.
An absolute non-relocatable symbol? Wouldn't that mean that once it's linked, the Value would be invalid? Or does that just mean that the Value is just a number, and not actually an address?
One other thing that went through my mind was that, once you've linked two object files together, there's no way to "un-link" them, right? It's not like there's two 'sections' in the output file or something, right?
Maybe if I knew what the debugging symbols actually *did*, I'd know what he was talking about. :)
First question -- in defining a global variable 'static' (in C code; e.g. static int bob=5, put outside any function), I would think that the compiler would basically treat it as global data that is only accessed only from the functions within that file (i.e. no symbol defined for it). But then I looked at an ELF object, and it looks like it actually *does* define a symbol for it. Could anyone tell me what this symbol is for? And if I compile two .o files together with the same "global static" defined, the output will end up having two symbols with the same name!
My second question is about what happens to symbol tables, etc. during linking. Let's say I'm linking two object files together, not to produce an executable, but just to merge the two files. (i.e. producing relocatable output) Well, that probably doesn't matter anyway... Would the relocation and symbol tables of the output just be the two input files' tables put together, but with the addresses in the tables changed to reflect the new positions in the output file? Well, I guess the symbol table would not be that exactly; if the symbol was present in both files, they would be merged into one entry saying whether it was defined in either file. But other than that? That would make sense to me, except for the debugging symbols, because of this line from the book confusing me (the bold line):
...The rest of the bits are the symbol type. The most important types include:
text, data, or bss: A symbol defined in this module. External bit may or may not be on. Value is the relocatable address in the module corresponding to the symbol.
abs: An absolute non-relocatable symbol. (Rare outside of debugger info.) External bit may or may not be on. Value is the absolute value of the symbol.
undefined: A symbol not defined in this module. External bit must be on. Value is usually zero, but see the ``common block hack'' below.
An absolute non-relocatable symbol? Wouldn't that mean that once it's linked, the Value would be invalid? Or does that just mean that the Value is just a number, and not actually an address?
One other thing that went through my mind was that, once you've linked two object files together, there's no way to "un-link" them, right? It's not like there's two 'sections' in the output file or something, right?
Maybe if I knew what the debugging symbols actually *did*, I'd know what he was talking about. :)