public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Dave Korn" <dave.korn@artimi.com>
To: "'Virgil Anuichi'" <vanuichi@yahoo.com>,
	"'Alan Modra'" <amodra@bigpond.net.au>
Cc: <binutils@sources.redhat.com>
Subject: RE: wrong initialized global variable (in the wrong section: .bss instead of .data)
Date: Thu, 10 Feb 2005 19:04:00 -0000	[thread overview]
Message-ID: <NUTMEG0goZolmRBaYFk00000025@NUTMEG.CAM.ARTIMI.COM> (raw)
In-Reply-To: <20050210140711.36117.qmail@web21002.mail.yahoo.com>

> -----Original Message-----
> From: binutils-owner On Behalf Of Virgil Anuichi
> Sent: 10 February 2005 14:07

> The initialization is not zero. And that's the
> problem. In fact, a global looking like int foo=0;
> would come up with an undidefined value, in the .bss.

  The .bss section is cleared to zero by the runtime startup code, so I suspect
your problem is to do with that.  Are you using -nostdlib or -nodefaultlibs (or
even -nostartfiles)?  Both those flags exclude the C runtime startup files from
the link.

> I actually dig some more and it's not the linker
> script, rather the compiler. The objdump shows me even
> the .o file has the global in the .bss section. The
> old compiler works fine: it puts it in .data section.
> All initialized globals seem to be put in the .bss
> with the exception of the globals initialized with a
> constant (?).
> For instance int foo=0; ends up in .bss
> while
> int foo1=TICK_1; ends up in .data
> Again, the old gcc compiler sets all of them in .data.

  Above, you said that "the initialisation is not zero", but the example you
have here, you say that zero-inited variables end up in .bss and non-zero-inited
variables end up in .data, and that is the correct behaviour, by design.  If you
wish to change it, the -fno-zero-initialised-in-bss flag that Alan mentioned
will move the zero initialised variables into the .bss section for you.

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....

  reply	other threads:[~2005-02-10 15:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-09 23:03 Virgil Anuichi
2005-02-10  4:25 ` Alan Modra
2005-02-10 17:26   ` Virgil Anuichi
2005-02-10 19:04     ` Dave Korn [this message]
2005-02-10 21:20       ` Dave Korn
2005-02-10 23:40       ` Virgil Anuichi
2005-02-11  0:05         ` Virgil Anuichi
2005-02-11  0:19           ` Virgil Anuichi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=NUTMEG0goZolmRBaYFk00000025@NUTMEG.CAM.ARTIMI.COM \
    --to=dave.korn@artimi.com \
    --cc=amodra@bigpond.net.au \
    --cc=binutils@sources.redhat.com \
    --cc=vanuichi@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).