kmod linking is very strange

Godfrey van der Linden gvdl at mac.com
Mon Mar 18 17:21:59 UTC 2013


I posted this to current, but was steered to hackers. 

Begin forwarded message:

> From: Godfrey Van der Linden <gvdl at juniper.net>
> Subject: kmod linking is very strange
> Date: 15March, 2013 16:46:13 PDT
> To: freebsd-current at freebsd.org
> 
> G'day, All.
> 
> First post so please be gentle ;-). Are the barracudas here?
> 
> Summary:
> 
> Module link-elf will link against static symbols and will fail if the kernel is not compiled with DDB or the required MODULE_DEPEND has been stripped of local symbols, see nm -g miibus.ko. I propose that we add a sysctl & associated boot arg that only allows kmod loading against externally visible symbols. Then in 11 we can enable this flag by default.
> 
> In Detail:
> 
> Due to another bug in sys/conf/kmod.mk, (http://www.freebsd.org/cgi/query-pr.cgi?pr=177008, contains a patch) the miibus.ko exports no symbols.  I.e. symbols are 'static'. 
> 
> sys/kern/link-elf.c:link_elf_lookup_symbol() is the culprit. After determining that an external symbol can't be found, it does the following.
> 
>        /* If we have not found it, look at the full table (if loaded) */
>        if (ef->symtab == ef->ddbsymtab)
>                return (ENOENT);
> 
>        /* Exhaustive search */
>        for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
>                strp = ef->ddbstrtab + symp->st_name;
>                if (strcmp(name, strp) == 0) {
>                        if (symp->st_shndx != SHN_UNDEF ||
>                            (symp->st_value != 0 &&
>                             ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
>                                *sym = (c_linker_sym_t) symp;
>                                return (0);
>                        }
>                        return (ENOENT);
>                }
>        }
> 
> This code walks the ddbsymtab looking for any symbol, including locals.
> 
> Any kernel that is not built with DDB or any MODULE_DEPEND dependency .ko that is stripped will break module loading.
> 
> 
> Godfrey van der Linden
> _______________________________________________
> freebsd-current at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe at freebsd.org"



More information about the freebsd-hackers mailing list