disable bss

Programming, for all ages and all languages.
Post Reply
Guest

disable bss

Post by Guest »

Hello, is it possible to disable the bss section ?
I mean if i have following:

Code: Select all

char uninitialized_data[4096];

void main() { .......... }
uninitialized_data will go in the bss section and the linker doesnt reserve space for it in the binary file.

If i initialize the array:

Code: Select all

char uninitialized_data[4096] = "blabla...";

void main() { .......... }
Then it goes into the data section.

Is it possible to say the linker that uninitialized data goes into the data section, too so that the linker reserves the space for uninitialized data in the binary.

Thanks in advance.
Ryu

Re:disable bss

Post by Ryu »

All linkers that I work with don't have an option for that. But really, if you dont want that to be within the binary then don't declare it. And my guess that would be more of an compiler setting then the linker.

I don't mean to sound like a nuisance or anything, but can you please post generic programming related things in the programming section of the forum?
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:disable bss

Post by nick8325 »

You might be able to do it with linker scripts, by putting .bss in the same section as .data.

Why do you want to do that? It will make the file bigger by filling it with zeroes. There's probably a better way...
mystran

Re:disable bss

Post by mystran »

You got two options:

If you don't want .bss section at all, put your compiler's .bss section into the resulting binary's .data section in your linker script.

If you want specific thing in data section, you can either use assembler to define it into .data section, or tell your compiler to do that. For gcc, add __attribute__((section (".data"))) as last thing on the declaration line:

Code: Select all

char uninitialized_data[4096] __attribute__((section (".data")));
GCC also allows you to put all uninitialized data into datasection instead of .bss, you can use the switch -fno-zero-initialized-in-bss for that.

modify: changed data to .data in code, I think you need this
Post Reply