I'm trying to understand the operation of linker and loader, and memory addresses(physical or virtual) regarding how a program is actually compiled and executed. I encountered two pieces of information and formed my own version of comprehension.
1st information:
W.5.1 SHARED OBJECTS In a typical system, a number of programs will be running. Each program relies on a number of functions, some of which will be standard C library functions, like printf(), malloc(), strcpy(), etc. and some are non-standard or user defined functions. If every program uses the standard C library, it means that each program would normally have a unique copy of this particular library present within it. Unfortunately, this result in wasted resources, degrade the efficiency and performance. **Since the C library is common, it is better to have each program reference the common, one instance of that library, instead of having each program contain a copy of the library. This is implemented during the linking process where some of the objects are linked during the link time whereas some done during the run time (deferred/dynamic linking). **
2nd information:
C Library
Main Articles: See C Library, Creating a C Library One thing up front: When you begin working on your kernel, you do not have a C library available. You have to provide everything yourself, except a few pieces provided by the compiler itself. You will also have to port an existing C library or write one yourself. The C library implements the standard C functions (i.e., the things declared in , , etc.) and provides them in binary form suitable for linking with user-space applications. In addition to standard C functions (as defined in the ISO standard), a C library might (and usually does) implement further functionality, which might or might not be defined by some standard. The standard C library says nothing about networking, for example. For Unix-like systems, the POSIX standard defines what is expected from a C library; other systems might differ fundamentally. It should be noted that, in order to implement its functionality, the C library must call kernel functions. So, for your own OS, you can of course take a ready-made C library and just recompile it for your OS - but that requires that you tell the library how to call your kernel functions, and your kernel to actually provide those functions. A more elaborate example is available in Library Calls or, you can use an existing C Library or create your own C Library.
The way I understood:
when a computer boots, it first doesn't have any access to C library and instead it must work with machine code. But with the help of boot code, it will eventually start loading the OS. In this example, I will assume a computer loading linux OS. Naturally a linux kernel will be loaded.
when a linux kernel is booted, this also means that standard C library(basic functions like printf for example) is also loaded on to low memory(portion of RAM assigned for kernel space). Assume that a user has made a simple code using printf() from standard C library. The user will compile this code and during this process, the linker will make a 'reference' for printf(), implying the position where printf() function is residing in low memory. When this code is executed, the loader will load this executable saved in HDD to high memory(portion of RAM assigned for user space). When the process confronts printf() function, it will branch to low memory address containing the start of printf() function.
Am i correct? If not, where am I wrong?