Sunday, January 28, 2024

[SOLVED] Why my symbol is not exported with EXPORT_SYMBOL?

Issue

I'm making a simple kernel object. but somehow a variable is not exported with EXPORT_SYMBIL macro. the source is:

#include <linux/module.h>
#include <linux/init.h>

MODULE_LICENSE("Dual BSD/GPL");

int hello_int __attribute__ ((__unused__));
EXPORT_SYMBOL(hello_int);

static int hello_init(void)
{
        printk(KERN_ALERT "driver loaded\n");
        return 0;
}

static void hello_exit(void)
{
        printk(KERN_ALERT "driver unloaded\n");
}

module_init(hello_init);
module_exit(hello_exit);

but.

# insmod hello.ko
# cat /proc/kallsyms | grep hello

d9fb0000 t hello_exit   [hello]
d9fb000c t hello_init   [hello]
d9fb0000 t cleanup_module       [hello]
d9fb000c t init_module  [hello]
d9f6374e t br_hello_timer_expired       [bridge]
d9f64027 t show_hello_timer     [bridge]
d9f640fb t store_hello_time     [bridge]
d9f64264 t set_hello_time       [bridge]
d9f641ee t show_hello_time      [bridge]

no hello_int is there. but certainly,

# cat Module.symvers

0x8ed8de1a      hello_int       /home/ken/myprojects/hello/hello        EXPORT_SYMBOL

why? something wrong?

# uname -a
Linux debian-6-0-6-i386 2.6.32-5-686 #1 SMP Sun Sep 23 09:49:36 UTC 2012 i686 GNU/Linux

and here is Makefile for this:

obj-m := hello.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Solution

Your problem is that the kernel is configured without CONFIG_KALLSYMS_ALL set, causing it to only export functions and not variables. I'm finding it difficult to track what happened in relation to this, but it looks like at some point the flag was enabled in one of the kernel updates.



Answered By - Anya Shenanigans
Answer Checked By - Mary Flores (WPSolving Volunteer)