我正在尝试为sbc1651编写模块。由于设备是ARM,因此需要交叉编译。首先,我正在尝试编译" Hello Kernel"模块找到here。这在我的x86开发系统上编译得很好,但是当我尝试交叉编译时,我收到以下警告。
/home/developer/HelloKernel/hello-1.mod.c:14: warning: missing initializer
/home/developer/HelloKernel/hello-1.mod.c:14: warning: (near initialization for '__this_module.arch.unw_sec_init')
由于这是自动生成的.mod.c文件,我不知道发生了什么。 mod.c文件似乎是由module.h文件生成的。据我所知,我的x86系统的module.h和arm内核头的module.h之间的相关部分是相同的。
令我困惑的是,这个问题要么不是可谷歌的(由我......),要么以前没有发生过任何事情。或者我只是做一些毫无根据的事情,任何有意义的人都不会这样做。
我使用的交叉编译器是由飞思卡尔提供的(我认为)。我想这可能是编译器的一个问题。是否值得尝试自己构建工具链?显然,既然这是一个警告,我可以忽略它,但由于它如此奇怪,我很担心,并且至少知道原因......
非常感谢,
Sompom
以下是源文件
你好-1.mod.c
#include <linux/module.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>
MODULE_INFO(vermagic, VERMAGIC_STRING);
struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};
static const struct modversion_info ____versions[]
__used
__attribute__((section("__versions"))) = {
{ 0x3972220f, "module_layout" },
{ 0xefd6cf06, "__aeabi_unwind_cpp_pr0" },
{ 0xea147363, "printk" },
};
static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";
hello-1.c(从给定链接略微修改)
/* hello-1.c - The simplest kernel module.
*
* Copyright (C) 2001 by Peter Jay Salzman
*
* 08/02/2006 - Updated by Rodrigo Rubira Branco <rodrigo@kernelhacking.com>
*/
/* Kernel Programming */
#ifndef MODULE
#define MODULE
#endif
#ifndef LINUX
#define LINUX
#endif
#ifndef __KERNEL__
#define __KERNEL__
#endif
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
static int hello_init_module(void)
{
printk(KERN_ALERT "Hello world 1.\n");
/* A non 0 return means init_module failed; module can't be loaded.*/
return 0;
}
static void hello_cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}
module_init(hello_init_module);
module_exit(hello_cleanup_module);
MODULE_LICENSE("GPL");
生成文件
export ARCH:=arm
export CCPREFIX:=/opt/freescale/usr/local/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/arm-linux-
export CROSS_COMPILE:=${CCPREFIX}
TARGET := hello-1
WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wno-sign-compare -Wno-unused -Werror
UNUSED_FLAGS := -std=c99 -pedantic
EXTRA_CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
KDIR ?= /home/developer/src/ltib-microsys/ltib/rpm/BUILD/linux-2.6.35.3
ifneq ($(KERNELRELEASE),)
# kbuild part of makefile
obj-m := $(TARGET).o
else
# normal makefile
default: clean
$(MAKE) -C $(KDIR) M=$$PWD
.PHONY: clean
clean:
-rm built-in.o
-rm $(TARGET).ko
-rm $(TARGET).ko.unsigned
-rm $(TARGET).mod.c
-rm $(TARGET).mod.o
-rm $(TARGET).o
-rm modules.order
-rm Module.symvers
endif
答案 0 :(得分:1)
显然MODULE_ARCH_INIT
是一个定义为某种{ ... }
初始化程序的宏。 GCC以这样的初始化者发布过于偏执(和彻头彻尾的恶意)警告而闻名,因为它们不覆盖目标聚合中的每个字段,即使语言规范说一切正常。
以下是针对完全安全(和惯用)= { 0 }
初始化程序发出警告的示例:Why is the compiler throwing this warning: "missing initializer"? Isn't the structure initialized?
我猜你的MODULE_ARCH_INIT
被定义为不覆盖目标结构的每个字段并且由于同样的原因触发相同的警告。
语言保证在这种情况下,非覆盖字段是零初始化的,但GCC只是不确定零是否是您想用这些字段初始化的。因此警告。