Subject: Re: gcc -fPIC/-fpic and 'const'
To: =?ISO-8859-1?Q?Jarom=EDr_Dolecek?= <jdolecek@netbsd.org>
From: Todd Vierling <tv@wasabisystems.com>
List: tech-userlevel
Date: 03/01/2001 15:44:24
On Thu, 1 Mar 2001, Jaromír Dolecek wrote:
: it looks like if a source file is compiled with -fPIC or -fpic,
: const stuff is not moved to text segment of the resulting object.
: Is that deliberate ? It works OK in neither of those two flags is
: not used.
Works fine for me:
===== x.c =====
const char foo[] = "test";
===============
$ cc -fPIC -c x.c
$ objdump --headers x.o
x.o: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000000 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .data 00000000 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000034 2**2
ALLOC
3 .note 00000014 00000000 00000000 00000034 2**0
CONTENTS, READONLY
4 .rodata 00000005 00000000 00000000 00000048 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
.rodata contains the symbol, as it should; the only other section with a
size != 0 is the magical .note.
Note that on ELF, .text is not the only read-only section. There are
several possible ones; .rodata is actually supposed to be mapped read-only
and *non-executable* where possible. 8-)
--
-- Todd Vierling <tv@wasabisystems.com> * Wasabi NetBSD: Run with it.
-- NetBSD 1.5 now available on CD-ROM -- http://www.wasabisystems.com/