Date: Tue, 01 Sep 1998 18:40:42 +0000 From: Mike Smith <mike@smith.net.au> To: John Polstra <jdp@polstra.com> Cc: Mike Smith <mike@smith.net.au>, "Andrew Reilly" <reilly@zeta.org.au>, current@FreeBSD.ORG Subject: Re: ELF binaries size Message-ID: <199809011840.SAA02659@dingo.cdrom.com> In-Reply-To: Your message of "Tue, 01 Sep 1998 18:34:11 MST." <199809020134.SAA16805@austin.polstra.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> > > > No, we map both text and data read-only. > > > > > > No, the text is read-only and the data is copy-on-write. > > > > Is this an ELF requirement, or just an arbitrary change? > > 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) dingo:/tmp>nm a.out | sort 00001020 F /usr/lib/aout/crt0.o 00001020 T start 00001560 F /var/tmp/ccMd26351.o 00001560 t gcc2_compiled. 00001568 T _main 00001580 F __main.o 00001580 T ___do_global_dtors 000015a8 T ___do_global_ctors 000015f4 T ___main 00001620 F _exit.o 00001940 T _etext 00002000 d __DYNAMIC 0000207c D ___progname 0000208c D _foo 0000209c D __exit_dummy_ref 000020ac D __exit_dummy_decl 000020bc D _edata 000020c4 B ___DTOR_LIST__ 000020cc B ___CTOR_LIST__ 000020d4 B ___ldso_version 000020d8 B ___ldso_entry 000020dc B _environ 000020e0 B _errno 000020e4 B _bar 000020e8 B _end As you can see, 'foo' is in the data segment, and it's pretty clearly read-only. If you were to compile with -fwritable_strings, gcc would emit code to copy it to the bss. The data segment only contains constant data, including constant initialisers for non-global initialised variables. As you can see from 'bar', variables live in the bss. -- \\ Sometimes you're ahead, \\ Mike Smith \\ sometimes you're behind. \\ mike@smith.net.au \\ The race is long, and in the \\ msmith@freebsd.org \\ end it's only with yourself. \\ msmith@cdrom.com 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?199809011840.SAA02659>