From owner-freebsd-stable@freebsd.org Wed Jul 15 08:17:30 2015 Return-Path: Delivered-To: freebsd-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A208A9A2A91 for ; Wed, 15 Jul 2015 08:17:30 +0000 (UTC) (envelope-from janm@transactionware.com) Received: from mail3.transactionware.com (mail.transactionware.com [203.14.245.7]) by mx1.freebsd.org (Postfix) with SMTP id 2B53915D3 for ; Wed, 15 Jul 2015 08:17:29 +0000 (UTC) (envelope-from janm@transactionware.com) Received: (qmail 35238 invoked by uid 907); 15 Jul 2015 08:17:21 -0000 Received: from Unknown (HELO jmmacpro.tmst.com.au) (203.14.245.130) (smtp-auth username janm, mechanism plain) by mail3.transactionware.com (qpsmtpd/0.84) with (ECDHE-RSA-AES256-SHA encrypted) ESMTPSA; Wed, 15 Jul 2015 18:17:21 +1000 From: Jan Mikkelsen Subject: amd64 kernel dynamic linking allows extern references to statics Date: Wed, 15 Jul 2015 18:17:20 +1000 Message-Id: <13C52D9D-E1E6-4F83-A881-4E867C336B31@transactionware.com> Cc: Karl Denninger To: FreeBSD Stable Mailing List Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2102\)) X-Mailer: Apple Mail (2.2102) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jul 2015 08:17:30 -0000 Hi, (All on 10.2-BETA1.) I noticed that the latest patch in the bug = https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D187594 = works on = amd64 but fails to load zfs.ko on i386 with a symbol not found error. Looking at the patch, there is one file that has =E2=80=9Cextern int = zio_use_uma=E2=80=9D to reference a variable that is declared elsewhere = as =E2=80=9Cstatic int zio_use_uma=E2=80=9D. To me this obviously should = not work. However it does work on amd64 but fails on i386. Below is a small test case that reproduces the problem. The generated = kernel module loads on amd64 but fails on i386. On amd64 one compilation = unit is accessing a static in from another compilation unit by declaring = the variable =E2=80=9Cextern=E2=80=9D.=20 I haven=E2=80=99t looked further to attempt to find the bug. However, it = looks like a Bad Thing=E2=84=A2 to me. Regards, Jan. =E2=80=94=E2=80=94Makefile: KMOD=3D refstatic SRCS=3D refstatic.c testfunc.c bus_if.h device_if.h pci_if.h .include =E2=80=94=E2=80=94 refstatic.c: #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int testvar =3D 1; int func(void); static int refstatic_probe(device_t dev) { ++testvar; device_printf(dev, "func returns %d\n", func()); return ENXIO; } static int refstatic_attach(device_t dev) { (void) dev; return ENXIO; } static int refstatic_detach(device_t dev) { return 0; } static device_method_t refstatic_methods[] =3D { DEVMETHOD(device_probe, refstatic_probe), DEVMETHOD(device_attach, refstatic_attach), DEVMETHOD(device_detach, refstatic_detach), { 0, 0 } }; static driver_t refstatic_driver =3D { "refstatic", refstatic_methods, 64 }; static devclass_t refstatic_devclass; DRIVER_MODULE(refstatic, pci, refstatic_driver, refstatic_devclass, 0, = 0); =E2=80=94=E2=80=94testfunc.c: extern int testvar; int func(void); int func(void) { return testvar; }