Date: Mon, 18 Mar 2013 10:21:50 -0700 From: Godfrey van der Linden <gvdl@mac.com> To: freebsd-hackers@freebsd.org Subject: kmod linking is very strange Message-ID: <8B0E0420-3E21-4230-97BC-1689225E1B5A@mac.com> References: <A649469B-7760-42FA-9859-316FA04AFE4E@juniper.net>
next in thread | previous in thread | raw e-mail | index | archive | help
I posted this to current, but was steered to hackers.=20 Begin forwarded message: > From: Godfrey Van der Linden <gvdl@juniper.net> > Subject: kmod linking is very strange > Date: 15March, 2013 16:46:13 PDT > To: freebsd-current@freebsd.org >=20 > G'day, All. >=20 > First post so please be gentle ;-). Are the barracudas here? >=20 > Summary: >=20 > 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. >=20 > In Detail: >=20 > Due to another bug in sys/conf/kmod.mk, = (http://www.freebsd.org/cgi/query-pr.cgi?pr=3D177008, contains a patch) = the miibus.ko exports no symbols. I.e. symbols are 'static'.=20 >=20 > 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. >=20 > /* If we have not found it, look at the full table (if loaded) = */ > if (ef->symtab =3D=3D ef->ddbsymtab) > return (ENOENT); >=20 > /* Exhaustive search */ > for (i =3D 0, symp =3D ef->ddbsymtab; i < ef->ddbsymcnt; i++, = symp++) { > strp =3D ef->ddbstrtab + symp->st_name; > if (strcmp(name, strp) =3D=3D 0) { > if (symp->st_shndx !=3D SHN_UNDEF || > (symp->st_value !=3D 0 && > ELF_ST_TYPE(symp->st_info) =3D=3D = STT_FUNC)) { > *sym =3D (c_linker_sym_t) symp; > return (0); > } > return (ENOENT); > } > } >=20 > This code walks the ddbsymtab looking for any symbol, including = locals. >=20 > Any kernel that is not built with DDB or any MODULE_DEPEND dependency = .ko that is stripped will break module loading. >=20 >=20 > Godfrey van der Linden > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to = "freebsd-current-unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8B0E0420-3E21-4230-97BC-1689225E1B5A>