Assigning global variable locations in linker

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Assigning global variable locations in linker

4,013 Views
nanoGeek
Contributor I
I am using CW fo CF v6.x.
 
Is there any way to use the linker to assign global variable locations in memory?  "OBJECT" doesn't seem to work and the only other way I have been able to control the location of global variables is to declare them in reverse order from how I wish for them to be assigned and then force the declaration file to be the first in line in the .bss segment (main.c below):
 
 .uninitialized_data :
 {
  __START_SBSS = .;
  *(.sbss)
  . = ALIGN(0x8);
  *(SCOMMON)
  __END_SBSS = .;
  __START_BSS = .;
  main.c(.bss)
  *(.bss)
  . = ALIGN(0x8);
  *(COMMON)
  __END_BSS = .; 
  . = ALIGN(0x8);
 } > DATA

 
Also, I have the "targeting for Coldfire" manual which discusses the linker.  Is this the most comprehensive linker guide that exists or is there a document that covers the linker more in depth?  For example, what does .bss and .sbss stand for?
 
Thanks,
 
Joe
 
Labels (1)
0 Kudos
3 Replies

951 Views
CrasyCat
Specialist III
Hello
 
I assume you are using CodeWarrior for ColdFire V6.2.
 
In order to place a variable at a specific address you can
  1- Allocate it in a user defined section and allocate the section appropriately in
       the .lcf file.
  2- Use the OBJECT linker command
 
 To allocate an object in a user defined section use following notation:
#pragma define_section myData ".myData" far_absolute RW
__declspec(myData) int MyVar;
To make sure the section myData is allocated first in RAM area, modify your ,lcf file as follows:
 .uninitialized_data :
 {
  *(.myData)
  __START_SBSS = .;
  *(.sbss)
  . = ALIGN(0x8);
  *(SCOMMON)
  __END_SBSS = .;
  __START_BSS = .;
  main.c(.bss)
  *(.bss)
  . = ALIGN(0x8);
  *(COMMON)
  __END_BSS = .; 
  . = ALIGN(0x8);
 } > DATA
 
 2- is implemented as follows:
Suppose you have following variable defined in  main.c source file:
int myVar2;
You can use the object keyword as follows in the .lcf file:
 .uninitialized_data :
 {
  OBJECT(_myVar2, main.c)
  __START_SBSS = .;
  *(.sbss)
  . = ALIGN(0x8);
  *(SCOMMON)
  __END_SBSS = .;
  __START_BSS = .;
  main.c(.bss)
  *(.bss)
  . = ALIGN(0x8);
  *(COMMON)
  __END_BSS = .; 
  . = ALIGN(0x8);
 } > DATA
 
Note that the compiler adds a leading _ as prefix to symbol names. In the .lcf file you have to refer to the object internal name.
 
The Targeting_ColdFire.pdf manual is the manual where you will find all info around the linker.
 
I hope this helps.
 
CrasyCat
0 Kudos

951 Views
nanoGeek
Contributor I
Both options work, but #2 causes S-records to be generated for the RAM areas (not desirable).  Is there a way to supress the S-records?
 
Thanks,
 
Joe
 
0 Kudos

951 Views
CrasyCat
Specialist III
Hello
 
Yep looks like variant 2 supposed the object to be initialized data. I did not find a way to get it set to uninitialized.
 
I will report that back to engineering. In the mean time you will have to either use 1 or place the object in main_application_data instead of  uninitialized_data.
 
CrasyCat
0 Kudos