简体   繁体   English

.text、.bss、.data 部分未显示在 kernel 模块中

[英].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 模块和 Makefile 用于在 beagle-bone 板上运行的 linux。

/* 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.模块构建良好并生成test_km.ko文件,当test_km.ko文件为insmod时, /sys/modules/test_km/sections显示如下。

.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.为什么此 kernel 模块不存在.text、.data、.bss部分。

I have downloaded the kernel source from https://github.com/beagleboard我已经从https://github.com/beagleboard下载了 kernel 源

Linux kernel version: 5.10.120 Linux kernel 版本:5.10.120

Thanks in advance.提前致谢。

Why the.text, .data, .bss sections not present for this kernel module?为什么此 kernel 模块不存在 .text、.data、.bss 部分?

TL;DR: Because you haven't coded any. TL;DR:因为你没有编写任何代码。

The macros, module_init() and module_exit() place those functions in the init and exit sections.module_init()module_exit()将这些函数放在initexit部分。

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.仅由 init 和 exit 代码引用,工具推断只能使用常量 200。

You need to add non-init and non-exit code and then the tools will start to put things in.text, .data and.bss.您需要添加非初始化和非退出代码,然后工具将开始将内容放入.text、.data 和.bss。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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