简体   繁体   中英

.text, .bss, .data sections not showing in kernel module

I have the following kernel module and Makefile for linux running on beagle-bone board.

/* Kernel Module : kmodule.c */
#include<linux/module.h>
#include<linux/kernel.h>
s32 gval = 200;
static s32 __init test_init(void)
{
    pr_info("%s done : gval:%d\n",__FUNCTION__,gval);
    return 0;
}
static void __exit test_deinit(void)
{
    pr_info("%s done : gval:%d\n",__FUNCTION__,gval);
}
module_init(test_init);
module_exit(test_deinit);
MODULE_LICENSE("GPL");

/* Makefile */
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
BBB_KERNEL_SRC=kernel_source_path
EXTRA_CFLAGS += -g -DDEBUG
obj-m += test_km.o
test_km-objs := kmodule.o
all:
    make -C $(BBB_KERNEL_SRC) M=$(PWD) modules
clean:
    make -C $(BBB_KERNEL_SRC) M=$(PWD) clean

The module builds fine and test_km.ko file is generated,when the test_km.ko file is insmod ,the /sys/modules/test_km/sections shows the following.

.ARM.exidx.exit.text
.ARM.exidx.init.text
.exit.text
.gnu.linkonce.this_module
.init.plt
.init.text
.note.Linux
.note.gnu.build-id
.plt
.rodata
.rodata.str1.4
.strtab
.symtab

Why the .text, .data, .bss sections not present for this kernel module.

I have downloaded the kernel source from https://github.com/beagleboard

Linux kernel version: 5.10.120

Thanks in advance.

Why the.text, .data, .bss sections not present for this kernel module?

TL;DR: Because you haven't coded any.

The macros, module_init() and module_exit() place those functions in the init and exit sections.

s32 gval = 200; is only references by the init and exit code and the tools have deduced that just the constant 200 can be used.

You need to add non-init and non-exit code and then the tools will start to put things in.text, .data and.bss.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM