Let's say I want to use printk()
within arch/x86/boot/string.c
before compiling the kernel. Which header file do I have to include so that the linker knows where to find printk()
? I tried #include <linux/kernel.h>
and #include <linux/printk.h>
but I always get errors during make bzImage
telling me the linker does not find printk
:
arch/x86/boot/compressed/string.o: In function `memcmp`:
string.c:(.text+0x19): undefined reference to `printk`
printk is a C function from the Linux kernel interface that prints messages to the kernel log. It accepts a string parameter called the format string, which specifies a method for rendering an arbitrary number of varied data type parameter(s) into a string. The string is then printed to the kernel log.
printk messages go to the kernel log message buffer, which can be exposed in a variety of ways depending on system configuration. The shell command dmesg will show them, and they should also be being copied to files in /var/log by the syslog daemon.
The linux kernel's exported header files describe the API for user space programs attempting to use kernel services. These kernel header files are used by the system's C library (such as glibc or uClibc) to define available system calls, as well as constants and structures to be used with these system calls.
The system's libc headers are usually installed at the default location /usr/include and the kernel headers in subdirectories under that (most notably /usr/include/linux and /usr/include/asm).
You are trying to instrument the boot stage of the kernel. It has its own really small library and doesn't have any headers like linux/printk.h
available. The function is called printf()
and it's implemented in arch/x86/boot/printf.c.
The output of this function goes to the channel whatever defined in BIOS (int 10h) and, if asked, to the legacy (you can't use UART which has 32-bit I/O, for example) serial line. For the details refer to the printf.c source file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With