Is the standard C library initialized by the kernel first?

I am trying to understand the operation of the linker and the loader, as well as the memory addresses (physical or virtual) as to how the program actually compiles and runs. I came across two pieces of information and created my own version of understanding.

1st information:

W.5.1 GENERAL OBJECTS In a typical system, a number of programs will run. Each program relies on a number of functions, some of which will be standard C library functions, such as printf (), malloc (), strcpy (), etc., and some non-standard or user-defined functions. If each program uses the standard C library, this means that each program typically has a unique copy of that particular library inside. Unfortunately, this result in spent resources degrades efficiency and productivity. ** Since the C library is common, it is better for each program to reference a common, one copy of this library, instead of each program containing a copy of the library. This is done during the linking process, when some of the objects are linked during the linking,while some of them are executed at runtime (deferred / dynamic binding). **

The second information:

C library

Main articles: see the C library, creating the C library One thing to come: When you start working with the kernel, you do not have the C library available. You must provide everything yourself, with the exception of a few parts provided by the compiler itself. You will also need to have an existing C library or write it yourself. The C library implements standard C functions (i.e., things stated in, etc.) and provides them in binary form for communication with user space applications. In addition to the C function standard (as defined in the ISO standard), the C library can (and usually does) implements additional functions that may or may not be defined by any standard. The C standard library says nothing about the network, for example. For Unix-like POSIX systems, the standard defines what is expected from the C library;other systems may differ fundamentally. It should be noted that in order to implement its functionality, the C library must call the kernel functions. So, for your own OS, you can, of course, take ready-made C libraries and just recompile it for your OS, but it requires you to tell the libraries how to call the kernel functions, and your kernel actually provides these functions. A more sophisticated example is available in Library Calls or, you can use your existing C library or create your own C Library.how to call kernel functions, and your kernel actually provides these functions. A more sophisticated example is available in Library Calls or, you can use your existing C library or create your own C Library.how to call kernel functions, and your kernel actually provides these functions. A more sophisticated example is available in Library Calls or, you can use your existing C library or create your own C Library.

:

, C, . . , Linux. , ​​linux.

​​linux, , C ( , printf ) ( , ). , , printf() C. , printf(), , printf() . , , , ( , ). printf(), , printf().

? , ?

+4
2

.

1.) libc . - .

2.) libc.so - .

:

, .. bash , bash forks . . , .text.data.bss ELF, . :

sudo cat /proc/1118/maps 
00400000-00407000 r-xp 00000000 08:01 1845158                            /sbin/getty
00606000-00607000 r--p 00006000 08:01 1845158                            /sbin/getty
00607000-00608000 rw-p 00007000 08:01 1845158                            /sbin/getty
00608000-0060a000 rw-p 00000000 00:00 0 
00ff3000-01014000 rw-p 00000000 00:00 0                                  [heap]
...
7f728efd3000-7f728efd5000 rw-p 001bf000 08:01 466797                     /lib/x86_64-linux-gnu/libc-2.19.so
7f728efd5000-7f728efda000 rw-p 00000000 00:00 0 
7f728efda000-7f728effd000 r-xp 00000000 08:01 466799                     /lib/x86_64-linux-gnu/ld-2.19.so

7f728f1fe000-7f728f1ff000 rw-p 00000000 00:00 0 
7fffa122b000-7fffa124c000 rw-p 00000000 00:00 0                          [stack]
7fffa1293000-7fffa1295000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

. , ​​Linux ld-linux.so ( ). , ld-linux . , , . ldd

ldd /sbin/getty 
linux-vdso.so.1 =>  (0x00007fff4cfa6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2af2832000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2af2c24000)

- ELF ( , ). ld-linux () , /usr/lib .. ld-linux mmap . , libc .

+7

... , , , : , , ( ).

, :) : linux-vdso.so.1 = > (0x00007fff4cfa6000) " C ( , printf, )... ". , :) ( C) , C , : userpace linux. http://man7.org/linux/man-pages/man7/vdso.7.html

+1

Source: https://habr.com/ru/post/1599615/


All Articles