From owner-freebsd-mips@freebsd.org Thu Feb 1 20:06:14 2018 Return-Path: Delivered-To: freebsd-mips@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D0F29EC308E for ; Thu, 1 Feb 2018 20:06:13 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from mail.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) (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 7074D83162; Thu, 1 Feb 2018 20:06:13 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id CAAED10A7DB; Thu, 1 Feb 2018 15:06:11 -0500 (EST) From: John Baldwin To: Adrian Chadd Cc: Michael Zhilin , Mori Hiroki , "freebsd-mips@freebsd.org" Subject: Re: kld not work on Atheros Date: Thu, 01 Feb 2018 12:06:08 -0800 Message-ID: <4510846.CbLV3ucMtE@ralph.baldwin.cx> User-Agent: KMail/4.14.10 (FreeBSD/11.1-STABLE; KDE/4.14.30; amd64; ; ) In-Reply-To: References: <87596.64393.qm@web101718.mail.ssk.yahoo.co.jp> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail.baldwin.cx); Thu, 01 Feb 2018 15:06:11 -0500 (EST) X-Virus-Scanned: clamav-milter 0.99.2 at mail.baldwin.cx X-Virus-Status: Clean X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Feb 2018 20:06:14 -0000 On Wednesday, January 31, 2018 02:12:42 PM Adrian Chadd wrote: > Hi, > > Bump - do I just put in an #ifdef MIPS around this workaround for now, > or what's the cleaner solution? :) Cleaner solution is to not load reltabs or relatabs for sections that don't have SHF_ALLOC set. That is, earlier in load_elf_obj.c (in loader) and in link_elf_obj.c when looping over SHT_RELTAB and SHT_RELTABA sections, ignore relocation tables whose associated section doesn't have SHF_ALLOC set. Try this (untested): diff --git a/stand/common/load_elf_obj.c b/stand/common/load_elf_obj.c index b58dde0dfbf8..4c893e17a5b1 100644 --- a/stand/common/load_elf_obj.c +++ b/stand/common/load_elf_obj.c @@ -282,6 +282,8 @@ __elfN(obj_loadimage)(struct preloaded_file *fp, elf_file_t ef, u_int64_t off) switch (shdr[i].sh_type) { case SHT_REL: case SHT_RELA: + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; lastaddr = roundup(lastaddr, shdr[i].sh_addralign); shdr[i].sh_addr = (Elf_Addr)lastaddr; lastaddr += shdr[i].sh_size; diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c index 448d5b9c08a5..0bcec40822e1 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -272,9 +272,17 @@ link_elf_link_preload(linker_class_t cls, const char *filename, symstrindex = shdr[i].sh_link; break; case SHT_REL: + /* + * Ignore relocation tables for sections not + * loaded by the loader. + */ + if (shdr[shdr[i].sh_info].sh_addr == 0) + break; ef->nreltab++; break; case SHT_RELA: + if (shdr[shdr[i].sh_info].sh_addr == 0) + break; ef->nrelatab++; break; } @@ -398,12 +406,16 @@ link_elf_link_preload(linker_class_t cls, const char *filename, pb++; break; case SHT_REL: + if (shdr[shdr[i].sh_info].sh_addr == 0) + break; ef->reltab[rl].rel = (Elf_Rel *)shdr[i].sh_addr; ef->reltab[rl].nrel = shdr[i].sh_size / sizeof(Elf_Rel); ef->reltab[rl].sec = shdr[i].sh_info; rl++; break; case SHT_RELA: + if (shdr[shdr[i].sh_info].sh_addr == 0) + break; ef->relatab[ra].rela = (Elf_Rela *)shdr[i].sh_addr; ef->relatab[ra].nrela = shdr[i].sh_size / sizeof(Elf_Rela); @@ -620,9 +632,17 @@ link_elf_load_file(linker_class_t cls, const char *filename, symstrindex = shdr[i].sh_link; break; case SHT_REL: + /* + * Ignore relocation tables for unallocated + * sections. + */ + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; ef->nreltab++; break; case SHT_RELA: + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; ef->nrelatab++; break; case SHT_STRTAB: @@ -880,6 +900,8 @@ link_elf_load_file(linker_class_t cls, const char *filename, pb++; break; case SHT_REL: + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; ef->reltab[rl].rel = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK); ef->reltab[rl].nrel = shdr[i].sh_size / sizeof(Elf_Rel); @@ -898,6 +920,8 @@ link_elf_load_file(linker_class_t cls, const char *filename, rl++; break; case SHT_RELA: + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; ef->relatab[ra].rela = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK); ef->relatab[ra].nrela = -- John Baldwin