putting stuff in the text segment

Stephen J. Friedl friedl at vsi.UUCP
Fri May 27 03:50:06 AEST 1988


In article <523 at unh.UUCP>, jeff at unh.UUCP (Jeefrey E. F. Friedl) writes:
> In article <3813 at lynx.UUCP>, m5 at 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 at vsi.com    {backbones}!vsi.com!friedl   attmail!vsi!friedl

I'm jeff at unh's brother but I'm not proud of it.



More information about the Comp.lang.c mailing list