What are the implications? Is the kernel compiled with static libraries or are they implemented intrinsically?
Also, according to this, kernel code cannot use any floating point operation. Why is that?
What are the implications? Is the kernel compiled with static libraries or are they implemented intrinsically?
Also, according to this, kernel code cannot use any floating point operation. Why is that?
Why is it not possible to link shared libraries into kernel code?
It is possible. But, they are not the same shared libraries you use in userland.
Since classic System V, kernel can be running as set of loadable modules and is usually being run this way. Virtually all modern systems use this; Linux and FreeBSD are good examples. And, they use the same tools to create such modules as for userland. For example:
shared object of a kernel module:
$ file /lib/modules/4.4.0-97-generic/kernel/drivers/net/vxlan.ko
'/lib/modules/4.4.0-97-generic/kernel/drivers/net/vxlan.ko: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=561b0b69742c93a595c85be50f6916352c793e5c, not stripped
shared object of a userland library:
$ file /lib64/libm-2.23.so
/lib64/libm-2.23.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=cb41640d6965fac9bac4010bebac955e95e4d8c1, for GNU/Linux 2.6.32, stripped
the same for FreeBSD:
$ file /boot/kernel/agp.ko
/boot/kernel/agp.ko: ELF 64-bit LSB relocatable, x86-64, version 1 (FreeBSD), not stripped
$ file /lib/libm.so.5
/lib/libm.so.5: ELF 64-bit LSB shared object, x86-64, version 1 (FreeBSD), dynamically linked, stripped
in these cases, all are ELF "shared object" (the thing you named "shared library"; the term "shared object" is less obvious but declared in ELF specification) or "relocatable" ("object file"; but the way kernels use it is nearly identical to shared object). You can see subtle differences in file
diagnostics, as ELF branding and target specification; they are not principal for this linking. One of the first things that start in a freshly loaded kernel is a runtime linker that is aware of selected object file format and performs initial linking.
But, the thing that is different is that kernel modules are built against different programming interface and, in some cases, against different binary interface. Some library functions can cease; some can be implemented in a rather different way. If you compile and link kernel module without special options intended for kernel, there is major chance it wonʼt run properly (and cause kernel crash). Thatʼs why one should use specific header set and compile options. And, you usually cannot load a userland library into kernel because it depends on symbols that arenʼt present in kernel.