Glenn Fowler wrote:
[CC:'ing some (random) compiler people and the linker alien (rod) to
take a look at this issue]
> I've been at this so long you think I should know better
>
> I've been under the apparently mistaken assumption that
> if I dilligently pepper struct definitions and subsequent
> declarations and initializations with "const" that the compiler
> will attempt to place that data in readonly text
>
> I've done this with the libast tables in conftab.c lc.c
> but nm and size show the data going to the .data section
Was this a read/write or read-only data section ? IMO |const| data
should go into a read-only section but I am not sure whether they are
labelled "data" or "text" in that case.
A special case are string literals, for gcc they are read-only by
default but Sun Workshop/Forte/Studio unfortunately requires a special
option for that ("-xstrconst") which we use by default in our
ksh93-integration Makefiles.
> am I expecting too much from cc to do this without prodding?
No, in theory it should be working by default...
> is there a set of options that at least works for gcc on
> multiple architectures? or at least for solaris and the ksh93
> integration?
For string literals "-xstrconst" should do the job...
-- snip --
-xstrconst
Inserts string literals into the read-only data section
of the text segment instead of the default data seg-
ment. Duplicate strings will be eliminated and the
remaining copy shared amongst references in the code.
-- snip --
.. and AFAIK Sun Studio stores |const| data+structures into read-only
sections by default...
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 7950090
(;O/ \/ \O;)