www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/31/06:21:26

Date: Wed, 31 Jul 1996 12:18:09 +0200 (MET DST)
From: Mark Habersack <grendel AT ananke DOT amu DOT edu DOT pl>
To: Helge Kruse <hk AT bercos DOT de>
cc: djgpp AT delorie DOT com
Subject: Re: __attribute__((section))
In-Reply-To: <DvBL0t.qp@bercos.de>
Message-ID: <Pine.NEB.3.93.960731121214.7438B-100000@ananke.amu.edu.pl>
MIME-Version: 1.0

On Mon, 29 Jul 1996, Helge Kruse wrote:

>If you like to look at a quick and dirty hack, here it is:
>----- makefile -----
>CC=gcc
>DJGPP=c:/djgpp
>
>sample: sample.o specdat.o
>	ld -Tdjgpp.lnk -o $@ $(DJGPP)/lib/crt0.o -L$(DJGPP)/lib $^ -lgcc -lc -lgcc
>
>sample.o: sample.c
>    
>specdat.o: specdat.c
>	$(CC) -S $< -o $*.sx
>	sed "s/\.data/.section MYDATA/" <$*.sx >$*.s
>	$(CC) -c $*.s -o $@
>
>show: sample
>	objdump -h $<
>
>clean:
>	rm -f sample *.o *.s* *.bak
>----- sample.c -----
>#include "specdat.h"
>
>int maindata;
>
>void main(void)
>{
>    maindata=specdata;
>}
>----- specdat.h -----
>extern int specdata;
>----- specdat.c -----
>#include "specdat.h"
>
>/* ONLY use initialized data! */
>/* uninitialized data goes to .bss and cannot be moved */
>int specdata=0;
>
>/* section attributes are not supported for this target 
>int me __attribute ((section("MYDATA"))); */
>----- djgpp.lnk -----
>OUTPUT_FORMAT("coff-go32")
>ENTRY(start)
>SECTIONS
>{
>  .text : {
>    *(.text)
>    etext  =  . ; _etext = .;
>    . = ALIGN(0x200); 
>  }
>  .data ALIGN(0x200) : {
>    *(.data)
>    *(.bss)
>    edata  =  . ; _edata = .;
>    . = ALIGN(0x200); 
>  }
>  MYDATA 0x1234 : {
>    _mydata = . ;
>    *(MYDATA)
>    _emydata = . ;
>  }
>}
>----- end -----
>
>The djgpp.lnk is written from mind, so check it against the system file.
>
>Regards,
>	Helge
>
Neat! But still, wouldn't it be easier if GCC just supported the
__atrribute__((section))? 
The hack is OK, but where does MYDATA section go? Does it go to separate
segment when proggy is loaded? If so, you have to use far pointers/switch DS
selector if you want to access the data - BY HAND. I tried something similar
wit an .S file that created new section, put some data into it and initialize
that data. Then I created (by hand - don't know anything about sed ;-))) an
*.ld script and linked the proggy - it didn't work.

Greetz, Mark

/*******************************/
/** So here I am once more... **************************************/
/** When you grown up and leave your playground, where you kissed **/
/** your Prince and found your Frog - remember the Jester that    **/
/** showed you tears, a Script for Tears... ************************/
/*********************************************/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019