delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/07/23/13:16:51

From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Still a few questions about relocating COFF symbols (dynamic loading)
Date: 23 Jul 2002 09:30:58 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 38
Message-ID: <ahj7oi$jv$1@nets3.rz.RWTH-Aachen.DE>
References: <cd0304ab DOT 0207221344 DOT 2fb8967a AT posting DOT google DOT com>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 1027416658 639 137.226.32.75 (23 Jul 2002 09:30:58 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 23 Jul 2002 09:30:58 GMT
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

dshnv <dshnv AT www DOT com> wrote:
> When I have a source file like this:
> #include <stdio.h>

> char global_data[100] = { 0 };
> int global_bss;

> int main()
> {
>      int foo, bar;

>      printf("%d\n", foo );
> }

> and I perform a objdump file.o, I don't see a _foo or a _bar in the
> relocation or symbol table. 

Of course you don't.  Return to your C textbook and read about the
difference between static and automatic variables to see why.

> I already know that global_bss does not appear in the .bss but is
> defined as member of the [common] section. But I have to reserve
> memory for it anyway, so I thought of appending it at the end of the
> .bss.

You're looking at the wrong file, I think.  Note that file.o is
produced by the compiler alone.  It's the *linker* which will proceed
to put things from [common] into .bss, after having checked for
duplicates, which it would unite.

It may be best to avoid (i.e.: forbid) uninitialized,
non-"static"-qualified file-scope variable definitions like your
"global_bss".  Require them to either be initialized, or explicitly
labelled as private ("static"), or as "extern" to make them
declarations instead of (tentative) definitions.
-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019