How to place variables into a 2nd .bss / common section?

Michael Weise
Tue Sep 3 09:23:00 GMT 2013


I'm working on an embedded system with a coldfire (m68k-elf) cpu.
The system has two different ram areas:
1. External DRAM (the main ram module)
2. Internal SRAM 

The first and normal ".bss" section works just fine (see below).

To put global variables into the second section called
".bss_sram" I use the following macro:

#define SECTION_BSS_SRAM __attribute__((section(".bss_sram")))

Unfortunately, GCC generates assembler-code with the "@progbits"

.section	.bss_sram,"aw",@progbits

which makes the linker mark the section as loadable and reserve
space in the executable (not necessary & unwanted):

"m68k-elf-objdump -h $EXECUTABLE" shows the problem:
  5 .bss          01fac966  4000001c  00001700  0000401c  2**1
  6 .bss_sram     00001094  80000000  80000000  00010000  2**11
                  CONTENTS, ALLOC, LOAD, DATA

I didn't find any options to tell GCC that this is a section with
"common" data, but instead found a "dirty workaround" to inject
the "@nobits" attribute into the assembly code:

Is this the only way to have a second common section or is there a
more beautiful way / option?


More information about the Gcc-help mailing list