putting stuff in the text segment

Jeffrey E. F. Friedl jeff at unh.UUCP
Thu May 26 15:30:09 AEST 1988


In article <3813 at lynx.UUCP>, m5 at lynx.UUCP (Mike McNally) writes:
> Does a widely-accepted syntax extension to put data structures in the
> text segment exist?  We are thinking about adding something like this
> to our compiler in order to reduce memory use by oft-forked large
> applications.  I had in mind a couple of new storage classes, maybe 
> "rom" and "staticrom".

Certainly a nice thing to be able to do. However, not all systems have
ideas about "segments" (under UNIX they usually do, of course, but C has
made its way to a lot of pretty strange places).

Also, using the word "rom" implies that you can't modify the data.
What should happen then if there is an attempt to do this?  Should the
language ensure that any attempt to modify the data will {succeed, crash}?
When you have text segments, are you allowed (by the operating system) to
modify its contents (a different issue from what the *language* specifies)?
And in what cases... All the time (BSD magic number 0407)? None of the time
(BSD magic number 0410,0413)? Some of the time (perhaps on some system where
it depends on the sticky bit or something like that), etc...

These aren't flames, just being a devil's advocate....

However, I get from your posting that you're just doing something that
you need at your site and just wanting to do it the way it's been done
before if it has been done before.

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".
This would *really* screw things up when done with normal code, but with
static data... just what you want.

If not using a system with a -R type flag and if you must hack the compiler,
perhaps at least ensure (mostly) that the programs can still work with a
"standard" compiler with something like

	#ifndef MY_HACKED_COMPILER
	#  define shared
	#endif

	shared struct foo [BIG] {this, that, the other};
	
Then, your comipler would understand "shared" (or whatever you decide
upon) and you would compile with -DMY_HACKED_COMPILER (or have a hacked
cpp do it for you).

	*jeff*

-------------------------------------------------------------------------------
Jeffrey Eric Francis Friedl, Box 2146 Babcock House, Durham New Hampshire 03824
..!{uunet,decvax}!unh!jeff   BITNET%"j_friedl at unhh"  ..!ucbvax!kentvax!jfriedl

I hope I'm not around Jan 18, 2038 at 10:14:08PM
(yes, friedl at vsi is my brother, and he's proud of it).



More information about the Comp.lang.c mailing list