5

I created a memory linker script and saved it as memory.ld in the eclipse ide : Project : properties : gcc linker : miscellaneous : I added -M -T memory.ld

memory.ld :

    MEMORY
{
        ram (rw)   : ORIGIN = 0x4000000 ,  LENGTH = 2M  
}

SECTIONS
{
  RAM : { *(.myvarloc) 

} > ram }

In my c program : I made a global declaration as:

__attribute__ ((section(".myvarloc")))

 uint8 measurements [30];

ERRORS:

/usr/bin/ld: FEBRUARY section `.text' will not fit in region `ram'
/usr/bin/ld: region `ram' overflowed by 20018 bytes
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x2b): undefined reference to `__init_array_end'
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x31): undefined reference to `__init_array_start'
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x57): undefined reference to `__init_array_start'
/usr/bin/ld: FEBRUARY: hidden symbol `__init_array_end' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
user3252048
  • 77
  • 1
  • 12
  • The error is regarding `.text`/`ram` not `.myvarloc` overflow. – anishsane Feb 11 '14 at 14:26
  • 2
    Your linker script probably needs to tell the linker what to do with the rest of the code/data/etc., not just what to do with the .myvarloc section – nos Feb 11 '14 at 14:27
  • thank you very much for the reply. Could you please give me an example ?? – user3252048 Feb 11 '14 at 14:29
  • I need only memory section. So I did like above. – user3252048 Feb 11 '14 at 14:32
  • Do i want to specify like above in my c program ?? – user3252048 Feb 11 '14 at 14:33
  • Following may be helpful: http://stackoverflow.com/questions/21681578/creating-a-c-function-with-a-given-size-in-the-text-segment/21682647. I suggest taking a template linker file and just modifying it... might be easier than writing your own from scratch. As @nos suggests, you do probs need to tell the linker what to do with all the other sections – Jimbo Feb 11 '14 at 14:58
  • I modified like above and I am not getting any error. How to check the above .ld file is valid ?? – user3252048 Feb 11 '14 at 15:27
  • If I do like above in my c program then the variable measurements[30] will be stored in the ram region. Could anyone please answer my question ?? – user3252048 Feb 11 '14 at 15:48
  • @user3252048: It is very unclear what you are actually trying to *achieve*. At this point I'd daresay that *having* a linker script is not even the right way to solve whatever problem you have. Judging from your posts, I have a feeling you aren't really sure what a linker script actually does; i.e., this is not a conscious architectural decision but a rather hackish attempt to solve some *other* problem you have not told us about. – DevSolar Feb 11 '14 at 15:58
  • __attribute__ ((section(".my_special_text"))) void MySpecialFunction(...) { .... } The linker will put any function preceded by the __attribute__ statement into the my_special_text section. – user3252048 Feb 11 '14 at 16:00
  • Someone answered that like above in the code and it also works like that : http://stackoverflow.com/questions/21681578/creating-a-c-function-with-a-given-size-in-the-text-segment/21682647 – user3252048 Feb 11 '14 at 16:00
  • My question is : In my program - __attribute__ ((section(".myvarloc"))) uint8 measurements [30]; // will the measurement variable stored in a .myvarloc ?? – user3252048 Feb 11 '14 at 16:02

1 Answers1

1

Depending on the compiler you are using (GCC?) and the processor for which you are compiling (x86?), the compiler will generate several segment references in the object files. The most common ones are .text for code segments, .data for initialized data and .bss for uninitialized data. You can see which segments your compiler generates by using the nm utility on your object files.
I assume that until you provided your own linker script, the environment has provided some default script automatically and/or implicitly. But now that you have decided to "roll your own", you have to take care of all details yourself.

I cannot verify the details, but you could start with the following SECTIONS:

SECTIONS
{
  .bss : { *(.myvarloc) } 
  .bss : { *(.bss) }
  .data : { *(.data) }
  .text : { *(.text) }
}

I'm not sure if this is the exact syntax your GCC linker (it depends a little on the version), but you can find more information in the manual.

Johan Bezem
  • 2,582
  • 1
  • 20
  • 47