Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Work around abs rela relocations issue (for now):



details:   https://anonhg.NetBSD.org/src/rev/70fca080ecbd
branches:  trunk
changeset: 379581:70fca080ecbd
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jun 09 15:15:35 2021 +0000

description:
Work around abs rela relocations issue (for now):

$ readelf -r compat_linux
...
Relocation section '.rela.data' at offset 0x37270 contains 537 entries:
Offset          Info           Type           Sym. Value    Sym. Name + Addend
...
000000000040  000000000001 R_X86_64_64                          0
000000000048  000000000001 R_X86_64_64                          0
...

$ objdump -r compat_linux
...
RELOCATION RECORDS FOR [.data]:
OFFSET           TYPE              VALUE
...
0000000000000040 R_X86_64_64       *ABS*
0000000000000048 R_X86_64_64       *ABS*
...

Since those have symidx == 0, and the 0 symbol table entry is special,
treat them as SHN_ABS.

Change ENOENT -> ENOEXEC to avoid confusion (like other linking errors),
and add some debugging when that happens.

diffstat:

 sys/kern/subr_kobj.c |  20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diffs (55 lines):

diff -r 1f1edc6d63d4 -r 70fca080ecbd sys/kern/subr_kobj.c
--- a/sys/kern/subr_kobj.c      Wed Jun 09 14:49:13 2021 +0000
+++ b/sys/kern/subr_kobj.c      Wed Jun 09 15:15:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_kobj.c,v 1.67 2020/06/27 17:27:59 christos Exp $  */
+/*     $NetBSD: subr_kobj.c,v 1.68 2021/06/09 15:15:35 christos Exp $  */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.67 2020/06/27 17:27:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.68 2021/06/09 15:15:35 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
@@ -881,7 +881,7 @@ kobj_sym_lookup(kobj_t ko, uintptr_t sym
 
        sym = ko->ko_symtab + symidx;
 
-       if (symidx == SHN_ABS) {
+       if (symidx == SHN_ABS || symidx == 0) {
                *val = (uintptr_t)sym->st_value;
                return 0;
        } else if (symidx >= ko->ko_symcnt) {
@@ -1074,7 +1074,12 @@ kobj_relocate(kobj_t ko, bool local)
                        }
                        error = kobj_reloc(ko, base, rel, false, local);
                        if (error != 0) {
-                               return ENOENT;
+                               kobj_error(ko, "unresolved rel relocation "
+                                   "@%#jx type=%d symidx=%d",
+                                   (intmax_t)rel->r_offset,
+                                   (int)ELF_R_TYPE(rel->r_info),
+                                   (int)ELF_R_SYM(rel->r_info));
+                               return ENOEXEC;
                        }
                }
        }
@@ -1105,7 +1110,12 @@ kobj_relocate(kobj_t ko, bool local)
                        }
                        error = kobj_reloc(ko, base, rela, true, local);
                        if (error != 0) {
-                               return ENOENT;
+                               kobj_error(ko, "unresolved rela relocation "
+                                   "@%#jx type=%d symidx=%d",
+                                   (intmax_t)rela->r_offset,
+                                   (int)ELF_R_TYPE(rela->r_info),
+                                   (int)ELF_R_SYM(rela->r_info));
+                               return ENOEXEC;
                        }
                }
        }



Home | Main Index | Thread Index | Old Index