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.
Sections in C
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Sections in C
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.
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.
-
pini
Re:Sections in C
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]
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]
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Sections in C
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
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
Code: Select all
. = SIZEOF_HEADERS;
.text 0: {
*(.text)
. = ALIGN(0x10);
}
.data (ADDR(.text) + SIZEOF(.text)) : {
*(.rodata)
*(.data)
. = ALIGN(0x10);
}
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