title: How to get value of variable defined in ld linker script from C
body: <p>I am writing a program to run bare metal. I am trying to get a variable from a custom linker script to use in C here is what I have attempted.</p>
  
  <p>From C:</p>
  
  <pre><code>extern unsigned long* __START_OF_PROG_MEMORY;
  volatile unsigned long *StartOfProgram = (unsigned long*) (&amp;__START_OF_PROG_MEMORY);
  </code></pre>
  
  <p>Linker Script:</p>
  
  <pre><code>SECTIONS
  {
      . = 0x80000;
      PROVIDE(__START_OF_PROG_MEMORY = .);
      .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) }
      .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) }
      PROVIDE(_data = .);
      .data : { *(.data .data.* .gnu.linkonce.d*) }
      .bss (NOLOAD) : {
          . = ALIGN(16);
          __bss_start = .;
          *(.bss .bss.*)
          *(COMMON)
          __bss_end = .;
      }
      _end = .;
      PROVIDE(__END_OF_PROG_MEMORY = .);
  
     /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) }
  }
  __bss_size = (__bss_end - __bss_start)&gt;&gt;3;
  </code></pre>
  
  <p>Is the the correct way to get the contents of the variable defined in the linker script?</p>