All of lore.kernel.org
 help / color / mirror / Atom feed
From: vjoss197@gmail.com (Vaibhav Jain)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Query on linker scripts
Date: Mon, 26 Mar 2012 04:01:09 -0700	[thread overview]
Message-ID: <CAKuUYSyiE2TfLwxu60z95rZDvk_bLWW5PAEcFZnCAEmPqdfF4g@mail.gmail.com> (raw)
In-Reply-To: <8E369781E2274447B64FD25FC6AE8C372A47BC3580@nda-hclt-evs06.HCLT.CORP.HCL.IN>

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?
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 ?

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 at 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 at 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 at kernelnewbies.org [kernelnewbies-
> > bounces+pranay.shrivastava=hcl.com at kernelnewbies.org] On Behalf Of
> > kernelnewbies-request at kernelnewbies.org [kernelnewbies-
> > request at kernelnewbies.org]
> > > Sent: Saturday, March 24, 2012 9:30 PM
> > > To: kernelnewbies at kernelnewbies.org
> > > Subject: Kernelnewbies Digest, Vol 16, Issue 29
> > >
> > > Send Kernelnewbies mailing list submissions to
> > >          kernelnewbies at kernelnewbies.org
> > >
> > > To subscribe or unsubscribe via the World Wide Web, visit
> > >
> >  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> > > or, via email, send a message with subject or body 'help' to
> > >          kernelnewbies-request at kernelnewbies.org
> > >
> > > You can reach the person managing the list at
> > >          kernelnewbies-owner at 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)
> > >
> > >
> > > ---------------------------------------------------------------------
> > -
> > >
> > > Message: 1
> > > Date: Fri, 23 Mar 2012 21:43:40 -0700
> > > From: Vaibhav Jain<vjoss197@gmail.com>
> > > Subject: Query on linker scripts
> > > To: kernelnewbies at 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
> > > -------------- next part --------------
> > > An HTML attachment was scrubbed...
> > > URL:
> > http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/2012
> > 0323/6e1741da/attachment-0001.html
> > >
> > > ------------------------------
> > >
> > > Message: 2
> > > Date: Sat, 24 Mar 2012 16:26:38 +0100
> > > From: Carlo Caione<carlo.caione@gmail.com>
> > > Subject: Re: Query on linker scripts
> > > To: Vaibhav Jain<vjoss197@gmail.com>
> > > Cc: kernelnewbies at kernelnewbies.org
> > > Message-ID:<4F6DE7AE.9070808@gmail.com>
> > > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> > >
> > > On 24/03/2012 05:43, Vaibhav Jain wrote:
> > >> Hi,
> > > [cut]
> > >> 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 = .;
> > The sbss will tell you the start of the section bss.
> > >>           *(COMMON)
> > >>           *(.bss)
> > >>           ebss = .;
> > The ebss will tell you the end of the section bss. The use of these
> > symbols is since you'd like to have the kernel's section be safe from
> > every other process.
> >
> > This way you can know where your kernel code starts and ends. So you
> > can set up the pages( ptes and pgds as well) in a sensible manner for
> > your kernel.
> >
> > So in the above case you'd have like two variables in your C code like
> > extern long sbss,ebss and then to get the location where the bss begins
> > you'd do &sbss while to get its ending address you'd do &ebss. So when
> > you subtract these two that should give you the size of your bss
> > section.
> >
> > However you should do ebss=. after your .bss section and make it
> > ALIGN(0x1000) like others so you get page aligned section values cuz it
> > makes easier to arrange for the pte and pgd for kernel. Also you should
> > set the GDT values for kernel only code separately accordingly from the
> > values you get after an initial temporary GDT has been setup earlier by
> > GRUB or by you.
> >
> > More appropriate would be to get the size of text and data sections as
> > well since you wouldn't want to accidentally bump into kernel code.
> >
> >
> >
> > >>       }
> > >> }
> > >
> > > I'm not sure if you are OT, anyway...
> > >
> > > i.e. they are useful if you want to clear the bss section before
> > execution.
> > >
> > > [snippet for ARM proc]
> > > ...
> > >          ldr     r2, =_sbss
> > >          b       LoopFillZerobss
> > > /* Zero fill the bss segment. */
> > > FillZerobss:
> > >          movs    r3, #0
> > >          str     r3, [r2], #4
> > >
> > > LoopFillZerobss:
> > >          ldr     r3, = _ebss
> > >          cmp     r2, r3
> > >          bcc     FillZerobss
> > > ...
> > >
> > > --
> > > Carlo Caione
> > >
> > >
> > >
> > > ------------------------------
> > >
> > > _______________________________________________
> > > Kernelnewbies mailing list
> > > Kernelnewbies at kernelnewbies.org
> > > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> > >
> > >
> > > End of Kernelnewbies Digest, Vol 16, Issue 29
> > > *********************************************
> >
> > ::DISCLAIMER::
> > -----------------------------------------------------------------------
> > ------------------------------------------------
> >
> > The contents of this e-mail and any attachment(s) are confidential and
> > intended for the named recipient(s) only.
> > It shall not attach any liability on the originator or HCL or its
> > affiliates. Any views or opinions presented in
> > this email are solely those of the author and may not necessarily
> > reflect the opinions of HCL or its affiliates.
> > Any form of reproduction, dissemination, copying, disclosure,
> > modification, distribution and / or publication of
> > this message without the prior written consent of the author of this e-
> > mail is strictly prohibited. If you have
> > received this email in error please delete it and notify the sender
> > immediately. Before opening any mail and
> > attachments please check them for viruses and defect.
> >
> > -----------------------------------------------------------------------
> > ------------------------------------------------
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120326/7479779b/attachment-0001.html 

  reply	other threads:[~2012-03-26 11:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-24 18:45 Query on linker scripts Pranay Kumar Srivastava
     [not found] ` <CAKuUYSwPiuGTa+8r6O+-GMLu9e6dXOXNfDHu4UBx2yvrHcQyvw@mail.gmail.com>
2012-03-26  6:41   ` Pranay Kumar Srivastava
2012-03-26 11:01     ` Vaibhav Jain [this message]
2012-03-26 11:54       ` Pranay Kumar Srivastava
2012-03-27  1:38         ` Vaibhav Jain
2012-03-27 11:00           ` Pranay Kumar Srivastava
2012-03-26 15:14       ` Dave Hylands
  -- strict thread matches above, loose matches on Subject: below --
2012-03-24  4:43 Vaibhav Jain
2012-03-24 15:26 ` Carlo Caione

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKuUYSyiE2TfLwxu60z95rZDvk_bLWW5PAEcFZnCAEmPqdfF4g@mail.gmail.com \
    --to=vjoss197@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.