From owner-freebsd-stable@freebsd.org Wed Jul 15 13:28:04 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 50F849A1483 for ; Wed, 15 Jul 2015 13:28:04 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BF36A1AD5 for ; Wed, 15 Jul 2015 13:28:03 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id t6FDRkCQ096729 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Wed, 15 Jul 2015 16:27:46 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t6FDRkCQ096729 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id t6FDRigm096728; Wed, 15 Jul 2015 16:27:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 15 Jul 2015 16:27:44 +0300 From: Konstantin Belousov To: Jan Mikkelsen Cc: FreeBSD Stable Mailing List , Karl Denninger Subject: Re: amd64 kernel dynamic linking allows extern references to statics Message-ID: <20150715132744.GD2404@kib.kiev.ua> References: <13C52D9D-E1E6-4F83-A881-4E867C336B31@transactionware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <13C52D9D-E1E6-4F83-A881-4E867C336B31@transactionware.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home 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 13:28:04 -0000 On Wed, Jul 15, 2015 at 06:17:20PM +1000, Jan Mikkelsen wrote: > Hi, > > (All on 10.2-BETA1.) > > I noticed that the latest patch in the bug https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=187594 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 ???extern int zio_use_uma??? to reference a variable that is declared elsewhere as ???static int zio_use_uma???. 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 ???extern???. > > I haven???t looked further to attempt to find the bug. However, it looks like a Bad Thing??? to me. > I am not sure that this is fixable. Issue is that amd64 modules are relinked object files, and they might have unresolved relocations against local symbols. Change like the following probably fix your test case, but also quite possible would break legitimate local references. diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c index 021381d..6fa5276 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -1096,7 +1096,8 @@ link_elf_lookup_symbol(linker_file_t lf, const char *name, c_linker_sym_t *sym) for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) { strp = ef->ddbstrtab + symp->st_name; - if (symp->st_shndx != SHN_UNDEF && strcmp(name, strp) == 0) { + if (symp->st_shndx != SHN_UNDEF && strcmp(name, strp) == 0 && + ELF_ST_BIND(symp->st_info) != STB_LOCAL) { *sym = (c_linker_sym_t) symp; return 0; }