bss section in code space

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

bss section in code space

1,362 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elecia on Wed Mar 02 11:34:10 MST 2011
Looking at my .map file, I noticed that uninitialized globals are going into code space. Given a lack of initialization, global variables should default to zero so they shouldn't take up the flash.

I've replicated this with the blinky example (blinky_main.c is attached, modifications are noted with BSS_TESTING #def). The buffer is going into the .bss section as it should but the bss section is taking up flash space. I compiled with space optimization (-Os) but it did not change the behavior.

In the cr_startup_lpc13.c file, the start up code says

[COLOR=DarkGreen][I]    // Zero fill the bss segment.  This is done with inline assembly since this
    // will clear the value of pulDest if it is not kept in a register.
[/I][/COLOR]
Exactly what I would expect. So why is the linker putting the bss section in my image?

I know I can fix this with my own linker scripts (though it is pretty complicated and uses linker varaibles. I tried just putting NOLOAD for the bss section of the linker script but that moves the bytes to the data section instead of the bss section).

Anyway, I'd like to know how to fix this with the managed scripts.  I'm using LPCXpresso 3.6.1. I'm compiling for LPC1343.

Thanks,
Elecia
0 Kudos
Reply
8 Replies

1,291 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Mon Dec 10 03:47:37 MST 2012
You might want to read this FAQ then...

http://support.code-red-tech.com/CodeRedWiki/FlashRamSize

Regards,
CodeRedSupport
0 Kudos
Reply

1,291 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by efrasiyab_ on Mon Dec 10 03:14:59 MST 2012
Thanks for reply. it is my fault as lamer. i was looking erroneously  "dec" field as though it is code space consumption of project.
0 Kudos
Reply

1,291 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Dec 10 03:02:08 MST 2012
According to the map file in your zip file, the 'junk' is correctly located in bss and not in flash. Why do you think it is in flash?
0 Kudos
Reply

1,291 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by efrasiyab_ on Mon Dec 10 02:22:49 MST 2012
Hi,
I have faced with same issue. I created new project and defined a global variable like "volatile unsigned char junk[ 128 ]". it sits in bss segment but also in flas! it is uninitialised variable and it must not be stored in the code space. I am missing something but cant find. I also tried to edit linker script and changed optimisation options but nothing changed.
mcu: 11c12
lpcxpresso version: v4.2.2 [Build 275] [03/04/2012]
0 Kudos
Reply

1,291 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Mar 02 19:07:35 MST 2011
Elecia,

I've imported the project as is. Can I ask why you think the .bss section is placed in flash? The enhanced Managed Linker Script mechanism does place data pointers to the .bss section boundaries in flash (e.g. __bss_section_table, __bss_section_table_end). These are used by an updated version of the ResetISR entry code to clear the .bss section. The updated entry code can be found in the LPC1343 examples which you can import. In your case, the IDE is using updated linker scripts, but does not have the startup code which uses the new mechanism. I see no evidence the .bss image itself is consuming flash space.

Regards,

CodeRedSupport


Quote: elecia
Here is the whole project. I took the standard blinky example and modified main  to add a global variable (bssJunkData) and a line that uses that variable. I also turned on space optimization (which didn't matter).

Note that the problem is not whether bssJunkData goes into bss (it does) but whether bss should be taking up flash space in my image when the section is filled with zeros by Reset_Handler.

Thanks,
Elecia

0 Kudos
Reply

1,291 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elecia on Wed Mar 02 17:04:07 MST 2011
Here is the whole project. I took the standard blinky example and modified main  to add a global variable (bssJunkData) and a line that uses that variable. I also turned on space optimization (which didn't matter).

Note that the problem is not whether bssJunkData goes into bss (it does) but whether bss should be taking up flash space in my image when the section is filled with zeros by Reset_Handler.

Thanks,
Elecia
0 Kudos
Reply

1,291 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Mar 02 15:43:35 MST 2011
If you not use the memory you have reserved, it will be discarded and so you may think the space has been allocated, when it has not.

For example, if I just add
int junk[128] ;
to blinky, it will apeear to have a size, but in fact the linker will have discared the memory and the symbol,

If I then add
junk[0]=1 ;
to main() , then the linker will not discard the data, and you will see it is correctly added to bss.

If you still think there is a problem, post the WHOLE project.
0 Kudos
Reply

1,291 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Mar 02 14:05:20 MST 2011
You'll need to export the entire project, and post it.

Regards,

CodeRedSupport
0 Kudos
Reply