Hi, I'm just wondering if I can force the linker (or objcopy) to write the bss section to my output file.. I use the file size to allocate memory to load the program.. It doesn't seem to be writing the bss variables, and this is causing me to have a page fault..
Could this be a problem in my .ld file?
Just to give some more info, I use:
ld -melf_386 --script=program.ld -o program.out program.o other_stuff.o
then
objcopy -v -S -O binary program.out program.bin
now, 'nm program.out' shows a '00000202004 b y_pos', which is 4 bytes over what is linked (thus causing my page fault)
Any help would be appreciated.
bss section not written?
Well the easiest way to do it would be like so. This is a excerpt from a linker script. This is assuming that the bss section is the last section in the file.
The LONG(0) forces the bss section to be written to the file.
Code: Select all
.bss
{
*(.bss)
LONG(0)
}
...
my kernel has the BSS section, but it's not being write to the file, so, look the code above
I guess they go to the BSS section, my kernel is pure binary. So, doing this
I'm initializing this variables, but, if they don't go to the file, could I be writing other memory than the memory the variables are?
my kernel has the BSS section, but it's not being write to the file, so, look the code above
Code: Select all
long int vars[2048];
Code: Select all
int i;
for (i = 0; i < 2048; i++) {
vars[i] = 0;
}
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: bss section not written?
If you wrote an ELF loader (this only takes a small amount of code) then you would be able to have more control over the whole load process - and you wouldn't need to do the 'objcopy'.bradbobak wrote:Hi, I'm just wondering if I can force the linker (or objcopy) to write the bss section to my output file.. I use the file size to allocate memory to load the program.. It doesn't seem to be writing the bss variables, and this is causing me to have a page fault..
Otherwise, it's next to impossible to find out how much BSS space is needed for a binary unless you write a special header that all programs for your OS require. Then your loader just needs to parse this header.
ok, thanks.. i'm going to make an elf loader.. i just have one more question.. bss is supposed to be 'unitialized data'.. but i'm doing
and this is being put into bss.. should i clear the bss section to 0 when i start?
Code: Select all
static uint x_pos = 0;
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
The reason why it's put into BSS is because BSS is always initialized to 0, so you can get a performance boost (and strip size) by not putting multiple references to '0' in the data section of the program.bradbobak wrote:ok, thanks.. i'm going to make an elf loader.. i just have one more question.. bss is supposed to be 'unitialized data'.. but i'm doing
and this is being put into bss.. should i clear the bss section to 0 when i start?Code: Select all
static uint x_pos = 0;
GCC/ld automatically does this for you.