Date: Sat, 10 Feb 2018 11:50:32 -0800 From: Adrian Chadd <adrian@freebsd.org> To: Mori Hiroki <yamori813@yahoo.co.jp> Cc: John Baldwin <jhb@freebsd.org>, Michael Zhilin <mizhka@gmail.com>, "freebsd-mips@freebsd.org" <freebsd-mips@freebsd.org> Subject: Re: kld not work on Atheros Message-ID: <CAJ-Vmo=YAgr1zcHm4jVO7qjPpYM71W_xgk8gMArfW5NMCGciLQ@mail.gmail.com> In-Reply-To: <406460.12451.qm@web101716.mail.ssk.yahoo.co.jp> References: <87596.64393.qm@web101718.mail.ssk.yahoo.co.jp> <CAJ-Vmon1vRjh276Fp50GWT8BcTv31EnXD4twkVYTkSH_BFL1yQ@mail.gmail.com> <CAJ-Vmonzu1%2BrxUkW2bL-7nUPyYeY6aHjP1vYPT8gBN7iTmu3dQ@mail.gmail.com> <4510846.CbLV3ucMtE@ralph.baldwin.cx> <406460.12451.qm@web101716.mail.ssk.yahoo.co.jp>
next in thread | previous in thread | raw e-mail | index | archive | help
hi, Mori - did you try John's patch and it worked ok? -a On 8 February 2018 at 02:58, Mori Hiroki <yamori813@yahoo.co.jp> wrote: > Hi > > Sorry too late reply. > > I try to head code now. Work fine. Thanks. > > Hiroki Mori > > > ----- Original Message ----- >> From: John Baldwin <jhb@freebsd.org> >> To: Adrian Chadd <adrian@freebsd.org> >> Cc: Michael Zhilin <mizhka@gmail.com>; Mori Hiroki <yamori813@yahoo.co.jp>; "freebsd-mips@freebsd.org" <freebsd-mips@freebsd.org> >> Date: 2018/2/2, Fri 05:06 >> Subject: Re: kld not work on Atheros >> >> 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 >>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ-Vmo=YAgr1zcHm4jVO7qjPpYM71W_xgk8gMArfW5NMCGciLQ>