Path: utzoo!attcan!uunet!vsi!friedl From: friedl@vsi.UUCP (Stephen J. Friedl) Newsgroups: comp.lang.c Subject: Re: putting stuff in the text segment Summary: Problems with `cc -R' in BSD Message-ID: <688@vsi.UUCP> Date: 26 May 88 17:50:06 GMT References: <3813@lynx.UUCP> <523@unh.UUCP> Distribution: na Organization: V-Systems, Inc. -- Santa Ana, CA Lines: 37 In article <523@unh.UUCP>, jeff@unh.UUCP (Jeefrey E. F. Friedl) writes: > In article <3813@lynx.UUCP>, m5@lynx.UUCP (Mike McNally) writes: > > [How to put data in the text segment?] > > [...] > If you're using BSD at least, you can just compile the code where the > initialized data is with the -R flag, which is passed to the assembler > and indicates that all ".data" directives should be ".text". Be careful with this: as I recall, *all* initialized statics go into the .text and are readonly. This means that: foo() { static int been_here = 0; if (! been_here) { /* whatever */ been_here++; /* <------ CORE DUMP HERE */ } } core dumps at the "been_here++"; a program can't modify its own .text. My solution was to declare: static int been_here; and rely on the initialization to zero; an uninitialized static always goes into the .bss. This may have changed since 4.2. -- Steve Friedl V-Systems, Inc. (714) 545-6442 3B2-kind-of-guy friedl@vsi.com {backbones}!vsi.com!friedl attmail!vsi!friedl I'm jeff@unh's brother but I'm not proud of it.