<div>Thanks a lot for the explanation and the link!! I have just one more question about</div><div>linker scripts. I am not clear about alignment of sections. Is it necessary to align sections? </div><div>Can the alignment be different from 4096?</div>
<div>In the script that I provided the text and data sections are aligned while the bss section is not. Is there </div><div>a reason for it ?</div><div> </div><div>Thanks</div><div>Vaibhav Jain</div><div><br><br> </div><div class="gmail_quote">
On Sun, Mar 25, 2012 at 11:41 PM, Pranay Kumar Srivastava <span dir="ltr"><<a href="mailto:Pranay.Shrivastava@hcl.com">Pranay.Shrivastava@hcl.com</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">
<div class="im"><br>
<br>
> -----Original Message-----<br>
> From: Vaibhav Jain [mailto:<a href="mailto:vjoss197@gmail.com">vjoss197@gmail.com</a>]<br>
> Sent: Sunday, March 25, 2012 3:19 AM<br>
> To: Pranay Kumar Srivastava<br>
> Subject: Re: Query on linker scripts<br>
><br>
><br>
</div><div class="im">> Hi Pranay,<br>
> Thanks for replying!. I am still not clear about this as I have not<br>
> reached<br>
> the part of the tutorial which talks about pte and pgd. Could you<br>
> please explain this point about safety of section with a simpler<br>
> example?<br>
<br>
</div>I'll take example from your script.<br>
<div class="im">.bss :<br>
{<br>
sbss = .;<br>
*(COMMON)<br>
*(.bss)<br>
ebss = .;<br>
}<br>
<br>
</div>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<br>
<br>
.bss ALIGN(4096):<br>
<div class="im">{<br>
sbss = .;<br>
*(COMMON)<br>
*(.bss)<br>
}<br>
</div>ebss = ABSOLUTE(.); /*This should be a page aligned address*/<br>
<div class="im"><br>
<br>
<br>
Also, from your reply I figured out that it is not compulsory<br>
> to define such symbols and the names can be different than sbss and<br>
> ebss. Am I right ?<br>
<br>
</div>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.<br>
<br>
<a href="http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/simple-example.html" target="_blank">http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/simple-example.html</a><br>
<br>
><br>
><br>
> Thanks<br>
> Vaibhav Jain<br>
<br>
Please include <a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a> in cc when replying. You are likely to get more responses that way.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> On Sat, Mar 24, 2012 at 11:45 AM, Pranay Kumar Srivastava<br>
> <<a href="mailto:Pranay.Shrivastava@hcl.com">Pranay.Shrivastava@hcl.com</a>> wrote:<br>
> On 03/24/2012 11:52 PM, Pranay Kumar Srivastava wrote:<br>
> ><br>
> > ________________________________________<br>
> > From: kernelnewbies-<br>
> bounces+pranay.shrivastava=<a href="mailto:hcl.com@kernelnewbies.org">hcl.com@kernelnewbies.org</a> [kernelnewbies-<br>
> bounces+pranay.shrivastava=<a href="mailto:hcl.com@kernelnewbies.org">hcl.com@kernelnewbies.org</a>] On Behalf Of<br>
> <a href="mailto:kernelnewbies-request@kernelnewbies.org">kernelnewbies-request@kernelnewbies.org</a> [kernelnewbies-<br>
> <a href="mailto:request@kernelnewbies.org">request@kernelnewbies.org</a>]<br>
> > Sent: Saturday, March 24, 2012 9:30 PM<br>
> > To: <a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a><br>
> > Subject: Kernelnewbies Digest, Vol 16, Issue 29<br>
> ><br>
> > Send Kernelnewbies mailing list submissions to<br>
> > <a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a><br>
> ><br>
> > To subscribe or unsubscribe via the World Wide Web, visit<br>
> ><br>
> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
> > or, via email, send a message with subject or body 'help' to<br>
> > <a href="mailto:kernelnewbies-request@kernelnewbies.org">kernelnewbies-request@kernelnewbies.org</a><br>
> ><br>
> > You can reach the person managing the list at<br>
> > <a href="mailto:kernelnewbies-owner@kernelnewbies.org">kernelnewbies-owner@kernelnewbies.org</a><br>
> ><br>
> > When replying, please edit your Subject line so it is more specific<br>
> > than "Re: Contents of Kernelnewbies digest..."<br>
> ><br>
> ><br>
> > Today's Topics:<br>
> ><br>
> > 1. Query on linker scripts (Vaibhav Jain)<br>
> > 2. Re: Query on linker scripts (Carlo Caione)<br>
> ><br>
> ><br>
> > ---------------------------------------------------------------------<br>
> -<br>
> ><br>
> > Message: 1<br>
> > Date: Fri, 23 Mar 2012 21:43:40 -0700<br>
> > From: Vaibhav Jain<<a href="mailto:vjoss197@gmail.com">vjoss197@gmail.com</a>><br>
> > Subject: Query on linker scripts<br>
> > To: <a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a><br>
> > Message-ID:<br>
> ><br>
> <CAKuUYSw=_<a href="mailto:zZykPWeTbJsGEYPPSroWK%2Bwhm0o5L_PnCManVcrng@mail.gmail.com">zZykPWeTbJsGEYPPSroWK+whm0o5L_PnCManVcrng@mail.gmail.com</a>><br>
> > Content-Type: text/plain; charset="iso-8859-1"<br>
> ><br>
> > Hi,<br>
> ><br>
> > Recently I have started reading tutorials for writing a small kernel.<br>
> All<br>
> > such tutorials mention use of linker scripts. I have<br>
> > read few articles on linker scritps but I am stuck on one thing. I am<br>
> > unable to understand the use of defining new symbols in linker<br>
> scripts.<br>
> > Using a linker script to arrange different sections in the object<br>
> file is<br>
> > understandable but defining symbols which are not referenced anywhere<br>
> in<br>
> > the script<br>
> > is confusing. An example is the use of symbols sbss and ebss in the<br>
> bss<br>
> > section as show in the script below<br>
> ><br>
> ><br>
> > ENTRY (loader)<br>
> > SECTIONS<br>
> > {<br>
> > . = 0x00100000;<br>
> > .text ALIGN (0x1000) :<br>
> > {<br>
> > *(.text)<br>
> > }<br>
> > .rodata ALIGN (0x1000) :<br>
> > {<br>
> > *(.rodata*)<br>
> > }<br>
> > .data ALIGN (0x1000) :<br>
> > {<br>
> > *(.data)<br>
> > }<br>
> > .bss :<br>
> > {<br>
> > sbss = .;<br>
> > *(COMMON)<br>
> > *(.bss)<br>
> > ebss = .;<br>
> > }<br>
> > }<br>
> ><br>
> > Please explain how defining such symbols is useful.<br>
> ><br>
> > Thanks<br>
> > Vaibhav Jain<br>
> > -------------- next part --------------<br>
> > An HTML attachment was scrubbed...<br>
> > URL:<br>
> <a href="http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/2012" target="_blank">http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/2012</a><br>
> 0323/6e1741da/attachment-0001.html<br>
> ><br>
> > ------------------------------<br>
> ><br>
> > Message: 2<br>
> > Date: Sat, 24 Mar 2012 16:26:38 +0100<br>
> > From: Carlo Caione<<a href="mailto:carlo.caione@gmail.com">carlo.caione@gmail.com</a>><br>
> > Subject: Re: Query on linker scripts<br>
> > To: Vaibhav Jain<<a href="mailto:vjoss197@gmail.com">vjoss197@gmail.com</a>><br>
> > Cc: <a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a><br>
> > Message-ID:<<a href="mailto:4F6DE7AE.9070808@gmail.com">4F6DE7AE.9070808@gmail.com</a>><br>
> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
> ><br>
> > On 24/03/2012 05:43, Vaibhav Jain wrote:<br>
> >> Hi,<br>
> > [cut]<br>
> >> is confusing. An example is the use of symbols sbss and ebss in the<br>
> bss<br>
> >> section as show in the script below<br>
> >> ENTRY (loader)<br>
> >> SECTIONS<br>
> >> {<br>
> >> . = 0x00100000;<br>
> >> .text ALIGN (0x1000) :<br>
> >> {<br>
> >> *(.text)<br>
> >> }<br>
> >> .rodata ALIGN (0x1000) :<br>
> >> {<br>
> >> *(.rodata*)<br>
> >> }<br>
> >> .data ALIGN (0x1000) :<br>
> >> {<br>
> >> *(.data)<br>
> >> }<br>
> >> .bss :<br>
> >> {<br>
> >> sbss = .;<br>
> The sbss will tell you the start of the section bss.<br>
> >> *(COMMON)<br>
> >> *(.bss)<br>
> >> ebss = .;<br>
> The ebss will tell you the end of the section bss. The use of these<br>
> symbols is since you'd like to have the kernel's section be safe from<br>
> every other process.<br>
><br>
> This way you can know where your kernel code starts and ends. So you<br>
> can set up the pages( ptes and pgds as well) in a sensible manner for<br>
> your kernel.<br>
><br>
> So in the above case you'd have like two variables in your C code like<br>
> extern long sbss,ebss and then to get the location where the bss begins<br>
> you'd do &sbss while to get its ending address you'd do &ebss. So when<br>
> you subtract these two that should give you the size of your bss<br>
> section.<br>
><br>
> However you should do ebss=. after your .bss section and make it<br>
> ALIGN(0x1000) like others so you get page aligned section values cuz it<br>
> makes easier to arrange for the pte and pgd for kernel. Also you should<br>
> set the GDT values for kernel only code separately accordingly from the<br>
> values you get after an initial temporary GDT has been setup earlier by<br>
> GRUB or by you.<br>
><br>
> More appropriate would be to get the size of text and data sections as<br>
> well since you wouldn't want to accidentally bump into kernel code.<br>
><br>
><br>
><br>
> >> }<br>
> >> }<br>
> ><br>
> > I'm not sure if you are OT, anyway...<br>
> ><br>
> > i.e. they are useful if you want to clear the bss section before<br>
> execution.<br>
> ><br>
> > [snippet for ARM proc]<br>
> > ...<br>
> > ldr r2, =_sbss<br>
> > b LoopFillZerobss<br>
> > /* Zero fill the bss segment. */<br>
> > FillZerobss:<br>
> > movs r3, #0<br>
> > str r3, [r2], #4<br>
> ><br>
> > LoopFillZerobss:<br>
> > ldr r3, = _ebss<br>
> > cmp r2, r3<br>
> > bcc FillZerobss<br>
> > ...<br>
> ><br>
> > --<br>
> > Carlo Caione<br>
> ><br>
> ><br>
> ><br>
> > ------------------------------<br>
> ><br>
> > _______________________________________________<br>
> > Kernelnewbies mailing list<br>
> > <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
> > <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
> ><br>
> ><br>
> > End of Kernelnewbies Digest, Vol 16, Issue 29<br>
> > *********************************************<br>
><br>
> ::DISCLAIMER::<br>
> -----------------------------------------------------------------------<br>
> ------------------------------------------------<br>
><br>
> The contents of this e-mail and any attachment(s) are confidential and<br>
> intended for the named recipient(s) only.<br>
> It shall not attach any liability on the originator or HCL or its<br>
> affiliates. Any views or opinions presented in<br>
> this email are solely those of the author and may not necessarily<br>
> reflect the opinions of HCL or its affiliates.<br>
> Any form of reproduction, dissemination, copying, disclosure,<br>
> modification, distribution and / or publication of<br>
> this message without the prior written consent of the author of this e-<br>
> mail is strictly prohibited. If you have<br>
> received this email in error please delete it and notify the sender<br>
> immediately. Before opening any mail and<br>
> attachments please check them for viruses and defect.<br>
><br>
> -----------------------------------------------------------------------<br>
> ------------------------------------------------<br>
<br>
</div></div></blockquote></div><br>