From owner-freebsd-current Tue Sep 1 18:44:53 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id SAA10017 for freebsd-current-outgoing; Tue, 1 Sep 1998 18:44:53 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from dingo.cdrom.com (dingo.cdrom.com [204.216.28.145]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id SAA10009 for ; Tue, 1 Sep 1998 18:44:50 -0700 (PDT) (envelope-from mike@dingo.cdrom.com) Received: from dingo.cdrom.com (localhost.cdrom.com [127.0.0.1]) by dingo.cdrom.com (8.9.1/8.8.8) with ESMTP id SAA02659; Tue, 1 Sep 1998 18:40:43 GMT (envelope-from mike@dingo.cdrom.com) Message-Id: <199809011840.SAA02659@dingo.cdrom.com> X-Mailer: exmh version 2.0.2 2/24/98 To: John Polstra cc: Mike Smith , "Andrew Reilly" , current@FreeBSD.ORG Subject: Re: ELF binaries size In-reply-to: Your message of "Tue, 01 Sep 1998 18:34:11 MST." <199809020134.SAA16805@austin.polstra.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 01 Sep 1998 18:40:42 +0000 From: Mike Smith Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > > > 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