| Thread overview | |||||
|---|---|---|---|---|---|
|
April 19, 2014 Defining symbols in a linker script | ||||
|---|---|---|---|---|
| ||||
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
| ||||
April 19, 2014 Re: Defining symbols in a linker script | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Mike Attachments:
| 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 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 I think you mean to 'extern (C) extern' Iain | |||
April 19, 2014 Re: Defining symbols in a linker script | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | 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.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply