From: NoEmailAds AT execpc DOT com (Chris Giese) Newsgroups: comp.os.msdos.djgpp Subject: Re: Still a few questions about relocating COFF symbols (dynamic loading) Date: Wed, 24 Jul 2002 02:29:00 GMT Organization: PROPULSION GROUP References: X-Newsreader: Forte Free Agent 1.21/32.243 Lines: 57 Message-ID: <3d3e11b2$0$1426$272ea4a1@news.execpc.com> NNTP-Posting-Host: 7f5c161c.news.execpc.com X-Trace: DXC=c>BGW2>Bl69PSWMQ4SPmU>bhiU1EQ[HI=0ICGTaT\Bl==EV;d7?Dn`=e3C>TkR[`^1Y?mT25 AT 5nn6``kKCI57int 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