www.digitalmars.com         C & C++   DMDScript  

D.gnu - Defining symbols in a linker script

reply "Mike" <none none.com> writes:
Hello,

It is common practice in ARM Cortex-M bare metal C/C++ programs 
to define symbols in the linker so one can initialize the .data 
and .bss segments and know the boundaries of one's stack and 
heap.  It looks something like this.

**** linkerscript ****
__text_end__ = .;

.data : AT(__text_end__)
{
     __data_start__ = .;
     *(.data)
     *(.data.*)
     __data_end__ = .;
} > SRAM

**** C++ file ****
extern "C" uint32_t __text_end__;
extern "C" uint32_t __data_start__;
extern "C" uint32_t __data_end__;

void startup()
{
     // copy mutable state out of ROM into RAM
     memcpy(&__data_start__, &__text_end__, (&__data_end__ - 
&__data_start__) * 4);
}

I tried to do something similar in D with...

extern(C) __gshared uint __text_end__;
extern(C) __gshared uint __data_start__;
extern(C) __gshared uint __data_end__;

... but unfortunately this puts new variables in the .bss 
segment.  I want the un-mangled name, so I can refer to it 
easily, but I also want it to be truly "extern" (defined 
elsewhere).  Is that possible at this moment in D?

Thanks for the help,
Mike
Apr 18 2014
next sibling parent "Iain Buclaw via D.gnu" <d.gnu puremagic.com> writes:
--001a113a665aa47cc704f75b7d23
Content-Type: text/plain; charset=UTF-8

On 19 Apr 2014 01:35, "Mike via D.gnu" <d.gnu puremagic.com> wrote:
 Hello,

 It is common practice in ARM Cortex-M bare metal C/C++ programs to define

know the boundaries of one's stack and heap. It looks something like this.
 **** linkerscript ****
 __text_end__ = .;

 .data : AT(__text_end__)
 {
     __data_start__ = .;
     *(.data)
     *(.data.*)
     __data_end__ = .;
 } > SRAM

 **** C++ file ****
 extern "C" uint32_t __text_end__;
 extern "C" uint32_t __data_start__;
 extern "C" uint32_t __data_end__;

 void startup()
 {
     // copy mutable state out of ROM into RAM
     memcpy(&__data_start__, &__text_end__, (&__data_end__ -

 }

 I tried to do something similar in D with...

 extern(C) __gshared uint __text_end__;
 extern(C) __gshared uint __data_start__;
 extern(C) __gshared uint __data_end__;

 ... but unfortunately this puts new variables in the .bss segment.  I

to be truly "extern" (defined elsewhere). Is that possible at this moment in D?
 Thanks for the help,
 Mike

I think you mean to 'extern (C) extern' Iain --001a113a665aa47cc704f75b7d23 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <p dir=3D"ltr">On 19 Apr 2014 01:35, &quot;Mike via D.gnu&quot; &lt;<a href= =3D"mailto:d.gnu puremagic.com">d.gnu puremagic.com</a>&gt; wrote:<br> &gt;<br> &gt; Hello,<br> &gt;<br> &gt; It is common practice in ARM Cortex-M bare metal C/C++ programs to def= ine symbols in the linker so one can initialize the .data and .bss segments= and know the boundaries of one&#39;s stack and heap. =C2=A0It looks someth= ing like this.<br> &gt;<br> &gt; **** linkerscript ****<br> &gt; __text_end__ =3D .;<br> &gt;<br> &gt; .data : AT(__text_end__)<br> &gt; {<br> &gt; =C2=A0 =C2=A0 __data_start__ =3D .;<br> &gt; =C2=A0 =C2=A0 *(.data)<br> &gt; =C2=A0 =C2=A0 *(.data.*)<br> &gt; =C2=A0 =C2=A0 __data_end__ =3D .;<br> &gt; } &gt; SRAM<br> &gt;<br> &gt; **** C++ file ****<br> &gt; extern &quot;C&quot; uint32_t __text_end__;<br> &gt; extern &quot;C&quot; uint32_t __data_start__;<br> &gt; extern &quot;C&quot; uint32_t __data_end__;<br> &gt;<br> &gt; void startup()<br> &gt; {<br> &gt; =C2=A0 =C2=A0 // copy mutable state out of ROM into RAM<br> &gt; =C2=A0 =C2=A0 memcpy(&amp;__data_start__, &amp;__text_end__, (&amp;__d= ata_end__ - &amp;__data_start__) * 4);<br> &gt; }<br> &gt;<br> &gt; I tried to do something similar in D with...<br> &gt;<br> &gt; extern(C) __gshared uint __text_end__;<br> &gt; extern(C) __gshared uint __data_start__;<br> &gt; extern(C) __gshared uint __data_end__;<br> &gt;<br> &gt; ... but unfortunately this puts new variables in the .bss segment. =C2= =A0I want the un-mangled name, so I can refer to it easily, but I also want= it to be truly &quot;extern&quot; (defined elsewhere). =C2=A0Is that possi= ble at this moment in D?<br> &gt;<br> &gt; Thanks for the help,<br> &gt; Mike</p> <p dir=3D"ltr">I think you mean to &#39;extern (C) extern&#39;</p> <p dir=3D"ltr">Iain </p> --001a113a665aa47cc704f75b7d23--
Apr 18 2014
prev sibling parent "Mike" <none none.com> writes:
On Saturday, 19 April 2014 at 01:50:45 UTC, Iain Buclaw via D.gnu 
wrote:
 I think you mean to 'extern (C) extern'

Yes, that's what I was looking for. Thanks.
Apr 18 2014