Page 1 of 1

Loading text & data section into different segments

Posted: Tue May 15, 2007 3:22 am
by sampath
Hello all,
I am using the following script to load text and data in different
segments but its not working.
can anyone point to the problems in this ???
OUTPUT_FORMAT("coff-go32")
SECTIONS
{
.text 0x00000000 :
{
*(.text)
. = ALIGN(4096);
etext = .;_etext = .;}
.data 0x00000000:
{
*(.data)
. = ALIGN(4096);
edata = .;_edata = .;}
.bss :
{ *(.bss)
*(COMMON)
. = ALIGN(4096);
end = .;_end = .;}}

I am using DJGPP.when I
use this script along with ld it gives the following error...
ld --oformat coff-go32 -Tld.scr file1.o
error:Section .data overlaps .text section
My intention is to load .text and .data into different segments.If I
use 0x00000000 only in .text then, data gets continuous address.so when
I load data in different location it leaves .text size space and then
copies the data section.It works fine except for the wastage of .text
size memory at the beginning of data segment.


Rgds,
sampath S

Posted: Tue May 15, 2007 3:44 am
by os64dev
.data and .text both point to the same adress that should be interesting. I load the code and overwrite it with data. sound buggy to me.

In 32-bit pmode assigin segments is a little bit harder if you use c/c++ because it assumes ds to point to a specific location and a flat memory model. which btw can be achieved/controlled by paging. This may sound fuzzy but my mental state at this point is kinda fuzzy. To little sleep for many days.

Posted: Tue May 15, 2007 7:29 am
by urxae
Like I posted in alt.os.development, where the same question was posted:
Me in alt.os.development wrote:You could try using overlays (See http://www.gnu.org/software/binutils/ma ... html#SEC22).

Alternatively, you could define your data segment as "expand-down", making non-zero segment starting addresses possible. This way you can disallow data access to your .text without needing to change any addresses. The .data addresses will still be right after your .text addresses, but reading and writing .text addresses through pointers will be disallowed.
For more info on this, see the description of data segment descriptors in an Intel or AMD manual.