Page 1 of 1
Sections in C
Posted: Sun Feb 09, 2003 10:55 am
by pini
How can I do to put all my C global variables in the data section ?
It seems that they're currently in the same section as my code.
Re:Sections in C
Posted: Mon Feb 10, 2003 2:22 am
by Pype.Clicker
global variables should go into the .data section if they are initialized and in .bss (not in file) section -- that should be zeroed by the loader ...
In no way they're supposed to go in the .text section except if you stated it explicitly in your linking script (if any). However, constant string usually go to .text in formats where no .rodata section is available.
Re:Sections in C
Posted: Mon Feb 10, 2003 10:06 am
by pini
Here's my linker script.
I will try to re-make my question : Can I control how the different sections (text, data, rodata) are organized in the binary file ?
[attachment deleted by admin]
Re:Sections in C
Posted: Mon Feb 10, 2003 10:16 am
by Pype.Clicker
you can do this by modifying the order of the sections in your script and by forcing the output virtual address of the sections. For instance
Code: Select all
. = SIZEOF_HEADERS;
.text 0: {
*(.text)
. = ALIGN(0x10);
}
.data (ADDR(.text) + SIZEOF(.text)) : {
*(.rodata)
*(.data)
. = ALIGN(0x10);
}
will make sure that no more than 16 bytes of padding is used between section, and that the 'data' section starts just after 'text'.
As you saw, i also grouped the read-only and read-write sections together (for compatibility with my COFF/ELF->SFS tools, mainly)
note that '.' refers to the output (file-offset), not the virtual address, afaik ... So .=0x100000 is likely to skip 1Mb in your output file (though i might be wrong on this
