Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Handle absolute relocations coming from the kernel: pres...
details: https://anonhg.NetBSD.org/src/rev/37a13bdcdc49
branches: trunk
changeset: 357256:37a13bdcdc49
user: maxv <maxv%NetBSD.org@localhost>
date: Fri Nov 03 09:59:07 2017 +0000
description:
Handle absolute relocations coming from the kernel: preserve SHN_ABS in
the kernel and module symbols, and when relocating a symbol that has
SHN_ABS, take its value as-is and don't return an error if it equals zero.
Sent on tech-kern@.
diffstat:
sys/arch/alpha/alpha/kobj_machdep.c | 17 +++++-----
sys/arch/amd64/amd64/kobj_machdep.c | 21 ++++++------
sys/arch/arm/arm32/kobj_machdep.c | 29 +++++++++--------
sys/arch/hppa/hppa/kobj_machdep.c | 20 ++++++------
sys/arch/i386/i386/kobj_machdep.c | 17 +++++-----
sys/arch/m68k/m68k/kobj_machdep.c | 13 ++++---
sys/arch/powerpc/powerpc/kobj_machdep.c | 11 +++---
sys/arch/riscv/riscv/kobj_machdep.c | 10 +++--
sys/arch/sh3/sh3/kobj_machdep.c | 9 +++--
sys/arch/sparc/sparc/kobj_machdep.c | 7 ++-
sys/arch/sparc64/sparc64/kobj_machdep.c | 9 +++--
sys/ddb/db_sym.c | 14 ++++----
sys/kern/kern_ksyms.c | 19 ++++++++---
sys/kern/subr_kobj.c | 52 +++++++++++++++++++++-----------
sys/sys/kobj.h | 4 +-
sys/sys/ksyms.h | 5 +-
16 files changed, 146 insertions(+), 111 deletions(-)
diffs (truncated from 866 to 300 lines):
diff -r 4bdbed8292c8 -r 37a13bdcdc49 sys/arch/alpha/alpha/kobj_machdep.c
--- a/sys/arch/alpha/alpha/kobj_machdep.c Fri Nov 03 07:14:24 2017 +0000
+++ b/sys/arch/alpha/alpha/kobj_machdep.c Fri Nov 03 09:59:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kobj_machdep.c,v 1.2 2008/04/28 20:23:10 martin Exp $ */
+/* $NetBSD: kobj_machdep.c,v 1.3 2017/11/03 09:59:07 maxv Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.2 2008/04/28 20:23:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.3 2017/11/03 09:59:07 maxv Exp $");
#define ELFSIZE ARCH_ELFSIZE
@@ -72,6 +72,7 @@
uintptr_t rtype, symidx;
const Elf_Rel *rel;
const Elf_Rela *rela;
+ int error;
if (isrela) {
rela = (const Elf_Rela *)data;
@@ -92,8 +93,8 @@
break;
case R_ALPHA_REFQUAD:
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
return -1;
addr += addend;
if (*where != addr)
@@ -101,8 +102,8 @@
break;
case R_ALPHA_GLOB_DAT:
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
return -1;
addr += addend;
if (*where != addr)
@@ -111,8 +112,8 @@
case R_ALPHA_JMP_SLOT:
/* No point in lazy binding for kernel modules. */
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
return -1;
if (*where != addr)
*where = addr;
diff -r 4bdbed8292c8 -r 37a13bdcdc49 sys/arch/amd64/amd64/kobj_machdep.c
--- a/sys/arch/amd64/amd64/kobj_machdep.c Fri Nov 03 07:14:24 2017 +0000
+++ b/sys/arch/amd64/amd64/kobj_machdep.c Fri Nov 03 09:59:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kobj_machdep.c,v 1.5 2008/12/08 08:41:36 njoly Exp $ */
+/* $NetBSD: kobj_machdep.c,v 1.6 2017/11/03 09:59:08 maxv Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.5 2008/12/08 08:41:36 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.6 2017/11/03 09:59:08 maxv Exp $");
#define ELFSIZE ARCH_ELFSIZE
@@ -80,6 +80,7 @@
uintptr_t rtype, symidx;
const Elf_Rel *rel;
const Elf_Rela *rela;
+ int error;
if (isrela) {
rela = (const Elf_Rela *)data;
@@ -110,16 +111,16 @@
break;
case R_X86_64_64: /* S + A */
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
return -1;
val = addr + addend;
*where = val;
break;
case R_X86_64_PC32: /* S + A - P */
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
return -1;
where32 = (Elf32_Addr *)where;
val32 = (Elf32_Addr)(addr + addend - (Elf64_Addr)where);
@@ -128,8 +129,8 @@
case R_X86_64_32: /* S + A */
case R_X86_64_32S: /* S + A sign extend */
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
return -1;
val32 = (Elf32_Addr)(addr + addend);
where32 = (Elf32_Addr *)where;
@@ -138,8 +139,8 @@
case R_X86_64_GLOB_DAT: /* S */
case R_X86_64_JUMP_SLOT:/* XXX need addend + offset */
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
return -1;
*where = addr;
break;
diff -r 4bdbed8292c8 -r 37a13bdcdc49 sys/arch/arm/arm32/kobj_machdep.c
--- a/sys/arch/arm/arm32/kobj_machdep.c Fri Nov 03 07:14:24 2017 +0000
+++ b/sys/arch/arm/arm32/kobj_machdep.c Fri Nov 03 09:59:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kobj_machdep.c,v 1.11 2016/07/11 15:51:01 martin Exp $ */
+/* $NetBSD: kobj_machdep.c,v 1.12 2017/11/03 09:59:08 maxv Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.11 2016/07/11 15:51:01 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.12 2017/11/03 09:59:08 maxv Exp $");
#define ELFSIZE ARCH_ELFSIZE
@@ -78,6 +78,7 @@
Elf_Word rtype, symidx;
const Elf_Rel *rel;
const Elf_Rela *rela;
+ int error;
if (isrela) {
rela = (const Elf_Rela *)data;
@@ -99,8 +100,8 @@
return 0;
case R_ARM_ABS32:
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
break;
*where = addr + addend;
return 0;
@@ -110,8 +111,8 @@
break;
case R_ARM_JUMP_SLOT:
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
break;
*where = addr;
return 0;
@@ -126,8 +127,8 @@
case R_ARM_MOVT_ABS:
if ((*where & 0x0fb00000) != 0x03000000)
break;
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
break;
if (rtype == R_ARM_MOVT_ABS)
addr >>= 16;
@@ -150,8 +151,8 @@
addend <<= 2;
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
break;
addend += (uintptr_t)addr - (uintptr_t)where;
@@ -171,8 +172,8 @@
case R_ARM_REL32: /* ((S + A) | T) - P */
/* T = 0 for now */
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
break;
addend += (uintptr_t)addr - (uintptr_t)where;
@@ -184,8 +185,8 @@
if (addend & 0x40000000)
addend |= 0xc0000000;
/* T = 0 for now */
- addr = kobj_sym_lookup(ko, symidx);
- if (addr == 0)
+ error = kobj_sym_lookup(ko, symidx, &addr);
+ if (error)
break;
addend += (uintptr_t)addr - (uintptr_t)where;
diff -r 4bdbed8292c8 -r 37a13bdcdc49 sys/arch/hppa/hppa/kobj_machdep.c
--- a/sys/arch/hppa/hppa/kobj_machdep.c Fri Nov 03 07:14:24 2017 +0000
+++ b/sys/arch/hppa/hppa/kobj_machdep.c Fri Nov 03 09:59:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kobj_machdep.c,v 1.14 2014/02/01 08:05:51 skrll Exp $ */
+/* $NetBSD: kobj_machdep.c,v 1.15 2017/11/03 09:59:08 maxv Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.14 2014/02/01 08:05:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.15 2017/11/03 09:59:08 maxv Exp $");
#define ELFSIZE ARCH_ELFSIZE
@@ -155,52 +155,52 @@
case R_TYPE(DIR32):
/* symbol + addend */
- addr = kobj_sym_lookup(ko, symidx);
+ kobj_sym_lookup(ko, symidx, &addr);
value += addr;
break;
case R_TYPE(DIR21L):
/* LR(symbol, addend) */
- addr = kobj_sym_lookup(ko, symidx);
+ kobj_sym_lookup(ko, symidx, &addr);
value = LR(addr, value);
break;
case R_TYPE(DIR17R):
case R_TYPE(DIR14R):
/* RR(symbol, addend) */
- addr = kobj_sym_lookup(ko, symidx);
+ kobj_sym_lookup(ko, symidx, &addr);
value = RR(addr, value);
break;
case R_TYPE(PCREL32):
case R_TYPE(PCREL17F):
/* symbol - PC - 8 + addend */
- addr = kobj_sym_lookup(ko, symidx);
+ kobj_sym_lookup(ko, symidx, &addr);
value += addr - (Elf_Word)where - 8;
break;
case R_TYPE(DPREL21L):
/* LR(symbol - GP, addend) */
- addr = kobj_sym_lookup(ko, symidx);
+ kobj_sym_lookup(ko, symidx, &addr);
value = LR(addr - GP, value);
break;
case R_TYPE(DPREL14R):
/* RR(symbol - GP, addend) */
- addr = kobj_sym_lookup(ko, symidx);
+ kobj_sym_lookup(ko, symidx, &addr);
value = RR(addr - GP, value);
break;
case R_TYPE(PLABEL32):
/* fptr(symbol) */
- addr = kobj_sym_lookup(ko, symidx);
+ kobj_sym_lookup(ko, symidx, &addr);
value = addr;
break;
case R_TYPE(SEGREL32):
/* symbol - SB + addend */
/* XXX SB */
- addr = kobj_sym_lookup(ko, symidx);
+ kobj_sym_lookup(ko, symidx, &addr);
value += addr;
break;
diff -r 4bdbed8292c8 -r 37a13bdcdc49 sys/arch/i386/i386/kobj_machdep.c
Home |
Main Index |
Thread Index |
Old Index