【问题标题】:.ko file isn't produced after the make commandmake 命令后不生成 .ko 文件
【发布时间】:2011-12-15 19:19:26
【问题描述】:

我正在尝试编译一个简单的 hello world 内核模块,但是在 make 命令之后,我收到了以下警告并且没有生成 moduleName.ko 文件。问题的原因是什么?警告是否会阻止生成 .ko 文件?我该如何解决这个问题?谢谢。

make 命令后的输出:

make -C /lib/modules/2.6.20.15-custom/build SUBDIRS= modules
make[1]: Entering directory `/usr/src/linux-2.6.20.15'
CHK     include/linux/version.h
CHK     include/linux/utsrelease.h
Building modules, stage 2.
MODPOST 1595 modules
WARNING: vmlinux - Section mismatch: reference to .init.data:boot_params from .text be tween '_text' (at offset 0xc0100036) and 'startup_32_smp'
WARNING: vmlinux - Section mismatch: reference to .init.data:boot_params from .text between '_text' (at offset 0xc0100044) and 'startup_32_smp'
WARNING: vmlinux - Section mismatch: reference to .init.data:init_pg_tables_end from .text between '_text' (at offset 0xc01000a6) and 'startup_32_smp'
WARNING: vmlinux - Section mismatch: reference to .init.text:start_kernel from .text between 'is386' (at offset 0xc0100221) and 'check_x87'
WARNING: vmlinux - Section mismatch: reference to .init.text:smp_prepare_cpus from .text between 'init' (at offset 0xc0100438) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:migration_init from .text between 'init' (at offset 0xc010043d) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:spawn_ksoftirqd from .text between 'init' (at offset 0xc0100442) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:spawn_softlockup_task from .text between 'init' (at offset 0xc0100447) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:smp_cpus_done from .text between 'init' (at offset 0xc01004bf) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:sched_init_smp from .text between 'init' (at offset 0xc01004c4) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:cpuset_init_smp from .text between 'init' (at offset 0xc01004c9) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:usermodehelper_init from .text between 'init' (at offset 0xc01004d6) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:driver_init from .text between 'init' (at offset 0xc01004db) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:sysctl_init from .text between 'init' (at offset 0xc01004e1) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.data: from .text between 'init' (at offset 0xc0100507) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.data: from .text between 'init' (at offset 0xc0100524) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:prepare_namespace from .text between 'init' (at offset 0xc010070f) and 'rest_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:__alloc_bootmem from .text between 'init_gdt' (at offset 0xc010a1fb) and 'cpu_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:__alloc_bootmem from .text between 'init_gdt' (at offset 0xc010a211) and 'cpu_init'
WARNING: vmlinux - Section mismatch: reference to .init.text:sysenter_setup from .text between 'identify_cpu' (at offset 0xc010a8de) and 'display_cacheinfo'
WARNING: vmlinux - Section mismatch: reference to .init.text:mtrr_bp_init from .text between 'identify_cpu' (at offset 0xc010a8e8) and 'display_cacheinfo'
WARNING: vmlinux - Section mismatch: reference to .init.text:trap_init_f00f_bug from .text between 'init_intel' (at offset 0xc010c7f5) and 'cpuid4_cache_lookup'
WARNING: vmlinux - Section mismatch: reference to .init.data:initkmem_list3 from .text between 'set_up_list3s' (at offset 0xc0170e0f) and 's_start'
WARNING: vmlinux - Section mismatch: reference to .init.text:eisa_root_register from .text between 'pci_eisa_init' (at offset 0xc0263ebb) and 'virtual_eisa_release'
WARNING: vmlinux - Section mismatch: reference to .init.text:eisa_root_register from .text between 'virtual_eisa_root_init' (at offset 0xc0263f1f) and 'cpufreq_unregister_driver'
WARNING: vmlinux - Section mismatch: reference to .init.text: from .text between 'iret_exc' (at offset 0xc02e8dbb) and '_etext'
WARNING: vmlinux - Section mismatch: reference to .init.text:start_kernel from .paravirtprobe between '__start_paravirtprobe' (at offset 0xc03b34b0) and '__stop_paravirtprobe'
make[1]: Leaving directory `/usr/src/linux-2.6.20.15'

【问题讨论】:

    标签: linux-kernel kernel kernel-module


    【解决方案1】:

    使用make -C /lib/modules/2.6.20.15-custom/build M=$$PWD$$PWD,也不需要modules)。

    【讨论】:

    • $$PWD 也应该更快,因为您不必为了调用 pwd 而生成额外的 shell。另一方面,$(PWD) 不起作用,因为我怀疑您是否在 makefile 中定义了此类。除此之外:1. 不要依赖环境变量(因为 shell 可能会故意保留它们),2. 不要包含你所期望的。
    【解决方案2】:

    我认为您的命令中缺少变量 M - 它应该指向模块源代码所在的路径:

    make -C path-to-linux-src M=path-to-module-src modules
    

    【讨论】:

    • 我使用 SUBDIRS 而不是 M。我尝试使用 M,但在输出中使用 M 而不是 SUBDIRS 得到了相同的结果。
    • @stedkka 在您的输出中,您没有为 SUBDIR 赋值 - 它应该是 SUBDIR=path-to-your-module-src
    • 在 Makefile 中,有一个SUBDIRS=$(PWD) modules 行。
    • @stedkka 尝试 SUBDIRS=$(shell pwd) 并在输出中查看 SUBDIR 是否有值。
    • @dimbaThis 工作正常。此外,jørgensen 的回答也有效。今天,我浪费了几个小时来解决这个问题。非常感谢。
    猜你喜欢
    • 2014-07-13
    • 2020-07-09
    • 1970-01-01
    • 2020-09-15
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 2019-09-12
    • 2021-12-04
    相关资源
    最近更新 更多