What is the COMMON section in a linker script? The Bare Bones tutorial has *(COMMON) inside the .bss section. I couldn't find any info online about this.
I didn't want to make a separate thread for this, but another question I have about the linker script is the line ". = 0x00100000;" Why must we start the .text section at 256 kb (If I calculated that correctly)?
What is COMMON in a linker script?
-
- Member
- Posts: 83
- Joined: Tue Feb 03, 2009 11:37 am
-
- Member
- Posts: 510
- Joined: Wed Mar 09, 2011 3:55 am
Re: What is COMMON in a linker script?
You're off by a factor of 4. I'll let you figure out which way.gsingh2011 wrote:Why must we start the .text section at 256 kb (If I calculated that correctly)?
-
- Member
- Posts: 83
- Joined: Tue Feb 03, 2009 11:37 am
Re: What is COMMON in a linker script?
Ah, you're right. I should have said 1 mb. So why does my kernel need to start 1 mb past the start of memory?linguofreak wrote:You're off by a factor of 4. I'll let you figure out which way.gsingh2011 wrote:Why must we start the .text section at 256 kb (If I calculated that correctly)?
Re: What is COMMON in a linker script?
Because on x86 the low meg of memory is occupied by various... stuff. I'll let you figure out what it is.
Learn to read.
-
- Member
- Posts: 83
- Joined: Tue Feb 03, 2009 11:37 am
Re: What is COMMON in a linker script?
I see. So the first megabyte is used extensively by the BIOS. Also, if I understand correctly, the bootloader is copied into this memory as well. So if I'm developing an OS to run on x86, then I don't want to overwrite any of this memory, so I'll put my kernel at 1 MB. Is this at all related to why we have to boot the kernel with "kernel 200+<num_blocks>"?
My question about COMMON still holds.
My question about COMMON still holds.
Re: What is COMMON in a linker script?
"Common" variables are non-static global variables that are not assigned an initial value when declared. The variable declaration can be duplicated in another file, possibly with an initial value.
The COMMON keyword in the linker script tells the linker where to put these variables.
http://www.nasm.us/doc/nasmdoc6.html#section-6.7
http://www.cygwin.org/ml/crossgcc/2000-q2/msg00013.html
The COMMON keyword in the linker script tells the linker where to put these variables.
http://www.nasm.us/doc/nasmdoc6.html#section-6.7
http://www.cygwin.org/ml/crossgcc/2000-q2/msg00013.html
-
- Member
- Posts: 83
- Joined: Tue Feb 03, 2009 11:37 am
Re: What is COMMON in a linker script?
After some Googling I found an answer to this here: ftp://ftp.gnu.org/old-gnu/Manuals/grub- ... ub_10.htmlIs this at all related to why we have to boot the kernel with "kernel 200+<num_blocks>
For anyone else looking for it, kernel 200+18 means read 18 blocks starting from the offset 200. The offset 200 means 200 blocks from the beginning, which is 200*512 bytes=102400 bytes. You can see this number in the tutorial when calculating the pad.
So the only difference between *(COMMON) and *(.bss) is that the variables in the common could be declared in another file? So this is like the extern keyword in C, right?"Common" variables are non-static global variables that are not assigned an initial value when declared. The variable declaration can be duplicated in another file, possibly with an initial value.