What is COMMON in a linker script?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

What is COMMON in a linker script?

Post by gsingh2011 »

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)?
linguofreak
Member
Member
Posts: 510
Joined: Wed Mar 09, 2011 3:55 am

Re: What is COMMON in a linker script?

Post by linguofreak »

gsingh2011 wrote:Why must we start the .text section at 256 kb (If I calculated that correctly)?
You're off by a factor of 4. I'll let you figure out which way.
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Re: What is COMMON in a linker script?

Post by gsingh2011 »

linguofreak wrote:
gsingh2011 wrote:Why must we start the .text section at 256 kb (If I calculated that correctly)?
You're off by a factor of 4. I'll let you figure out which way.
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?
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: What is COMMON in a linker script?

Post by dozniak »

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.
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Re: What is COMMON in a linker script?

Post by gsingh2011 »

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.
natp
Posts: 6
Joined: Tue Apr 07, 2009 9:08 pm

Re: What is COMMON in a linker script?

Post by natp »

"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
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Re: What is COMMON in a linker script?

Post by gsingh2011 »

Is this at all related to why we have to boot the kernel with "kernel 200+<num_blocks>
After some Googling I found an answer to this here: ftp://ftp.gnu.org/old-gnu/Manuals/grub- ... ub_10.html

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.
"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.
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?
Post Reply