Linux Symbol table - Symbol, Symbol table, System.map, /proc/kallsysms, Sample Code

What is Symbol

A symbol is a name given to a space in the memory which stores

  • data (Variables, For reading and writing)
  • instructions (Functions, for executing)
So symbol in the programming language is either a variable or function.

What is Symbol table?

Data Structure created by compiler containing all the symbols used in the program.

Every kernel image that you build has a symbol table with it. The Linux kernel symbol table contains names and addresses of all the kernel symbols. When you install the kernel it will be present in /boot/System.map-<linux_version>

How to Export your symbols?

When you define a new function in your module, the default behavior of this function is local, only the module in which the function is defined can access it, cannot be accessed by other modules. To export this module we need to use EXPORT_SYMBOL or EXPORT_SYMBOL_GPL. Once you export them, they will be available to other modules to use.

Difference between EXPORT_SYMBOL and EXPORT_SYMBOL_GPL

EXPORT_SYMBOL: The exported symbol can be used by any kernel module
EXPORT_SYMBOL_GPL: The exported symbol can be used by only GPL licensed code.

What is the difference between System.map and /proc/kallsysms?

/proc/kallsysms: Contains symbols of dynamically loaded modules as well as builtin modules
System.map: Contains symbols of only builtin modules.



Sample Driver Code to export a Symbol:


#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/jiffies.h>

MODULE_LICENSE("GPL");

void print_jiffies(void)
{
    printk(KERN_INFO"%s: Jiffies:%ld\n",__func__, jiffies);
}

static int test_export_init(void)
{
    printk(KERN_INFO"%s: In init\n", __func__);
    return 0;
}

static void test_export_exit(void)
{
    printk(KERN_INFO"%s: In exit\n", __func__);
}

EXPORT_SYMBOL_GPL(print_jiffies);

module_init(test_export_init);
module_exit(test_export_exit);

Build and Load the module

To verify if the print_jiffies symbol has added to the symbol table.







Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto