kbuild - status on section mismatch warnings
During the last weeks I have worked on improved support for section mismatch checks.
When a function is marked __init then the implementation will be placed in a section named .init.text - that section will be discarded by vmlinux when the module is initialised.
So therefore any references to function marked __init are subject to references to functions that may suddenly disappear.
So the section mismatch checks originally implmented by Keith Ownes try to find all cases where a function outside .init.text reference a function declared inside a section named .init.text - this is a potential oops candidate.
To add to this picture we have several functions marked __devinit, where __devinit result in functions being marked __init _only_ when HOTPLUG is not enabled.
After chasing a number of false positives I am now on 86 warnings for an allmodconfig build for sparc64.
Browsing throug the warnings several warnings points to harmless constructs as for example init_module() which is not declared __init and so on, but others points to real bugs that ought to be fixed.
The typical pattern is:
static void __init foo(void)
{
...
}static void __devinit init_bar(void)
{
foo(); <= boom....
}When HOTPLUG is enabled we may call init_bar() at any point in time, but when init_bar() then calls foo() placed in __init section we go oops because the original foo() implmentation has been freed and is overwritten by something else.
I have fixed a few of the section mismatch warnings on the way, but so far the effort has been concentrated on the algorithm.
The fixes are not included in the output posted below.
A kernel has been test-compiled (defconfig + allmodconfig) for following architectures:x86_64, ia64, ppc64 and sparc64.
For each architecture a new workaround was needed to fix false positives but now the result looks good all over these four architectures.
The algorith I consider ready for 2.6.17 as sson as it opens up. And I hope that relevant people will pick up in their area and get the warnings fixed.
The patches are all pushed to my kbuild.git tree at git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild.git - and will be available in next -mm.
I you have trouble understanding the warning for a particular driver I will gladly try to help.
Sam
For reference is attached the output from a sparc64 run on 2.6.16-rc4-something:
Drivers that causes warnings:
arch/sparc64/solaris/solaris.odrivers/atm/fore_200e.odrivers/atm/he.odrivers/atm/horizon.odrivers/atm/lanai.odrivers/atm/zatm.odrivers/block/cpqarray.odrivers/block/floppy.odrivers/char/ip2main.odrivers/cpufreq/cpufreq_stats.odrivers/ide/ide-core.odrivers/isdn/hisax/hisax.odrivers/media/dvb/bt8xx/dvb-bt8xx.odrivers/media/dvb/ttpci/dvb-ttpci.odrivers/net/acenic.odrivers/net/de620.odrivers/net/myri_sbus.odrivers/net/pcnet32.odrivers/net/rrunner.odrivers/net/sis900.odrivers/net/tokenring/3c359.odrivers/scsi/esp.odrivers/scsi/fcal.odrivers/scsi/megaraid/megaraid_mbox.odrivers/scsi/pluto.odrivers/scsi/qla1280.odrivers/scsi/qlogicpti.odrivers/usb/gadget/g_serial.odrivers/usb/gadget/g_zero.odrivers/video/aty/atyfb.odrivers/video/macmodes.odrivers/video/savage/savagefb.odrivers/video/tridentfb.ofs/jffs2/jffs2.onet/ipv4/netfilter/ip_conntrack.onet/ipv4/netfilter/iptable_nat.osound/oss/cs46xx.osound/oss/forte.osound/oss/msnd.o
And the warnings themself:
WARNING: arch/sparc64/solaris/solaris.o - Section mismatch: reference to .init.text:init_socksys from .text between 'init_module' (at offset 0x3848) and 'cleanup_module'
WARNING: drivers/atm/fore_200e.o - Section mismatch: reference to .init.text:fore200e_init from .text between 'fore200e_pca_detect' (at offset 0x2d14) and 'fore200e_pca_remove_one'
WARNING: drivers/atm/he.o - Section mismatch: reference to .init.text:he_start from .text between 'he_init_one' (at offset 0x158) and 'he_remove_one'
WARNING: drivers/atm/horizon.o - Section mismatch: reference to .init.text:hrz_init from .text between 'hrz_probe' (at offset 0x3d04) and 'hrz_remove_one'
WARNING: drivers/atm/lanai.o - Section mismatch: reference to .init.text: from .text between 'sram_test_pass' (at offset 0x1e8) and 'sram_test_and_clear'
WARNING: drivers/atm/zatm.o - Section mismatch: reference to .init.text: from .text after 'zatm_init_one' (at offset 0x2cd0)
WARNING: drivers/atm/zatm.o - Section mismatch: reference to .init.text:zatm_start from .text after 'zatm_init_one' (at offset 0x2ce4)
WARNING: drivers/block/cpqarray.o - Section mismatch: reference to .init.text: from .text between 'cpqarray_register_ctlr' (at offset 0x9e8) and 'alloc_cpqarray_hba'
WARNING: drivers/block/floppy.o - Section mismatch: reference to .init.text:parse_floppy_cfg_string from .text between 'init_module' (at offset 0x91dc) and 'cleanup_module'
WARNING: drivers/block/floppy.o - Section mismatch: reference to .init.text:floppy_init from .text between 'init_module' (at offset 0x91e4) and 'cleanup_module'
WARNING: drivers/char/ip2main.o - Section mismatch: reference to .init.text:have_requested_irq from .text between 'cleanup_module' (at offset 0x2cd8) and 'ip2_loadmain'
WARNING: drivers/char/ip2main.o - Section mismatch: reference to .init.text:clear_requested_irq from .text between 'cleanup_module' (at offset 0x2cfc) and 'ip2_loadmain'
WARNING: drivers/char/ip2main.o - Section mismatch: reference to .init.text: from .text between 'ip2_loadmain' (at offset 0x3024) and 'set_irq'
WARNING: drivers/char/ip2main.o - Section mismatch: reference to .init.text:find_eisa_board from .text between 'ip2_loadmain' (at offset 0x312c) and 'set_irq'
WARNING: drivers/char/ip2main.o - Section mismatch: reference to .init.text:ip2_init_board from .text between 'ip2_loadmain' (at offset 0x3244) and 'set_irq'
WARNING: drivers/char/ip2main.o - Section mismatch: reference to .init.text:have_requested_irq from .text between 'ip2_loadmain' (at offset 0x3570) and 'set_irq'
WARNING: drivers/char/ip2main.o - Section mismatch: reference to .init.text:mark_requested_irq from .text between 'ip2_loadmain' (at offset 0x3608) and 'set_irq'
WARNING: drivers/cpufreq/cpufreq_stats.o - Section mismatch: reference to .init.text: from .data between 'cpufreq_stat_cpu_notifier' (at offset 0xf8) and 'notifier_policy_block'
WARNING: drivers/cpufreq/cpufreq_stats.o - Section mismatch: reference to .init.text: from .exit.text after 'cleanup_module' (at offset 0x70)
WARNING: drivers/ide/ide-core.o - Section mismatch: reference to .init.text:parse_options from .text between 'init_module' (at offset 0x215c) and 'cleanup_module'
WARNING: drivers/ide/ide-core.o - Section mismatch: reference to .init.text:ide_init from .text between 'init_module' (at offset 0x2164) and 'cleanup_module'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:setup_s0box from .text between 'checkcard' (at offset 0xe64) and 'HiSax_shiftcards'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:setup_avm_pcipnp from .text between 'checkcard' (at offset 0xe84) and 'HiSax_shiftcards'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:setup_diva from .text between 'checkcard' (at offset 0xea4) and 'HiSax_shiftcards'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:setup_niccy from .text between 'checkcard' (at offset 0xed4) and 'HiSax_shiftcards'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:setup_bkm_a4t from .text between 'checkcard' (at offset 0xee4) and 'HiSax_shiftcards'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:setup_sct_quadro from .text between 'checkcard' (at offset 0xef4) and 'HiSax_shiftcards'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:setup_gazel from .text between 'checkcard' (at offset 0xf04) and 'HiSax_shiftcards'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:setup_w6692 from .text between 'checkcard' (at offset 0xf14) and 'HiSax_shiftcards'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:inithdlc from .text between 'AVM_card_msg' (at offset 0x29d34) and 'ReadHDLCPnP'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:init_ipacx from .text between 'Diva_card_msg' (at offset 0x30fe0) and 'ph_command'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:clear_pending_jade_ints from .text between 'BKM_card_msg' (at offset 0x40d48) and 'jade_write_indirect'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:initjade from .text between 'BKM_card_msg' (at offset 0x40d58) and 'jade_write_indirect'
WARNING: drivers/isdn/hisax/hisax.o - Section mismatch: reference to .init.text:initW6692 from .text after 'w6692_card_msg' (at offset 0x47098)
WARNING: drivers/media/dvb/bt8xx/dvb-bt8xx.o - Section mismatch: reference to .init.text: from .text between 'dvb_bt8xx_probe' (at offset 0x148c) and 'dvb_bt8xx_remove'
WARNING: drivers/media/dvb/bt8xx/dvb-bt8xx.o - Section mismatch: reference to .init.text:dvb_bt8xx_load_card from .text between 'dvb_bt8xx_probe' (at offset 0x1518) and 'dvb_bt8xx_remove'
WARNING: drivers/media/dvb/ttpci/dvb-ttpci.o - Section mismatch: reference to .init.text:av7110_ir_init from .text between 'av7110_attach' (at offset 0xef1c) and 'av7110_detach'
WARNING: drivers/media/dvb/ttpci/dvb-ttpci.o - Section mismatch: reference to .exit.text:av7110_ir_exit from .text between 'av7110_detach' (at offset 0xf038) and 'av7110_irq'
WARNING: drivers/net/acenic.o - Section mismatch: reference to .init.data: from .text between 'ace_load_firmware' (at offset 0x3a70) and 'eeprom_start'
WARNING: drivers/net/acenic.o - Section mismatch: reference to .init.data: from .text between 'ace_load_firmware' (at offset 0x3a84) and 'eeprom_start'
WARNING: drivers/net/acenic.o - Section mismatch: reference to .init.data:tigon2FwRodata from .text between 'ace_load_firmware' (at offset 0x3a8c) and 'eeprom_start'
WARNING: drivers/net/acenic.o - Section mismatch: reference to .init.data:tigon2FwRodata from .text between 'ace_load_firmware' (at offset 0x3a9c) and 'eeprom_start'
WARNING: drivers/net/acenic.o - Section mismatch: reference to .init.data:tigon2FwData from .text between 'ace_load_firmware' (at offset 0x3aac) and 'eeprom_start'
WARNING: drivers/net/acenic.o - Section mismatch: reference to .init.data:tigon2FwData from .text between 'ace_load_firmware' (at offset 0x3ac0) and 'eeprom_start'
WARNING: drivers/net/de620.o - Section mismatch: reference to .init.text:de620_probe from .text between 'init_module' (at offset 0x2714) and 'cleanup_module'
WARNING: drivers/net/myri_sbus.o - Section mismatch: reference to .init.data: from .text between 'myri_load_lanai' (at offset 0x1f8) and 'myri_clean_rings'
WARNING: drivers/net/myri_sbus.o - Section mismatch: reference to .init.data: from .text between 'myri_load_lanai' (at offset 0x1fc) and 'myri_clean_rings'
WARNING: drivers/net/myri_sbus.o - Section mismatch: reference to .init.data:lanai4_data from .text between 'myri_load_lanai' (at offset 0x240) and 'myri_clean_rings'
WARNING: drivers/net/myri_sbus.o - Section mismatch: reference to .init.data:lanai4_data from .text between 'myri_load_lanai' (at offset 0x244) and 'myri_clean_rings'
WARNING: drivers/net/pcnet32.o - Section mismatch: reference to .init.data: from .text between 'pcnet32_probe_vlbus' (at offset 0x133c) and 'pcnet32_probe_pci'
WARNING: drivers/net/pcnet32.o - Section mismatch: reference to .init.data: from .text between 'pcnet32_probe_vlbus' (at offset 0x1340) and 'pcnet32_probe_pci'
WARNING: drivers/net/pcnet32.o - Section mismatch: reference to .init.data: from .text between 'pcnet32_probe_vlbus' (at offset 0x134c) and 'pcnet32_probe_pci'
WARNING: drivers/net/rrunner.o - Section mismatch: reference to .init.text:rr_init from .text between 'rr_init_one' (at offset 0x304) and 'rr_remove_one'
WARNING: drivers/net/sis900.o - Section mismatch: reference to .init.text:sis900_mii_probe from .text between 'sis900_probe' (at offset 0x598) and 'sis900_default_phy'
WARNING: drivers/net/tokenring/3c359.o - Section mismatch: reference to .init.text:xl_init from .text between 'xl_probe' (at offset 0x300) and 'xl_hw_reset'
WARNING: drivers/scsi/esp.o - Section mismatch: reference to .init.text:esp_detect from .data after 'driver_template' (at offset 0x530)
WARNING: drivers/scsi/fcal.o - Section mismatch: reference to .init.text:fcal_detect from .data after 'driver_template' (at offset 0x1a8)
WARNING: drivers/scsi/megaraid/megaraid_mbox.o - Section mismatch: reference to .init.text:megaraid_init_mbox from .text between 'megaraid_probe_one' (at offset 0x228) and 'megaraid_detach_one'
WARNING: drivers/scsi/pluto.o - Section mismatch: reference to .init.text:pluto_detect from .data after 'driver_template' (at offset 0x80)
WARNING: drivers/scsi/qla1280.o - Section mismatch: reference to .init.data: from .text between 'qla1280_get_token' (at offset 0x43a0) and 'qla1280_probe_one'
WARNING: drivers/scsi/qla1280.o - Section mismatch: reference to .init.data: from .text between 'qla1280_get_token' (at offset 0x43a8) and 'qla1280_probe_one'
WARNING: drivers/scsi/qlogicpti.o - Section mismatch: reference to .init.text:qpti_chain_del from .text between 'qlogicpti_release' (at offset 0xba0) and 'qlogicpti_info'
WARNING: drivers/scsi/qlogicpti.o - Section mismatch: reference to .init.text:qlogicpti_detect from .data after 'driver_template' (at offset 0xf8)
WARNING: drivers/usb/gadget/g_serial.o - Section mismatch: reference to .init.text:usb_ep_autoconfig_reset from .text between 'gs_bind' (at offset 0x10e4) and 'gs_unbind'
WARNING: drivers/usb/gadget/g_serial.o - Section mismatch: reference to .init.text:usb_ep_autoconfig from .text between 'gs_bind' (at offset 0x10f4) and 'gs_unbind'
WARNING: drivers/usb/gadget/g_serial.o - Section mismatch: reference to .init.text:usb_ep_autoconfig from .text between 'gs_bind' (at offset 0x111c) and 'gs_unbind'
WARNING: drivers/usb/gadget/g_serial.o - Section mismatch: reference to .init.text:usb_ep_autoconfig from .text between 'gs_bind' (at offset 0x1158) and 'gs_unbind'
WARNING: drivers/usb/gadget/g_zero.o - Section mismatch: reference to .init.text:usb_ep_autoconfig_reset from .text between 'zero_bind' (at offset 0x172c) and 'zero_suspend'
WARNING: drivers/usb/gadget/g_zero.o - Section mismatch: reference to .init.text:usb_ep_autoconfig from .text between 'zero_bind' (at offset 0x1738) and 'zero_suspend'
WARNING: drivers/usb/gadget/g_zero.o - Section mismatch: reference to .init.text:usb_ep_autoconfig from .text between 'zero_bind' (at offset 0x1780) and 'zero_suspend'
WARNING: drivers/video/aty/atyfb.o - Section mismatch: reference to .init.text:aty_init from .text between 'atyfb_pci_probe' (at offset 0x2fe4) and 'atyfb_remove'
WARNING: drivers/video/macmodes.o - Section mismatch: reference to .init.text:mac_find_mode from __ksymtab after '__ksymtab_mac_find_mode' (at offset 0x30)
WARNING: drivers/video/savage/savagefb.o - Section mismatch: reference to .init.data: from .text between 'savagefb_probe' (at offset 0x4c34) and 'savagefb_remove'
WARNING: drivers/video/savage/savagefb.o - Section mismatch: reference to .init.data: from .text between 'savagefb_probe' (at offset 0x4c38) and 'savagefb_remove'
WARNING: drivers/video/tridentfb.o - Section mismatch: reference to .init.text:get_memsize from .text between 'trident_pci_probe' (at offset 0x2acc) and 'trident_pci_remove'
WARNING: drivers/video/tridentfb.o - Section mismatch: reference to .init.text:get_displaytype from .text between 'trident_pci_probe' (at offset 0x2b34) and 'trident_pci_remove'
WARNING: drivers/video/tridentfb.o - Section mismatch: reference to .init.text:get_nativex from .text between 'trident_pci_probe' (at offset 0x2b4c) and 'trident_pci_remove'
WARNING: fs/jffs2/jffs2.o - Section mismatch: reference to .init.text:jffs2_zlib_init from .text between 'jffs2_compressors_init' (at offset 0x75c) and 'jffs2_compressors_exit'
WARNING: net/ipv4/netfilter/ip_conntrack.o - Section mismatch: reference to .init.text:ip_conntrack_init from .text between 'init_or_cleanup' (at offset 0xaac) and 'ip_conntrack_protocol_register'
WARNING: net/ipv4/netfilter/iptable_nat.o - Section mismatch: reference to .init.text:ip_nat_rule_init from .text after 'init_or_cleanup' (at offset 0xd88)
WARNING: sound/oss/cs46xx.o - Section mismatch: reference to .init.text: from .text between 'cs_hardware_init' (at offset 0x96c4) and 'cs46xx_probe'
WARNING: sound/oss/forte.o - Section mismatch: reference to .init.text: from .text between 'forte_chip_init' (at offset 0x2894) and 'forte_remove'
WARNING: sound/oss/msnd.o - Section mismatch: reference to .init.text:msnd_register from __ksymtab between '__ksymtab_msnd_register' (at offset 0x0) and '__ksymtab_msnd_unregister'
Quoted 8 lines · Sam Ravnborg
During the last weeks I have worked on improved support for section mismatch checks.
When a function is marked
__initthen the implementation will be placed in a section named .init.text - that section will be discarded by vmlinux when the module is initialised.
So therefore any references to function marked__initare subject to references to functions that may suddenly disappear.
Now try x86 with sd.o non-modular. And see
__init foo()
{
....
switch(n) {
....
....
}
}compiling essentially into
if (n < lower || n > upper) goto Ldefault; addr = const_array_of_labels[n - lower]; goto addr;
with const_array_of_labels sitting in .rodata and its contents pointing inside foo(), i.e. into .init.text. And yes, .init.text is discarded, while .rodata is left intact. Since the only reference to that array disappears along with .init.text *and* section where array goes into is hardwired into gcc, we
a) are actually OK and
b) can't do anything about that false positive, AFAICS.
Hi Al.
Quoted 11 lines
Now try x86 with sd.o non-modular. And see
__initfoo()
{
....switch(n) { .... .... } }
Hmm, in my tree sd.o has no switch in the init function. But that does not change your point which is valid indeed.
Quoted 7 lines
compiling essentially into
if (n < lower || n > upper) goto Ldefault; addr = const_array_of_labels[n - lower]; goto addr;
Quoted 7 lines
with
const_array_of_labelssitting in .rodata and its contents pointing insidefoo(), i.e. into .init.text. And yes, .init.text is discarded, while .rodata is left intact. Since the only reference to that array disappears along with .init.text *and* section where array goes into is hardwired into gcc, we
a) are actually OK and
b) can't do anything about that false positive, AFAICS.
For the same reason references to .init.text from .rodata are not warned upon - there are simply too many compielr generated false positives.
Following is the original comment from reference_init.pl:
* Unfortunately references to read only data that referenced .init
* sections had to be excluded. Almost all of these are false
* positives, they are created by gcc. The downside of excluding rodata
* is that there really are some user references from rodata to
* init code, e.g. drivers/video/vgacon.c:
*
* const struct consw vga_con = {
* con_startup: vgacon_startup,
*
* where vgacon_startup is __init. If you want to wade through
* the false
* positives, take out the check for rodata.
And this is unfortunate since we cannot do a full check, but we do a better job than before and warn for many of the trivial cases. Judging the amount of warnings already generated this is worth checking.
Sam
Quoted 49 lines · Sam Ravnborg
Hi Al.
Quoted 11 lines
Now try x86 with sd.o non-modular. And see
__initfoo()
{
....switch(n) { .... .... } }Hmm, in my tree sd.o has no switch in the init function. But that does not change your point which is valid indeed.
Quoted 7 lines
compiling essentially into
if (n < lower || n > upper) goto Ldefault; addr = const_array_of_labels[n - lower]; goto addr;Quoted 7 lines
with
const_array_of_labelssitting in .rodata and its contents pointing insidefoo(), i.e. into .init.text. And yes, .init.text is discarded, while .rodata is left intact. Since the only reference to that array disappears along with .init.text *and* section where array goes into is hardwired into gcc, we
a) are actually OK and
b) can't do anything about that false positive, AFAICS.For the same reason references to .init.text from .rodata are not warned upon - there are simply too many compielr generated false positives.
Following is the original comment from reference_init.pl:
* Unfortunately references to read only data that referenced .init
* sections had to be excluded. Almost all of these are false
* positives, they are created by gcc. The downside of excluding rodata
* is that there really are some user references from rodata to
* init code, e.g.drivers/video/vgacon.c:
*
* const struct conswvga_con= {
*con_startup:vgacon_startup,
*
* wherevgacon_startupis__init. If you want to wade through
* the false
* positives, take out the check for rodata.
Quoted 3 lines
And this is unfortunate since we cannot do a full check, but we do a better job than before and warn for many of the trivial cases. Judging the amount of warnings already generated this is worth checking.
I think the best way to be with an extension to sparse to check calls from non-init marked code do not to go to items marked init unless forced to.
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Quoted 8 lines · Ben Dooks
Quoted 4 lines
And this is unfortunate since we cannot do a full check, but we do a better job than before and warn for many of the trivial cases. Judging the amount of warnings already generated this is worth checking.
I think the best way to be with an extension to sparse to check calls from non-init marked code do not to go to items marked init unless forced to.
Should be doable yes. Maybe even with current infrastructure? The advantage being that the check in modpost is run each time you build your modules so much harder to overlook.
Sam
Quoted 13 lines · Sam Ravnborg
Hi Al.
Quoted 11 lines
Now try x86 with sd.o non-modular. And see
__initfoo()
{
....switch(n) { .... .... } }
Quoted 2 lines
Hmm, in my tree sd.o has no switch in the init function. But that does not change your point which is valid indeed.
sd_major() gets inlined there with sufficiently recent gcc.
Quoted 4 lines
For the same reason references to .init.text from .rodata are not warned upon - there are simply too many compielr generated false positives.
Following is the original comment from reference_init.pl:
Oops, right you are - it's reference_discarded that gets buggered on that. My apologies. Still gets a spew on make buildcheck, though...