Mail Archives: djgpp/2002/07/23/23:38:32
dshnv AT www DOT com (dshnv) wrote:
{some code}
>int global_bss;
If you use GNU C, non-initialized non-static non-extern globals are
actually "common" variables. The linker allocates space for these,
not the compiler.
Turbo C, Microsoft C, etc. don't support common variables.
>int main()
>{
> int foo, bar;
Auto (non-static local) variables are stored on the stack. They
don't need relocation, so they don't appear in the symbol table
used for relocation. They may appear in one of the _debug_
sections, depending on the debug format used.
>Is it right that I can just leave these _foo and _bar variables alone,
>that I don't have to perform any kind of relocation, but just ignore
>them?
Correct.
>If not, how am I to figure the real size of the .bss if the
>section header sais the .bss is 0 bytes in size.
Your relocation code must support common variables. If not, the
relocatable code can be linked into a new relocatable file
using the "-r" and "-d" options to ld:
ld -d -r -o new_object_file.o object_file.o
>I already know that global_bss does not appear in the .bss but is
>defined as member of the [common] section.
The linker command above combines [common] into .bss for relocatable
files. From the 'ld' info page:
`-d' `-dc' `-dp'
These three options are equivalent; multiple forms are supported
for compatibility with other linkers. They assign space to common
symbols even if a relocatable output file is specified (with
`-r'). The script command `FORCE_COMMON_ALLOCATION' has the same
effect. *Note Miscellaneous Commands::.
And here's a program that loads and runs a relocatable version
of Tetris:
http://www.execpc.com/~geezer/osd/exec/runreloc.zip
It also works with ELF and Win32 PE COFF.
--
geezer@ | http://www.execpc.com/~geezer
execpc.com | http://www.execpc.com/~geezer/osd
- Raw text -