Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4006058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:28:08+00:00 2026-05-20T08:28:08+00:00

The following piece of code is from u-boot: /* Initialize GOT pointer. ** Global

  • 0

The following piece of code is from u-boot:

        /* Initialize GOT pointer.
        ** Global symbols can't be resolved before this is done, and as such we can't
        ** use any global symbols in this code.  We use the bal/ move xxx,ra combination to access
        ** data in a PC relative manner to avoid this.  This code will correctly set the
        ** gp regardless of whether the code has already been relocated or not.                                                          
        ** This code determines the current gp by computing the link time (gp - pc)                                                      
        ** and adding this to the current pc.                                                                                            
        ** runtime_gp = runtime_pc + (linktime_gp - linktime_pc)                                                                         
        ** U-boot is running from the address it is linked at at this time, so this                                                      
        ** general case code is not strictly necessary here.                                                                             
        */                                                                                                                               

/*Branch and link to get current PC in ra */                                                                                     
        bal     1f                                                                                                     
        nop                                                                                               
        .extern _GLOBAL_OFFSET_TABLE_                                            
        .word   _GLOBAL_OFFSET_TABLE_  /* This contains the linked address of the GOT */                                                 
        /* The ra register now contains the runtime address of the above memory location */                                              

        .word   . - 4                  /* This contains the link time address of the previous word,                                      
                                        which is also what the link time expected PC value is */                                         
1:                                                                                                
        move    gp, ra    /* Move current PC into gp register */                                                                         
        lw      a5, 0(ra) /* Load linked address of the GOT into a5 */                                                                   
        lw      a6, 4(ra) /* Load the link time address of the GOT storage location into a6 */                                           
        sub     a5, a6    /* Subtract a6 from t1. */                                                                                     
        /* a5 now contains the difference between the link-time GOT table address and the link time expected PC */                       

        /* Add this difference to the current PC (copied into gp above) so that gp now has the current runtime                           
        ** GOT table address */                                                                                                          
        daddu   gp, a5  # calculate current location of offset table              

I don’t understand 3 directive above:

.extern _GLOBAL_OFFSET_TABLE_
.word _GLOBAL_OFFSET_TABLE_ //what the meaning after declaring it as a external symbol?
.word . -4  //and also this one?

TIA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:28:09+00:00Added an answer on May 20, 2026 at 8:28 am
    .extern _GLOBAL_OFFSET_TABLE_
    

    The symbol is described outside of this compilation unit. Resolve it at link time.

    .word _GLOBAL_OFFSET_TABLE_
    

    Allocate a word worth of memory and place the address of the symbol at this location

    .word . - 4
    

    Take the current location, ., subtract 4 and place that value in a word of memory. Similar to the previous code except the value being placed at this location is being computed.

    Here is a link with a list of many of the assembler directives.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following piece of code in an aspx webpage: Response.Redirect(/Someurl/); I also
Hey folks, I have the following piece of code from C++. for (int i=0;
I am using the following piece of code to get results from DB as
The following piece of code shows an Insert table dialog: Dialog d = WordApp.Dialogs[WdWordDialog.wdDialogTableInsertTable];
I have the following piece of code pattern: void M1(string s, string v) {
I have the following piece of code which replaces template markers such as %POST_TITLE%
I used the following piece of code in the service to debug the service
I have the following piece of code in Visual C++ 2005 : : class
I have trouble with the following piece of code. When I go through with
I was reading a book on templates and found the following piece of code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.