www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - static variable __StackTop cannot be read at compile time even if

reply Taylor Hillegeist <taylorh140 gmail.com> writes:
So I'm trying to get my FRDM-KL25Z (cortex-m0) board up and 
running. I've got minimal c code running and trying to do a 
direct conversion for a start. I'm using LDC for this project.

The linker Describes the symbol __StackTop
This is very nice and useful.

So i have this code:

extern(C) int __StackTop;

 attribute("section",".isr_vector")
shared ISR[3] g_pfnVectors  =
[
     __StackTop,
     Reset_Handler,
     ....

However I keep getting:
start.d(62): Error: static variable __StackTop cannot be read at 
compile time

I need the symbol to be ignored until linking. How do i do it?
Mar 06 2016
next sibling parent David Nadlinger via digitalmars-d-ldc <digitalmars-d-ldc puremagic.com> writes:
On 6 Mar 2016, at 18:46, Taylor Hillegeist via digitalmars-d-ldc wrote:
 I need the symbol to be ignored until linking. How do i do it?
You probably want to declare the symbol as "extern extern(C) __gshared". However, I'm not quite sure what your code snippet is supposed to do. What type is ISR? Are you sure you don't need to take the address of __StackTop? — David
Mar 06 2016
prev sibling next sibling parent Timo Sintonen <t.sintonen luukku.com> writes:
On Sunday, 6 March 2016 at 18:46:35 UTC, Taylor Hillegeist wrote:
 So I'm trying to get my FRDM-KL25Z (cortex-m0) board up and 
 running. I've got minimal c code running and trying to do a 
 direct conversion for a start. I'm using LDC for this project.

 The linker Describes the symbol __StackTop
 This is very nice and useful.

 So i have this code:

 extern(C) int __StackTop;

  attribute("section",".isr_vector")
 shared ISR[3] g_pfnVectors  =
 [
     __StackTop,
     Reset_Handler,
     ....

 However I keep getting:
 start.d(62): Error: static variable __StackTop cannot be read 
 at compile time

 I need the symbol to be ignored until linking. How do i do it?
Have a look at https://bitbucket.org/timosi/minlibd/src/61039fcbbf5845c7f18370c30857cfc034241fa2/tools/main/tls.d?at=default&fileviewer=file-view-default That is an example how I use linker variables. I use gdc but I think it is the same in ldc. For that startup thing I have not bothered to make my own. I use the startup file from ST library instead.
Mar 06 2016
prev sibling parent David Nadlinger <code klickverbot.at> writes:
On Sunday, 6 March 2016 at 18:46:35 UTC, Taylor Hillegeist wrote:
  attribute("section",".isr_vector")
Furthermore, this should be section(".isr_vector") (from ldc.attributes, introduced in 0.17). ldc.attribute was never implemented (nor was it documented), and has been removed in the meantime. — David
Mar 07 2016