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

  • Home
  • SEARCH
  • 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 7752453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:48:17+00:00 2026-06-01T11:48:17+00:00

Friends, I have two files, a.c and b.c . I have defined a function

  • 0

Friends, I have two files, a.c and b.c .
I have defined a function foo in a.c which is being called from b.c.

From what I understand, when the compiler tries to compile b.c, it will see that the implementation of foo is not in b, so it will add a entry for foo in the symbol table which os to be resolved at the linking time. I understood this concept properly.

Now, i have a different function printf in b.c which is implmented in glibc. From what i understand, printf can be linked at the loadtime or at the run time. If printf will be linked at the run time, there must have a stub for each call to printf which will be resolved at the run time using a system call.

my question is “Is my understanding correct ??? + how does the compiler determine that a function foo would be resolved by linker and not at run time ???”

i noticed some similar questions but could not understand their significance here ???

  • 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-06-01T11:48:18+00:00Added an answer on June 1, 2026 at 11:48 am

    I find your question slightly hard to read, so I’m not quite sure how you understand it, so I’ll just describe how it works.

    1. If the symbol is in the same file (b.c) then the compiler refers to it directly. The linker is not used to resolve anything.

    2. If the symbol is not in the same file, and -fPIC is not specified, then the compiler simply emits a call to an undefined symbol. In this case the linker will search for the symbol in other .o files, or in libraries, and insert the direct reference at link time by basically pasting it into the blank.

      This is exactly how you would normally build a program (as opposed to a library). If the program uses dynamic libraries then there may be some symbols that cannot be fixed up at link time. If so, the linker will check that the library does have them and it will be left to the dynamic linker to finish the job at run time.

      It would be possible to do exactly this in shared libraries also, only with the dynamic linker always pasting the addresses into the program at run time, but to do that would mean that the shared library couldn’t be shared: each program would have to have its own copy with its own fix-ups. This is why that doesn’t happen.

    3. If the symbol is not in the same file, and -fPIC is specified, then the compiler does not use the symbol name directly. Instead, it calls functions via a PLT (Procedure Linkage Table) and gets the address of other symbols via a GOT (Global Offset Table).

      The GOT is a special table created by the linker, and it is basically just a list of undefined symbol references similar to the ones you’d find in a regular non-PIC program (except that they’re typically offsets to the base of the GOT). The dynamic linker fills in the blanks at run time. The compiler arranges for the address of the GOT to be always in a particular CPU register so the table can always be found.

      The PLT is a set of trampolines created by the linker. The compiler creates jumps into the PLT, and the dynamic linker sets up the PLT to bounce on to the real location of the function. Actually, in many cases the PLT is not filled in by the dynamic linker when the library is loaded: the PLT fills itself in the first time it is called by using the GOT (it’s self-modifying code).

      This is why dynamic libraries are normally built with -fPIC: the GOTs and PLTs can be modified for each program while still keeping the text of the libraries unmodified, and therefore allowing them to remain shared.

    So, now the answers to your questions:

    I think the ‘stub’ that you talked about might be the PLT?

    The compiler does not know when a function will be resolved. It only knows that it can’t resolve it itself. In fact, when you use dynamic libraries, the linker does not even try to resolve symbols fully (although I think it does check that they are defined in the library); this means that it’s possible to override a specific function in a library by providing another function with the same name. Tools like tsocks use this with LD_PRELOAD to intercept library calls.

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

Sidebar

Related Questions

i have two files one called stats.js one called storage.html in stats.js in contains
I have two classes defined in different h files and each class has some
I have a many-to-many relationship between two tables, let's say Friends and Foods. If
I have a table called 'friends', this contains the columns person1 and person2 .
I have created an invite friends code, which is properly working if an FB
So I have two files: File 1 has this method in it: import MyGlobals
I have two MXML component files and try to work with them as classes.
I have these two XIB files. The first one edited by my friend to
I have a two-column ListView linked to a Datapager. The ListView lists all files
I have two professional programmer friends who are going to teach me, and they

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.