summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Levon <john.levon@joyent.com>2019-05-03 06:15:08 -0700
committerJohn Levon <john.levon@joyent.com>2019-05-13 01:55:47 -0700
commit0250bb16937dff6249965f46ef0ff3927359e704 (patch)
treef0129f208c65d0bd73f02dc6f07f41b65519e4e1
parent9e0bf232630ca5ae16a56613041b276f8a1c9740 (diff)
downloadillumos-joyent-0250bb16937dff6249965f46ef0ff3927359e704.tar.gz
10925 remove 32-bit x86 krtld
Reviewed by: Andy Stormont <astormont@racktopsystems.com> Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: Peter Tribble <peter.tribble@gmail.com> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/uts/intel/Makefile.rules6
-rw-r--r--usr/src/uts/intel/ia32/krtld/doreloc.c22
-rw-r--r--usr/src/uts/intel/ia32/krtld/kobj_boot.c74
-rw-r--r--usr/src/uts/intel/ia32/krtld/kobj_convrelstr.c79
-rw-r--r--usr/src/uts/intel/ia32/krtld/kobj_crt.s82
-rw-r--r--usr/src/uts/intel/ia32/krtld/kobj_isa.c115
-rw-r--r--usr/src/uts/intel/ia32/krtld/kobj_reloc.c339
7 files changed, 13 insertions, 704 deletions
diff --git a/usr/src/uts/intel/Makefile.rules b/usr/src/uts/intel/Makefile.rules
index 5829d88c32..bcf29cb99a 100644
--- a/usr/src/uts/intel/Makefile.rules
+++ b/usr/src/uts/intel/Makefile.rules
@@ -21,7 +21,7 @@
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
-# Copyright 2019 Joyent, Inc. All rights reserved.
+# Copyright 2019 Joyent, Inc.
# Copyright 2017 Nexenta Systems, Inc.
#
@@ -279,9 +279,7 @@ $(OBJS_DIR)/%.o: $(UTSBASE)/intel/zfs/%.c
KRTLD_INC_PATH = -I$(UTSBASE)/common/krtld -I$(UTSBASE)/intel/sys
KRTLD_INC_PATH += -I$(UTSBASE)/intel/$(SUBARCH_DIR)/krtld
-KRTLD_CPPFLAGS_32 = -DELF_TARGET_386
-KRTLD_CPPFLAGS_64 = -DELF_TARGET_AMD64 -DMODDIR_SUFFIX=\"amd64\"
-KRTLD_CPPFLAGS = $(KRTLD_CPPFLAGS_$(CLASS)) -D_KRTLD
+KRTLD_CPPFLAGS = -D_KRTLD -DELF_TARGET_AMD64 -DMODDIR_SUFFIX=\"amd64\"
$(OBJS_DIR)/%.o: $(UTSBASE)/common/krtld/%.c
$(COMPILE.c) $(KRTLD_INC_PATH) $(KRTLD_CPPFLAGS) -o $@ $<
diff --git a/usr/src/uts/intel/ia32/krtld/doreloc.c b/usr/src/uts/intel/ia32/krtld/doreloc.c
index 34b7ad24db..9537cd3eac 100644
--- a/usr/src/uts/intel/ia32/krtld/doreloc.c
+++ b/usr/src/uts/intel/ia32/krtld/doreloc.c
@@ -23,10 +23,16 @@
* Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
*/
-#if defined(_KERNEL)
-#include <sys/types.h>
-#include "reloc.h"
-#else
+/*
+ * Copyright 2019 Joyent, Inc.
+ */
+
+/*
+ * While this is no longer relevant to the kernel, we keep it in its
+ * traditional location to match the other variants, used from the ld
+ * code.
+ */
+
#define ELF_TARGET_386
#if defined(DO_RELOC_LIBLD)
#undef DO_RELOC_LIBLD
@@ -39,7 +45,6 @@
#include "reloc.h"
#include "conv.h"
#include "msg.h"
-#endif
/*
* We need to build this code differently when it is used for
@@ -181,12 +186,7 @@ const Rel_entry reloc_table[R_386_NUM] = {
* been performed before calling this function except for the addition of
* the addresses in the instructions.
*/
-#if defined(_KERNEL)
-#define lml 0 /* Needed by arglist of REL_ERR_* macros */
-int
-do_reloc_krtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
- const char *file)
-#elif defined(DO_RELOC_LIBLD)
+#if defined(DO_RELOC_LIBLD)
/*ARGSUSED5*/
int
do_reloc_ld(Rel_desc *rdesc, uchar_t *off, Xword *value,
diff --git a/usr/src/uts/intel/ia32/krtld/kobj_boot.c b/usr/src/uts/intel/ia32/krtld/kobj_boot.c
deleted file mode 100644
index 83fceab7d0..0000000000
--- a/usr/src/uts/intel/ia32/krtld/kobj_boot.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * Bootstrap the linker/loader.
- */
-
-#include <sys/types.h>
-#include <sys/bootconf.h>
-#include <sys/link.h>
-#include <sys/auxv.h>
-#include <sys/kobj.h>
-#include <sys/bootsvcs.h>
-#include <vm/kboot_mmu.h>
-#include <sys/kobj_impl.h>
-
-/*
- * the kernel's entry point (from locore.s)
- */
-extern void _locore_start();
-
-/*
- * fakebop transfers control here.
- *
- * fakebop and dboot don't construct any boot vector or aux vector information.
- * We figure all this out for ourself instead.
- */
-/*ARGSUSED3*/
-void
-_kobj_boot(
- struct boot_syscalls *syscallp,
- void *dvec,
- struct bootops *bootops,
- Boot *ebp)
-{
- val_t bootaux[BA_NUM];
- int i;
-
- for (i = 0; i < BA_NUM; i++)
- bootaux[i].ba_val = NULL;
-
- bootaux[BA_ENTRY].ba_ptr = (void *)_locore_start;
- bootaux[BA_PAGESZ].ba_val = MMU_PAGESIZE;
- bootaux[BA_LPAGESZ].ba_val = kbm_nucleus_size;
-
- /*
- * Initialize krtld.
- */
- kobj_init(syscallp, dvec, bootops, bootaux);
-}
diff --git a/usr/src/uts/intel/ia32/krtld/kobj_convrelstr.c b/usr/src/uts/intel/ia32/krtld/kobj_convrelstr.c
deleted file mode 100644
index 5c52e12993..0000000000
--- a/usr/src/uts/intel/ia32/krtld/kobj_convrelstr.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-#include <sys/types.h>
-#include "reloc.h"
-
-static const char *rels[R_386_NUM] = {
- "R_386_NONE", "R_386_32",
- "R_386_PC32", "R_386_GOT32",
- "R_386_PLT32", "R_386_COPY",
- "R_386_GLOB_DAT", "R_386_JMP_SLOT",
- "R_386_RELATIVE", "R_386_GOTOFF",
- "R_386_GOTPC", "R_386_32PLT",
- "R_386_TLS_GD_PLT", "R_386_TLS_LDM_PLT",
- "R_386_TLS_TPOFF", "R_386_TLS_IE",
- "R_386_TLS_GOTIE", "R_386_TLS_LE",
- "R_386_TLS_GD", "R_386_TLS_LDM",
- "R_386_16", "R_386_PC16",
- "R_386_8", "R_386_PC8",
- "R_386_UNKNOWN24", "R_386_UNKNOWN25",
- "R_386_UNKNOWN26", "R_386_UNKNOWN27",
- "R_386_UNKNOWN28", "R_386_UNKNOWN29",
- "R_386_UNKNOWN30", "R_386_UNKNOWN31",
- "R_386_TLS_LDO_32", "R_386_UNKNOWN33",
- "R_386_UNKNOWN34", "R_386_TLS_DTPMOD32",
- "R_386_TLS_DTPOFF32", "R_386_UNKNOWN37",
- "R_386_SIZE32"
-};
-
-#if (R_386_NUM != (R_386_SIZE32 + 1))
-#error "R_386_NUM has grown"
-#endif
-
-/*
- * This is a 'stub' of the orignal version defined in liblddbg.so. This stub
- * returns the 'int string' of the relocation in question instead of converting
- * the relocation to it's full syntax.
- */
-const char *
-conv_reloc_386_type(Word type)
-{
- static char strbuf[32];
- int ndx = 31;
-
- if (type < R_386_NUM)
- return (rels[type]);
-
- strbuf[ndx--] = '\0';
- do {
- strbuf[ndx--] = '0' + (type % 10);
- type = type / 10;
- } while ((ndx >= (int)0) && (type > (Word)0));
-
- return (&strbuf[ndx + 1]);
-}
diff --git a/usr/src/uts/intel/ia32/krtld/kobj_crt.s b/usr/src/uts/intel/ia32/krtld/kobj_crt.s
deleted file mode 100644
index fee3a73953..0000000000
--- a/usr/src/uts/intel/ia32/krtld/kobj_crt.s
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * exit routine from linker/loader to kernel
- */
-
-#include <sys/asm_linkage.h>
-#include <sys/reboot.h>
-#include <sys/trap.h>
-
-/*
- * exitto is called from main() and does 1 things
- * It then jumps directly to the just-loaded standalone.
- * There is NO RETURN from exitto(). ????
- */
-
-#if defined(lint)
-
-/* ARGSUSED */
-void
-exitto(caddr_t entrypoint)
-{}
-
-#else /* lint */
-
- .data
-save_esp2:
- .long 0
-
- ENTRY(exitto)
- push %ebp / save stack
- mov %esp,%ebp
- pushal / protect secondary boot
-
- movl %esp, %eax
- movl %eax, save_esp2
-
- /holds address of array of pointers to functions
- movl $romp, %eax
- movl (%eax), %ecx
-
- /holds address of bootops structure
- movl $ops, %eax
- movl (%eax), %ebx
-
- movl 8(%ebp), %eax
- call *%eax
-
- movl save_esp2, %eax
- movl %eax, %esp
-
- popal
- pop %ebp / restore frame pointer
-
- ret
- SET_SIZE(exitto)
-#endif
diff --git a/usr/src/uts/intel/ia32/krtld/kobj_isa.c b/usr/src/uts/intel/ia32/krtld/kobj_isa.c
deleted file mode 100644
index b6a198b0a8..0000000000
--- a/usr/src/uts/intel/ia32/krtld/kobj_isa.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 1994-2002 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * Miscellaneous ISA-specific code.
- */
-#include <sys/types.h>
-#include <sys/elf.h>
-#include <sys/kobj.h>
-#include <sys/kobj_impl.h>
-
-/*
- * Check that an ELF header corresponds to this machine's
- * instruction set architecture. Used by kobj_load_module()
- * to not get confused by a misplaced driver or kernel module
- * built for a different ISA.
- */
-int
-elf_mach_ok(Elf32_Ehdr *h)
-{
- return ((h->e_ident[EI_DATA] == ELFDATA2LSB) &&
- (h->e_machine == EM_386));
-}
-
-/*
- * return non-zero for a bad address
- */
-int
-kobj_addrcheck(void *xmp, caddr_t adr)
-{
- struct module *mp;
-
- mp = (struct module *)xmp;
-
- if ((adr >= mp->text && adr < mp->text + mp->text_size) ||
- (adr >= mp->data && adr < mp->data + mp->data_size))
- return (0); /* ok */
- if (mp->bss && adr >= (caddr_t)mp->bss &&
- adr < (caddr_t)mp->bss + mp->bss_size)
- return (0);
- return (1);
-}
-
-
-/*
- * Flush instruction cache after updating text
- * This is a nop for this machine arch.
- */
-/*ARGSUSED*/
-void
-kobj_sync_instruction_memory(caddr_t addr, size_t len)
-{}
-
-/*
- * Calculate memory image required for relocable object.
- */
-/* ARGSUSED3 */
-int
-get_progbits_size(struct module *mp, struct proginfo *tp, struct proginfo *dp,
- struct proginfo *sdp)
-{
- struct proginfo *pp;
- uint_t shn;
- Shdr *shp;
-
- /*
- * loop through sections to find out how much space we need
- * for text, data, (also bss that is already assigned)
- */
- for (shn = 1; shn < mp->hdr.e_shnum; shn++) {
- shp = (Shdr *)(mp->shdrs + shn * mp->hdr.e_shentsize);
- if (!(shp->sh_flags & SHF_ALLOC))
- continue;
- if (shp->sh_addr != 0) {
- _kobj_printf(ops,
- "%s non-zero sect addr in input file\n",
- mp->filename);
- return (-1);
- }
- pp = (shp->sh_flags & SHF_WRITE)? dp : tp;
-
- if (shp->sh_addralign > pp->align)
- pp->align = shp->sh_addralign;
- pp->size = ALIGN(pp->size, shp->sh_addralign);
- pp->size += ALIGN(shp->sh_size, 8);
- }
- tp->size = ALIGN(tp->size, 8);
- dp->size = ALIGN(dp->size, 8);
- return (0);
-}
diff --git a/usr/src/uts/intel/ia32/krtld/kobj_reloc.c b/usr/src/uts/intel/ia32/krtld/kobj_reloc.c
deleted file mode 100644
index befd15853a..0000000000
--- a/usr/src/uts/intel/ia32/krtld/kobj_reloc.c
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * x86 relocation code.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/sysmacros.h>
-#include <sys/systm.h>
-#include <sys/user.h>
-#include <sys/bootconf.h>
-#include <sys/modctl.h>
-#include <sys/elf.h>
-#include <sys/kobj.h>
-#include <sys/kobj_impl.h>
-#include <sys/tnf.h>
-#include <sys/tnf_probe.h>
-
-#include "reloc.h"
-
-
-/*
- * Probe Discovery
- */
-
-#define PROBE_MARKER_SYMBOL "__tnf_probe_version_1"
-#define TAG_MARKER_SYMBOL "__tnf_tag_version_1"
-
-extern int tnf_splice_probes(int, tnf_probe_control_t *, tnf_tag_data_t *);
-
-/*
- * The kernel run-time linker calls this to try to resolve a reference
- * it can't otherwise resolve. We see if it's marking a probe control
- * block; if so, we do the resolution and return 0. If not, we return
- * 1 to show that we can't resolve it, either.
- */
-static int
-tnf_reloc_resolve(char *symname,
- Addr *value_p,
- long offset,
- tnf_probe_control_t **probelist,
- tnf_tag_data_t **taglist)
-{
- if (strcmp(symname, PROBE_MARKER_SYMBOL) == 0) {
- ((tnf_probe_control_t *)offset)->next = *probelist;
- *probelist = (tnf_probe_control_t *)offset;
- return (0);
- }
- if (strcmp(symname, TAG_MARKER_SYMBOL) == 0) {
- *value_p = (Addr)*taglist;
- *taglist = (tnf_tag_data_t *)offset;
- return (0);
- }
- return (1);
-}
-
-#define SDT_NOP 0x90
-#define SDT_NOPS 5
-
-static int
-sdt_reloc_resolve(struct module *mp, char *symname, uint8_t *instr)
-{
- sdt_probedesc_t *sdp;
- int i;
-
- /*
- * The "statically defined tracing" (SDT) provider for DTrace uses
- * a mechanism similar to TNF, but somewhat simpler. (Surprise,
- * surprise.) The SDT mechanism works by replacing calls to the
- * undefined routine __dtrace_probe_[name] with nop instructions.
- * The relocations are logged, and SDT itself will later patch the
- * running binary appropriately.
- */
- if (strncmp(symname, sdt_prefix, strlen(sdt_prefix)) != 0)
- return (1);
-
- symname += strlen(sdt_prefix);
-
- sdp = kobj_alloc(sizeof (sdt_probedesc_t), KM_WAIT);
- sdp->sdpd_name = kobj_alloc(strlen(symname) + 1, KM_WAIT);
- bcopy(symname, sdp->sdpd_name, strlen(symname) + 1);
-
- sdp->sdpd_offset = (uintptr_t)instr;
- sdp->sdpd_next = mp->sdt_probes;
- mp->sdt_probes = sdp;
-
- for (i = 0; i < SDT_NOPS; i++)
- instr[i - 1] = SDT_NOP;
-
- return (0);
-}
-
-int
-/* ARGSUSED2 */
-do_relocate(struct module *mp, char *reltbl, Word relshtype, int nreloc,
- int relocsize, Addr baseaddr)
-{
- unsigned long stndx;
- unsigned long off; /* can't be register for tnf_reloc_resolve() */
- register unsigned long reladdr, rend;
- register unsigned int rtype;
- long value;
- Sym *symref;
- int err = 0;
- tnf_probe_control_t *probelist = NULL;
- tnf_tag_data_t *taglist = NULL;
- int symnum;
-
- reladdr = (unsigned long)reltbl;
- rend = reladdr + nreloc * relocsize;
-
-#ifdef KOBJ_DEBUG
- if (kobj_debug & D_RELOCATIONS) {
- _kobj_printf(ops, "krtld:\ttype\t\t\toffset symbol\n");
- _kobj_printf(ops, "krtld:\t\t\t\t\t value\n");
- }
-#endif
-
- symnum = -1;
- /* loop through relocations */
- while (reladdr < rend) {
- symnum++;
- rtype = ELF32_R_TYPE(((Rel *)reladdr)->r_info);
- off = ((Rel *)reladdr)->r_offset;
- stndx = ELF32_R_SYM(((Rel *)reladdr)->r_info);
- if (stndx >= mp->nsyms) {
- _kobj_printf(ops, "do_relocate: bad strndx %d\n",
- symnum);
- return (-1);
- }
- if ((rtype > R_386_NUM) || IS_TLS_INS(rtype)) {
- _kobj_printf(ops, "krtld: invalid relocation type %d",
- rtype);
- _kobj_printf(ops, " at 0x%llx:", off);
- _kobj_printf(ops, " file=%s\n", mp->filename);
- err = 1;
- continue;
- }
-
-
- reladdr += relocsize;
-
-
- if (rtype == R_386_NONE)
- continue;
-
-#ifdef KOBJ_DEBUG
- if (kobj_debug & D_RELOCATIONS) {
- Sym * symp;
- symp = (Sym *)
- (mp->symtbl+(stndx * mp->symhdr->sh_entsize));
- _kobj_printf(ops, "krtld:\t%s",
- conv_reloc_386_type(rtype));
- _kobj_printf(ops, "\t0x%8x", off);
- _kobj_printf(ops, " %s\n",
- (const char *)mp->strings + symp->st_name);
- }
-#endif
-
- if (!(mp->flags & KOBJ_EXEC))
- off += baseaddr;
-
- /*
- * if R_386_RELATIVE, simply add base addr
- * to reloc location
- */
-
- if (rtype == R_386_RELATIVE) {
- value = baseaddr;
- } else {
- /*
- * get symbol table entry - if symbol is local
- * value is base address of this object
- */
- symref = (Sym *)
- (mp->symtbl+(stndx * mp->symhdr->sh_entsize));
-
- if (ELF32_ST_BIND(symref->st_info) == STB_LOCAL) {
- /* *** this is different for .o and .so */
- value = symref->st_value;
- } else {
- /*
- * It's global. Allow weak references. If
- * the symbol is undefined, give TNF (the
- * kernel probes facility) a chance to see
- * if it's a probe site, and fix it up if so.
- */
- if (symref->st_shndx == SHN_UNDEF &&
- sdt_reloc_resolve(mp, mp->strings +
- symref->st_name, (uint8_t *)off) == 0)
- continue;
-
- if (symref->st_shndx == SHN_UNDEF &&
- tnf_reloc_resolve(mp->strings +
- symref->st_name, &symref->st_value,
- off, &probelist, &taglist) != 0) {
- if (ELF32_ST_BIND(symref->st_info)
- != STB_WEAK) {
- _kobj_printf(ops,
- "not found: %s\n",
- mp->strings +
- symref->st_name);
- err = 1;
- }
- continue;
- } else { /* symbol found - relocate */
- /*
- * calculate location of definition
- * - symbol value plus base address of
- * containing shared object
- */
- value = symref->st_value;
-
- } /* end else symbol found */
- } /* end global or weak */
- } /* end not R_386_RELATIVE */
-
- /*
- * calculate final value -
- * if PC-relative, subtract ref addr
- */
- if (IS_PC_RELATIVE(rtype))
- value -= off;
-
-#ifdef KOBJ_DEBUG
- if (kobj_debug & D_RELOCATIONS) {
- _kobj_printf(ops, "krtld:\t\t\t\t0x%8x", off);
- _kobj_printf(ops, " 0x%8x\n", value);
- }
-#endif
-
- if (do_reloc_krtld(rtype, (unsigned char *)off, (Word *)&value,
- (const char *)mp->strings + symref->st_name,
- mp->filename) == 0)
- err = 1;
-
- } /* end of while loop */
- if (err)
- return (-1);
-
- if (tnf_splice_probes(mp->flags & KOBJ_PRIM, probelist, taglist))
- mp->flags |= KOBJ_TNF_PROBE;
-
- return (0);
-}
-
-int
-do_relocations(struct module *mp)
-{
- uint_t shn;
- Shdr *shp, *rshp;
- uint_t nreloc;
-
- /* do the relocations */
- for (shn = 1; shn < mp->hdr.e_shnum; shn++) {
- rshp = (Shdr *)
- (mp->shdrs + shn * mp->hdr.e_shentsize);
- if (rshp->sh_type == SHT_RELA) {
- _kobj_printf(ops, "%s can't process type SHT_RELA\n",
- mp->filename);
- return (-1);
- }
- if (rshp->sh_type != SHT_REL)
- continue;
- if (rshp->sh_link != mp->symtbl_section) {
- _kobj_printf(ops, "%s reloc for non-default symtab\n",
- mp->filename);
- return (-1);
- }
- if (rshp->sh_info >= mp->hdr.e_shnum) {
- _kobj_printf(ops, "do_relocations: %s sh_info ",
- mp->filename);
- _kobj_printf(ops, "out of range %d\n", shn);
- goto bad;
- }
- nreloc = rshp->sh_size / rshp->sh_entsize;
-
- /* get the section header that this reloc table refers to */
- shp = (Shdr *)
- (mp->shdrs + rshp->sh_info * mp->hdr.e_shentsize);
-
- /*
- * Do not relocate any section that isn't loaded into memory.
- * Most commonly this will skip over the .rela.stab* sections
- */
- if (!(shp->sh_flags & SHF_ALLOC))
- continue;
-#ifdef KOBJ_DEBUG
- if (kobj_debug & D_RELOCATIONS) {
- _kobj_printf(ops, "krtld: relocating: file=%s ",
- mp->filename);
- _kobj_printf(ops, "section=%d\n", shn);
- }
-#endif
-
- if (do_relocate(mp, (char *)rshp->sh_addr, rshp->sh_type,
- nreloc, rshp->sh_entsize, shp->sh_addr) < 0) {
- _kobj_printf(ops,
- "do_relocations: %s do_relocate failed\n",
- mp->filename);
- goto bad;
- }
- kobj_free((void *)rshp->sh_addr, rshp->sh_size);
- rshp->sh_addr = 0;
- }
- mp->flags |= KOBJ_RELOCATED;
- return (0);
-bad:
- kobj_free((void *)rshp->sh_addr, rshp->sh_size);
- rshp->sh_addr = 0;
- return (-1);
-}