What is .common section in map file?

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

What is .common section in map file?

Jump to solution
8,858 Views
ThomasH
Contributor II
Hi
 
I´m new in using  the CodeWarrior (4.5) for HCS12 annd I found a .common section in the map file. It seems that there are linked global variables. But I´m not sure and I can´t find a description in the docu.
 
Thanks!
Thomas
Labels (1)
Tags (1)
0 Kudos
1 Solution
2,832 Views
CrasyCat
Specialist III

Hello

Here are the predefined section used by the compiler is using:

.text : Contains the code.
.data : Contains the initialized global variables.
e.g. int a = 1, b= 2;
.stack: Contains the stack.
.bss : Contains the static un-initialized global variables.
e.g. static int c, d ;
.common: Contains the un-initialized global variables (not static).
e.g. int e, f;
.rodata : Contains the constant variables .
e.g. const int c1=2, c2=4 ;
.rodata1: Contains all the string constants.
e.g. #define mystr = “Hello world

I hope this helps.

CrasyCat

View solution in original post

0 Kudos
9 Replies
2,832 Views
CompilerGuru
NXP Employee
NXP Employee
Yes, the compiler places global variables into .common (a special ELF section with a predefined ELF section index SHN_COMMON, but that should not matter).

E.g.:

int global_i;
2,832 Views
ThomasH
Contributor II
And what is the .bss section?? For me it seems that the linker mixes .common and .bss section? Which types of variables will be linked there?
 
Thanks!
0 Kudos
2,833 Views
CrasyCat
Specialist III

Hello

Here are the predefined section used by the compiler is using:

.text : Contains the code.
.data : Contains the initialized global variables.
e.g. int a = 1, b= 2;
.stack: Contains the stack.
.bss : Contains the static un-initialized global variables.
e.g. static int c, d ;
.common: Contains the un-initialized global variables (not static).
e.g. int e, f;
.rodata : Contains the constant variables .
e.g. const int c1=2, c2=4 ;
.rodata1: Contains all the string constants.
e.g. #define mystr = “Hello world

I hope this helps.

CrasyCat

0 Kudos
2,831 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello CrasyCat and Pascal,

On CW10.6, S12Z chips , it seems no matter how i define the variable , it can not put in to the .bss segment .

For example

  int i = 0;

static int j ;

Why ?  And how can i put the variable to .bss segment ?

Thank !

Alice

0 Kudos
2,832 Views
DaveTonyCook
Contributor IV

Hi,

Just an addition to the above.  I'm working with CW 6.4 and it ignores the LCF *(COMMON) output section and sticks all uninitialised global data in the .bss section. !!??!!

I have the following:

1. static int x;          > .bss

2. static int y = 1;    > .data

3. static int y = 0;    > .bss   Couldn't this be quite dangerous as it relies on the start-up code zeroing the .bss. Uninitialised data should always be initialised before use.

4. int a                    > .bss  This should be emitted to .common or in this case *(COMMON) if provide the LCF however if I look at a disassembled c module the compiler does provide the required named section. This can be seen                                               by looking at the section index field (Shndx) in the symbol table.         

5. int a =1;              > .data

Also the linker documentation is very poor. Try searching the help file for COMMON, SCOMMON or .common ;0)

Snippet from my LCF

.uninitialized_data :

  {

  __START_BSS = .;

  *(.bss)

  . = ALIGN(0x8);

  # This should be for common GLOBAL variables declared in compiled code outside of any function

  # without the extern or static qualifier and which are not initialized. line has no effect!

  # All global uininitialised data declared as static,extern or with no type class specifier

  # are emmited to .bss TOGETHER WITH DATA INITIALISED TO 0

  *(COMMON)

  __END_BSS = .;

  . = ALIGN(0x8);

  } >> DATA

Any comments?

DaveCook

0 Kudos
2,832 Views
trytohelp
NXP Employee
NXP Employee

Hi Dave,

the original post was for HC12 V4.5 architecture.

the linker parameter file is not the same for the HC12 architecture and Coldfire.

to check the issue I recommend you to create a new post for this question.

Be aware the Coldfire V6.4 is an old version.

the last version based on Classic IDE is the V7.2.

the last development for Coldfire is CW for MCU V10.4 based on Eclipse.

I could investigate the problem/question.

In this case can you please create a new post for this question.

regards

Pascal

0 Kudos
2,832 Views
DaveTonyCook
Contributor IV

Hi Pascal,

As far as I'm aware the .common section is part of the ELF standard and is independent of processor architecture. There are many people that use and do not properly understand boiler plate LCF supplied with the tool chain and there is no description in the linker documentation regarding this.  Also there are many people that use older versions of the CW IDE.  I would have thought from the title and content of this post that the general nature of the issue would be relevant on this thread.

Best regards

0 Kudos
2,832 Views
trytohelp
NXP Employee
NXP Employee

Hi Dave,

I think I've understand the problem/question.

I need to work on it.

according to Catherine feedback the

      .common: Contains the un-initialized global variables (not static).

so in case of int a_1; the map file should use the SCOMMON or COMMON and not the .bss.

Regards

Pascal

0 Kudos
2,832 Views
trytohelp
NXP Employee
NXP Employee

Hi Dave,

I've checked with compiler team and my understanding was correct.

      Both SCOMMON and COMMON are used for sections related to .common

Regards

Pascal

0 Kudos