-----Original Message----- From: Vaibhav Jain [mailto:vjoss197@gmail.com] Sent: Tuesday, March 27, 2012 7:09 AM To: Pranay Kumar Srivastava Cc: kernelnewbies@kernelnewbies.org Subject: Re: Query on linker scripts
Hi,
Just one more query. bss is not a part of the executable but the linker script defines an output bss section. This means that the linker script only causes the symbols and section header for the bss section to be added to executable. Am I right ?
That would be correct if you are actually using an executable with a proper format like elf or coff. But if you are using a flat binary, in that case there won't be any symbol table maintained and everything will just get linked to wherever you've specified in your linker script. BSS still won't be part of you executable so what you can do is, find out much the bss section requires and then leave that space. Your stack would then start somewhere say 4KB above the BSS section while the data section would be right below the bss section. So that way, your stack and your data are linearly one after another. Ofcourse you can choose any other way to load the values. Bottom line... leave the pages required by the kernel alone and set up your GDT so that text section always gets loaded in the r/o part of your memory.
Thanks Vaibhav Jain On Mon, Mar 26, 2012 at 4:54 AM, Pranay Kumar Srivastava <Pranay.Shrivastava@hcl.com> wrote:
-----Original Message----- From: Vaibhav Jain [mailto:vjoss197@gmail.com] Sent: Monday, March 26, 2012 4:31 PM To: Pranay Kumar Srivastava Cc: kernelnewbies@kernelnewbies.org Subject: Re: Query on linker scripts
Thanks a lot for the explanation and the link!! I have just one more question about linker scripts. I am not clear about alignment of sections. Is it necessary to align sections? Its not mandatory but helps you to know in terms of pages how many are in use, otherwise while creating ptes for the kernel you'll need to calculate from the number of bytes the kernel has consumed and find out pages required. Otherwise its just a simple shift operation to find out the corresponding page from the page's beginning address.
Can the alignment be different from 4096? In the script that I provided the text and data sections are aligned while the bss section is not. Is there a reason for it ? The alignment generally corresponds to page granularity in the case of linker scripts. It's not about aligning data in C which can be done on say 4byte 8 byte etc... This alignment is done so that when the time comes to protect kernel and start user space applications you'll know which pages corresponds to kernel and can't be swapped and must be protected. Instead of thinking about protecting how many bytes kernel uses, think about how many pages the kernel uses.
Well, bss isn't part of your executable. It's stack and hence it doesn't make sense to have ALIGN there since you'll be responsible of setting up the stack for the kernel and using it. The data/text are part of the executable so you would want to have them aligned on page boundary so that when you load the kernel those sections would be loaded at page aligned address and end at page boundary.
Thanks Vaibhav Jain
On Sun, Mar 25, 2012 at 11:41 PM, Pranay Kumar Srivastava <Pranay.Shrivastava@hcl.com> wrote:
-----Original Message----- From: Vaibhav Jain [mailto:vjoss197@gmail.com] Sent: Sunday, March 25, 2012 3:19 AM To: Pranay Kumar Srivastava Subject: Re: Query on linker scripts
Hi Pranay, Thanks for replying!. I am still not clear about this as I have not reached the part of the tutorial which talks about pte and pgd. Could you please explain this point about safety of section with a simpler example? I'll take example from your script. .bss : { sbss = .; *(COMMON) *(.bss) ebss = .; } What I wanted to say was instead of taking ebss within .bss section
you
should take it outside that section. You might need to do ABSOLUTE since . will give you relative values but you'd want absolute values since addresses that you are interested in will begin from the entry point not from a section. So you can try something like this
.bss ALIGN(4096): { sbss = .; *(COMMON) *(.bss) } ebss = ABSOLUTE(.); /*This should be a page aligned address*/
Also, from your reply I figured out that it is not compulsory
to define such symbols and the names can be different than sbss and ebss. Am I right ? The names can be anything it's your choice entirely. But being descriptive helps. You should have a close look at the redhat tutorial for linker scripts instead of following someone else's linker script since you might not require all the variables chosen or you might need some additional variables due to the design you've chosen for your kernel.
http://docs.redhat.com/docs/en- US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/simple- example.html
Thanks Vaibhav Jain
Please include kernelnewbies@kernelnewbies.org in cc when replying. You are likely to get more responses that way.
On Sat, Mar 24, 2012 at 11:45 AM, Pranay Kumar Srivastava <Pranay.Shrivastava@hcl.com> wrote: On 03/24/2012 11:52 PM, Pranay Kumar Srivastava wrote:
________________________________________ From: kernelnewbies-
bounces+pranay.shrivastava=hcl.com@kernelnewbies.org
[kernelnewbies-
bounces+pranay.shrivastava=hcl.com@kernelnewbies.org] On Behalf Of kernelnewbies-request@kernelnewbies.org [kernelnewbies- request@kernelnewbies.org]
Sent: Saturday, March 24, 2012 9:30 PM To: kernelnewbies@kernelnewbies.org Subject: Kernelnewbies Digest, Vol 16, Issue 29
Send Kernelnewbies mailing list submissions to kernelnewbies@kernelnewbies.org
To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to kernelnewbies-request@kernelnewbies.org
You can reach the person managing the list at kernelnewbies-owner@kernelnewbies.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Kernelnewbies digest..."
Today's Topics:
1. Query on linker scripts (Vaibhav Jain) 2. Re: Query on linker scripts (Carlo Caione)
----------------------------------------------------------------- -- --
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies -
Message: 1 Date: Fri, 23 Mar 2012 21:43:40 -0700 From: Vaibhav Jain<vjoss197@gmail.com> Subject: Query on linker scripts To: kernelnewbies@kernelnewbies.org Message-ID:
<CAKuUYSw=_zZykPWeTbJsGEYPPSroWK+whm0o5L_PnCManVcrng@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
Recently I have started reading tutorials for writing a small kernel. All such tutorials mention use of linker scripts. I have read few articles on linker scritps but I am stuck on one thing. I am unable to understand the use of defining new symbols in linker scripts. Using a linker script to arrange different sections in the object file is understandable but defining symbols which are not referenced anywhere in the script is confusing. An example is the use of symbols sbss and ebss in the bss section as show in the script below
ENTRY (loader) SECTIONS { . = 0x00100000; .text ALIGN (0x1000) : { *(.text) } .rodata ALIGN (0x1000) : { *(.rodata*) } .data ALIGN (0x1000) : { *(.data) } .bss : { sbss = .; *(COMMON) *(.bss) ebss = .; } }
Please explain how defining such symbols is useful.
Thanks Vaibhav Jain