Module Name:    src
Committed By:   christos
Date:           Wed Jun  9 15:15:35 UTC 2021

Modified Files:
        src/sys/kern: subr_kobj.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/kern/subr_kobj.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_kobj.c
diff -u src/sys/kern/subr_kobj.c:1.67 src/sys/kern/subr_kobj.c:1.68
--- src/sys/kern/subr_kobj.c:1.67	Sat Jun 27 13:27:59 2020
+++ src/sys/kern/subr_kobj.c	Wed Jun  9 11:15:35 2021
@@ -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;
 			}
 		}
 	}

Reply via email to