From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 18 17:21:59 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 278E4B9D for ; Mon, 18 Mar 2013 17:21:59 +0000 (UTC) (envelope-from gvdl@mac.com) Received: from st11p01mm-asmtp004.mac.com (st11p01mm-asmtp004.mac.com [17.172.204.239]) by mx1.freebsd.org (Postfix) with ESMTP id 00267ACA for ; Mon, 18 Mar 2013 17:21:58 +0000 (UTC) Received: from gvdl-mbp15.jnpr.net (natint3.juniper.net [66.129.224.36]) by st11p01mm-asmtp004.mac.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Jan 3 2012)) with ESMTPSA id <0MJV000499KEGZ60@st11p01mm-asmtp004.mac.com> for freebsd-hackers@freebsd.org; Mon, 18 Mar 2013 17:21:52 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8626,1.0.431,0.0.0000 definitions=2013-03-18_01:2013-03-18,2013-03-18,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=18 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1302030000 definitions=main-1303180134 From: Godfrey van der Linden Subject: kmod linking is very strange Date: Mon, 18 Mar 2013 10:21:50 -0700 References: To: freebsd-hackers@freebsd.org Message-id: <8B0E0420-3E21-4230-97BC-1689225E1B5A@mac.com> MIME-version: 1.0 (Mac OS X Mail 6.1 \(1498\)) X-Mailer: Apple Mail (2.1498) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Mar 2013 17:21:59 -0000 I posted this to current, but was steered to hackers.=20 Begin forwarded message: > From: Godfrey Van der Linden > 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"