Loading text & data section into different segments

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
sampath
Posts: 18
Joined: Wed Dec 20, 2006 4:00 am

Loading text & data section into different segments

Post 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
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post 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.
Author of COBOS
urxae
Member
Member
Posts: 149
Joined: Sun Jul 30, 2006 8:16 am
Location: The Netherlands

Post 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.
Post Reply