Section declared in a source code is not shown in the memory map file

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

Section declared in a source code is not shown in the memory map file

4,123 Views
Veter
Contributor I
I use CodeWarrior Development Studio for ColdFire Verstion 6.3, Build 14.
My target is MCF5307.
 
I have section declaration in my source (C) code:
#pragma define_section constdata ".constdata" far_absolute RX
__declspec(CONST)static const uint16_t crcTable[8] = {
 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7
};
 
My link command file has following statement
.flashdata
{
...
*(.constdata)
...
} > sdram
 
This section is not shown in the memory map file.
Does anyone has idea what the problem might be?
How do declare section in CW for ColdFire so it actually works?
Labels (1)
0 Kudos
12 Replies

771 Views
CrasyCat
Specialist III
Hello
 
You need to specify an existing section name in the __declspec attribute.
 
#pragma define_section constdata ".constdata" far_absolute RX
__declspec(constdata )static const uint16_t crcTable[8] = {
 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7
};
 
CrasyCat
0 Kudos

771 Views
Veter
Contributor I
I did that, but section .constdata was not included into the map file. The array declaration appears in the .rodata section instead. Is there any way to change that. I do not want linker to think for me, I need this array at cirtain location.
 
Thank you for your reply!
0 Kudos

771 Views
CrasyCat
Specialist III
Hello
 
Can you make sure you are using the same __declspec in both the array definition and declaration.
Otherwise this should be working.
 
Can you please send me the C source file with variable definition and the linker file you are using.
 
CrasyCat
0 Kudos

771 Views
Veter
Contributor I
Please see attached c source and lcf file.
Thank you very much.
0 Kudos

771 Views
CrasyCat
Specialist III
Hello
 
Just took a look at your source code and did some quick test.
 
You need to modify the constant definition as follows.
 
#pragma define_section constdata ".constdata" far_absolute R
__declspec(constdata) static unsigned int crcTable[256] = {
 
The table will then be allocated in section .constdata.
I still need to figure out why the const keyword is bringing in trouble.
I will check internally and let you know.
CrasyCat
0 Kudos

771 Views
sjmelnikoff
Contributor III
A similar issue was also raised in this thread:
 
 
Steve.
0 Kudos

771 Views
CrasyCat
Specialist III
Hello
 
I double check internally.
I already asked engineering about something similar and here is what they told me:
 
The keyword const acts as __declspec(rodata), it has precedence over __declspec(constdata) since the pragma only create data/bss/text section.
 
So bottom line is if you want to put constants in a user defined sections you need to define it without the const keyword.
CrasyCat
0 Kudos

771 Views
sjmelnikoff
Contributor III

CrasyCat wrote:
 
The keyword const acts as __declspec(rodata), it has precedence over __declspec(constdata) since the pragma only create data/bss/text section.

That's a little annoying. It might be better to have const put data in rodata by default, but allow it to be overwritten by a declspec. This would allow const to be retained in these circumstances for the benefit of the compiler (as opposed to the linker).
 
Steve.
0 Kudos

771 Views
CrasyCat
Specialist III
Hello
 


sjmelnikoff wrote:
That's a little annoying. It might be better to have const put data in rodata by default, but allow it to be overwritten by a declspec. This would allow const to be retained in these circumstances for the benefit of the compiler (as opposed to the linker).


I opened a ticket for  a possible improvement in the compiler around that. Not sure when it will be implemented.
 
Note also that this behavior is specific to the Coldfire compiler.
PowerPC (or Power Architecture) compiler are placing the constant in a user defined section even when const keyword is used
 
CrasyCat 
0 Kudos

770 Views
sjmelnikoff
Contributor III
Ditto for HCS12.
 
Thanks CrasyCat for dealing with that!
 
Steve.
0 Kudos

771 Views
CrasyCat
Specialist III
Hello
 
CodeWarrior HCS12 & HCS08 do not have such issue either.
This is really limited to Coldfire build tools as far as I can tell.
 
Note that HC08 & HC12 tools do not supporet __declspec you have to use pagmas CONST_SEG MyConstSeg or @"MyConstSeg" instead
 
CrasyCat
0 Kudos

771 Views
Veter
Contributor I
Dropping "const" statement from the section declaration puts it right where it belongs.
The following statement is a working version.
 
#pragma define_section constdata ".constdata" far_absolute R
__declspec(constdata)static uint16_t crcTable[8] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7};
 
Thank you.
0 Kudos