This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why is a const array pointer with -fPIC mapped in ".data"?


On Mon, 2004-05-17 at 11:39, Kazuomi Kato wrote:
> I'd like to put an array data in the section ".rodata".
> I wish the array data to be unmodified so I used const type for it.
> However, inspite of the data specified as const type, I found the case
> that the data specified was mapped in the section ".data".  
> If a const pointer array is compiled with -fPIC option, const type
> to the pointer is ignored and the pointer exists in the ".data".
> 
> Do you know why this is happening?

Yes.
> Does the -fPIC option have to do with above phenomenon?

Yes.

The problem is that when the code is loaded it has to be dynamically
relocated (the pointers in the data have to be adjusted based on the
load address).  Because of this, it can't be made read-only (at least,
not without having the dynamic loader playing page protection dances in
the MMU).

So although your code is not logically modifiable (from the strict
source-code perspective), it does have to be physically modifiable from
the execution perspective.

If you really want your PIC data tables to be read-only, don't put
pointers in them.

R.

> 
> I used the gcc v3.2.1 for ARM.
> 
> I'd like to show an example bellow.
> ===
> "test.c"
> 
> const char const_rodata0[] = "test0";
> const char const_rodata1[] = "test1";
> const char const_rodata2[] = "test2";
> const char const_rodata3[] = "test3";
> const char const_rodata4[] = "test4";
> const char const_rodata5[] = "test5";
> 
> const char * const array_const[BUF][2] = {ã/* specified const to array_const */
>   {const_rodata0, const_rodata1},
>   {const_rodata2, const_rodata3},
>   {const_rodata4, const_rodata5}
> };


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]