kld not work on Atheros

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

kld not work on Atheros

Mori Hiroki
hi

I build current today. I can't use kld on AR9341(Big Endian).

kldload: geom_md.ko: lost base for reltab
linker_load_file: /boot/kernel/geom_md.ko - unsupported file type

Regards

Hiroki Mori
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: kld not work on Atheros

Michael Zhilin
Hi Hiroki-san,

This topic discussed by adrian@ and jhb@ few days ago.
Please use pre-r328101 revisions for a while.

+ Adrian and John in loop

Thanks!

On Thu, Jan 25, 2018 at 12:53 PM, Mori Hiroki <[hidden email]> wrote:

> hi
>
> I build current today. I can't use kld on AR9341(Big Endian).
>
> kldload: geom_md.ko: lost base for reltab
> linker_load_file: /boot/kernel/geom_md.ko - unsupported file type
>
> Regards
>
> Hiroki Mori
> _______________________________________________
> [hidden email] mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-mips
> To unsubscribe, send any mail to "[hidden email]"
>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: kld not work on Atheros

Adrian Chadd-2
hi,

yes; i did this:

Index: sys/kern/link_elf_obj.c
===================================================================
--- sys/kern/link_elf_obj.c    (revision 328277)
+++ sys/kern/link_elf_obj.c    (working copy)
@@ -1093,7 +1093,8 @@
         base = findbase(ef, ef->reltab[i].sec);
         if (base == 0) {
             link_elf_error(ef->lf.filename, "lost base for reltab");
-            return (ENOEXEC);
+            //return (ENOEXEC);
+            continue;
         }
         for ( ; rel < rellim; rel++) {
             symidx = ELF_R_SYM(rel->r_info);
@@ -1461,7 +1462,8 @@
         base = findbase(ef, ef->reltab[i].sec);
         if (base == 0) {
             link_elf_error(ef->lf.filename, "lost base for reltab");
-            return (ENOEXEC);
+            //return (ENOEXEC);
+            continue;
         }
         for ( ; rel < rellim; rel++) {
             symidx = ELF_R_SYM(rel->r_info);
@@ -1487,7 +1489,8 @@
         base = findbase(ef, ef->relatab[i].sec);
         if (base == 0) {
             link_elf_error(ef->lf.filename, "lost base for reltab");
-            return (ENOEXEC);
+            //return (ENOEXEC);
+            continue;
         }
         for ( ; rela < relalim; rela++) {
             symidx = ELF_R_SYM(rela->r_info);


jhb - what should we do to fix this in the short term?


-a

On 25 January 2018 at 02:02, Michael Zhilin <[hidden email]> wrote:

> Hi Hiroki-san,
>
> This topic discussed by adrian@ and jhb@ few days ago.
> Please use pre-r328101 revisions for a while.
>
> + Adrian and John in loop
>
> Thanks!
>
> On Thu, Jan 25, 2018 at 12:53 PM, Mori Hiroki <[hidden email]> wrote:
>>
>> hi
>>
>> I build current today. I can't use kld on AR9341(Big Endian).
>>
>> kldload: geom_md.ko: lost base for reltab
>> linker_load_file: /boot/kernel/geom_md.ko - unsupported file type
>>
>> Regards
>>
>> Hiroki Mori
>> _______________________________________________
>> [hidden email] mailing list
>> https://lists.freebsd.org/mailman/listinfo/freebsd-mips
>> To unsubscribe, send any mail to "[hidden email]"
>
>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: kld not work on Atheros

Adrian Chadd-2
Hi,

Bump - do I just put in an #ifdef MIPS around this workaround for now,
or what's the cleaner solution? :)



-a


On 27 January 2018 at 22:47, Adrian Chadd <[hidden email]> wrote:

> hi,
>
> yes; i did this:
>
> Index: sys/kern/link_elf_obj.c
> ===================================================================
> --- sys/kern/link_elf_obj.c    (revision 328277)
> +++ sys/kern/link_elf_obj.c    (working copy)
> @@ -1093,7 +1093,8 @@
>          base = findbase(ef, ef->reltab[i].sec);
>          if (base == 0) {
>              link_elf_error(ef->lf.filename, "lost base for reltab");
> -            return (ENOEXEC);
> +            //return (ENOEXEC);
> +            continue;
>          }
>          for ( ; rel < rellim; rel++) {
>              symidx = ELF_R_SYM(rel->r_info);
> @@ -1461,7 +1462,8 @@
>          base = findbase(ef, ef->reltab[i].sec);
>          if (base == 0) {
>              link_elf_error(ef->lf.filename, "lost base for reltab");
> -            return (ENOEXEC);
> +            //return (ENOEXEC);
> +            continue;
>          }
>          for ( ; rel < rellim; rel++) {
>              symidx = ELF_R_SYM(rel->r_info);
> @@ -1487,7 +1489,8 @@
>          base = findbase(ef, ef->relatab[i].sec);
>          if (base == 0) {
>              link_elf_error(ef->lf.filename, "lost base for reltab");
> -            return (ENOEXEC);
> +            //return (ENOEXEC);
> +            continue;
>          }
>          for ( ; rela < relalim; rela++) {
>              symidx = ELF_R_SYM(rela->r_info);
>
>
> jhb - what should we do to fix this in the short term?
>
>
> -a
>
> On 25 January 2018 at 02:02, Michael Zhilin <[hidden email]> wrote:
>> Hi Hiroki-san,
>>
>> This topic discussed by adrian@ and jhb@ few days ago.
>> Please use pre-r328101 revisions for a while.
>>
>> + Adrian and John in loop
>>
>> Thanks!
>>
>> On Thu, Jan 25, 2018 at 12:53 PM, Mori Hiroki <[hidden email]> wrote:
>>>
>>> hi
>>>
>>> I build current today. I can't use kld on AR9341(Big Endian).
>>>
>>> kldload: geom_md.ko: lost base for reltab
>>> linker_load_file: /boot/kernel/geom_md.ko - unsupported file type
>>>
>>> Regards
>>>
>>> Hiroki Mori
>>> _______________________________________________
>>> [hidden email] mailing list
>>> https://lists.freebsd.org/mailman/listinfo/freebsd-mips
>>> To unsubscribe, send any mail to "[hidden email]"
>>
>>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: kld not work on Atheros

John Baldwin
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
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: kld not work on Atheros

Mori Hiroki
Hi

Sorry too late reply.

I try to head code now. Work fine. Thanks.

Hiroki Mori


----- Original Message -----

> From: John Baldwin <[hidden email]>
> To: Adrian Chadd <[hidden email]>
> Cc: Michael Zhilin <[hidden email]>; Mori Hiroki <[hidden email]>; "[hidden email]" <[hidden email]>
> 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
>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: kld not work on Atheros

Adrian Chadd-2
hi,

Mori - did you try John's patch and it worked ok?


-a


On 8 February 2018 at 02:58, Mori Hiroki <[hidden email]> wrote:

> Hi
>
> Sorry too late reply.
>
> I try to head code now. Work fine. Thanks.
>
> Hiroki Mori
>
>
> ----- Original Message -----
>> From: John Baldwin <[hidden email]>
>> To: Adrian Chadd <[hidden email]>
>> Cc: Michael Zhilin <[hidden email]>; Mori Hiroki <[hidden email]>; "[hidden email]" <[hidden email]>
>> 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
>>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: kld not work on Atheros

Mori Hiroki
Hi.

I find this commit and try to head code.

https://svnweb.freebsd.org/base?view=revision&revision=328911


head code is kld work fine now.

Hiroki Mori


----- Original Message -----

> From: Adrian Chadd <[hidden email]>
> To: Mori Hiroki <[hidden email]>
> Cc: John Baldwin <[hidden email]>; Michael Zhilin <[hidden email]>; "[hidden email]" <[hidden email]>
> Date: 2018/2/11, Sun 04:50
> Subject: Re: kld not work on Atheros
>
> hi,
>
> Mori - did you try John's patch and it worked ok?
>
>
> -a
>
>
> On 8 February 2018 at 02:58, Mori Hiroki <[hidden email]> wrote:
>>  Hi
>>
>>  Sorry too late reply.
>>
>>  I try to head code now. Work fine. Thanks.
>>
>>  Hiroki Mori
>>
>>
>>  ----- Original Message -----
>>>  From: John Baldwin <[hidden email]>
>>>  To: Adrian Chadd <[hidden email]>
>>>  Cc: Michael Zhilin <[hidden email]>; Mori Hiroki
> <[hidden email]>; "[hidden email]"
> <[hidden email]>
>>>  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
>>>
>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "[hidden email]"