🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #41982

Re: how to put all consts into data segment?

#41982
From: Laine Stump
Date: Tue, 23 Jan 1996 00:00
42 lines
2234 bytes
hohmuth@gozo.gmd.de (Michael Hohmuth) wrote:

>Is it possible to instruct GCC to put all initialized data into the
>data segment, even constant data?

>Would "-Dconst= -fwritable-strings" be sufficient?

No, this isn't enough. There is other data not declared with "const"
that is treated as const.

>The background is that I want to create a module which is to be linked
>into an operating system which has its code segment register pointing
>to a different value than the data segment register (i486 in 32 bit
>mode).  I've instructed the linker to relocate the module's data/bss
>segments to the correct address (even though they're physically in
>subsequent real memory regions) in order to avoid any data address
>dereferences to text segment addresses, but I understand that GCC
>still puts constants into the the program's text segment.

Before doing the configure, find the proper include file (it will be the
same one that defines "CPP_PREDEFINES", for netbsd it was
config/i386/netbsd.h) and add the following #define:


#define READONLY_DATA_SECTION data_section

This will switch to .data before emitting const data, just as is done
for normal data.

You'll also need to move jump tables to this other segment, by
commenting out the this #define in the same file:

/* #define JUMP_TABLES_IN_TEXT_SECTION */

This is slightly annoying, since it puts something that could be
considered executable in the data segment, where it is not protected by
the i386 paging mechanism from munching. But it does allow you to do
what you want - we're using a gcc compiled like that for our own OS and
it has allowed us to catch a great number of potentially ugly problems.

Laine Stump
laine@morningstar.com
Technical Details
Message-ID: <1996Jan23.041816.27072@MorningStar.Com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <a5u41o6umn.fsf@gozo.gmd.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,393f5e6a02d548f4
X-Google-Attributes: gid11318c,public
From: laine@morningstar.com (Laine Stump)
Subject: Re: how to put all consts into data segment?
Date: 1996/01/23
Message-ID: <1996Jan23.041816.27072@MorningStar.Com>
X-Deja-AN: 136508755
sender: news@MorningStar.Com
references: <a5u41o6umn.fsf@gozo.gmd.de>
organization: Morning Star Technologies
reply-to: laine@morningstar.com
newsgroups: gnu.gcc.help