Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 01 Sep 1998 18:49:49 -0700
From:      John Polstra <jdp@polstra.com>
To:        Mike Smith <mike@smith.net.au>
Cc:        "Andrew Reilly" <reilly@zeta.org.au>, current@FreeBSD.ORG
Subject:   Re: ELF binaries size 
Message-ID:  <199809020149.SAA16932@austin.polstra.com>
In-Reply-To: Your message of "Tue, 01 Sep 1998 18:40:42 -0000." <199809011840.SAA02659@dingo.cdrom.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
> > I don't understand what you're getting at.  A program has to be able
> > to write its data.  That's where the variables are.
> 
> dingo:/tmp>cat a.c 
> char    *foo = "test";
> int	bar;
> void main(void) 
> {
>         foo[0] = 0;
> }
> dingo:/tmp>./a.out 
> Bus error (core dumped)
...
> As you can see, 'foo' is in the data segment, and it's pretty       
> clearly read-only.                                                  

No, foo is writable.  What foo points to is read-only.  Foo is in
the data segment, but what it points to is in the text segment.

There's read-only data (which goes into the text segment), and there's
writable data (which goes into the data segment).  It doesn't have
anything to do with initialization.  What foo points to is read-only
because it's a string constant.

A counter-example to your program above is:

    int foo = 100;
    int
    main(int argc, char **argv)
    {
	foo = 200;
	return 0;
    }

Here foo is initialized, but it is writable.

John
--
   John Polstra                                       jdp@polstra.com
   John D. Polstra & Co., Inc.                Seattle, Washington USA
   "Self-knowledge is always bad news."                 -- John Barth

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809020149.SAA16932>