Glenn Fowler wrote:
> On Fri, 20 Apr 2007 23:55:48 +0200 Roland Mainz wrote:
> > 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.
>
> ".data" => read/write, the cc I tested had .rodata for readonly
I tried the following testcase...
-- snip --
#include <stdlib.h>
#include <stdio.h>
const double greenslime[] =
{
.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19,
.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19,
.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19,
.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19,
.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19,
.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19,
.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19,
.1,.2,.3,.4,.5,.7,.1,.2,.3,.4,.5,.7,666.1,19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.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79,
.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79,
.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79,
.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79,
.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79,
.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79,
.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79,
.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79,
.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79.7,.2,.3,.4,.5,.7,.7,.2,.3,.4,.5,.7,666.7,79,
};
int main(int ac, char *av[])
{
printf("green=%ld, blue=%ld\n", sizeof(greenslime)+ac,
sizeof(blueslime)+ac);
return EXIT_SUCCESS;
}
-- snip --
... and compiled+tested the sources like this:
-- snip --
$ cc rodatatest.c -g -O -o rodatatest
$ ./rodatatest
green=3025, blue=3025
$ nm -s rodatatest | egrep
"lime"
[56] | 137640| 3024|OBJT |GLOB |0 |.data |blueslime
[75] | 68696| 3024|OBJT |GLOB |0 |.rodata |greenslime
$ cc -V
cc: Sun C 5.8 Patch 121015-04 2007/01/10
usage: cc [ options] files. Use 'cc -flags' for details
-- snip --
Can you check whether your results for this testcase differ, please ?
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 7950090
(;O/ \/ \O;)