17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55aefb655Srie * Common Development and Distribution License (the "License"). 65aefb655Srie * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 215aefb655Srie 227c478bd9Sstevel@tonic-gate /* 23*f3324781Sab196087 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * x86 relocation code. 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/param.h> 357c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 367c478bd9Sstevel@tonic-gate #include <sys/systm.h> 377c478bd9Sstevel@tonic-gate #include <sys/user.h> 387c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 397c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 407c478bd9Sstevel@tonic-gate #include <sys/elf.h> 417c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 427c478bd9Sstevel@tonic-gate #include <sys/kobj_impl.h> 437c478bd9Sstevel@tonic-gate #include <sys/tnf.h> 447c478bd9Sstevel@tonic-gate #include <sys/tnf_probe.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #include "reloc.h" 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * Probe Discovery 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #define PROBE_MARKER_SYMBOL "__tnf_probe_version_1" 547c478bd9Sstevel@tonic-gate #define TAG_MARKER_SYMBOL "__tnf_tag_version_1" 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate extern int tnf_splice_probes(int, tnf_probe_control_t *, tnf_tag_data_t *); 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * The kernel run-time linker calls this to try to resolve a reference 607c478bd9Sstevel@tonic-gate * it can't otherwise resolve. We see if it's marking a probe control 617c478bd9Sstevel@tonic-gate * block; if so, we do the resolution and return 0. If not, we return 627c478bd9Sstevel@tonic-gate * 1 to show that we can't resolve it, either. 637c478bd9Sstevel@tonic-gate */ 647c478bd9Sstevel@tonic-gate static int 657c478bd9Sstevel@tonic-gate tnf_reloc_resolve(char *symname, Addr *value_p, 667c478bd9Sstevel@tonic-gate Elf64_Sxword *addend_p, 677c478bd9Sstevel@tonic-gate long offset, 687c478bd9Sstevel@tonic-gate tnf_probe_control_t **probelist, 697c478bd9Sstevel@tonic-gate tnf_tag_data_t **taglist) 707c478bd9Sstevel@tonic-gate { 717c478bd9Sstevel@tonic-gate if (strcmp(symname, PROBE_MARKER_SYMBOL) == 0) { 727c478bd9Sstevel@tonic-gate *addend_p = 0; 737c478bd9Sstevel@tonic-gate ((tnf_probe_control_t *)offset)->next = *probelist; 747c478bd9Sstevel@tonic-gate *probelist = (tnf_probe_control_t *)offset; 757c478bd9Sstevel@tonic-gate return (0); 767c478bd9Sstevel@tonic-gate } 777c478bd9Sstevel@tonic-gate if (strcmp(symname, TAG_MARKER_SYMBOL) == 0) { 787c478bd9Sstevel@tonic-gate *addend_p = 0; 797c478bd9Sstevel@tonic-gate *value_p = (Addr)*taglist; 807c478bd9Sstevel@tonic-gate *taglist = (tnf_tag_data_t *)offset; 817c478bd9Sstevel@tonic-gate return (0); 827c478bd9Sstevel@tonic-gate } 837c478bd9Sstevel@tonic-gate return (1); 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate #define SDT_NOP 0x90 877c478bd9Sstevel@tonic-gate #define SDT_NOPS 5 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate static int 907c478bd9Sstevel@tonic-gate sdt_reloc_resolve(struct module *mp, char *symname, uint8_t *instr) 917c478bd9Sstevel@tonic-gate { 927c478bd9Sstevel@tonic-gate sdt_probedesc_t *sdp; 937c478bd9Sstevel@tonic-gate int i; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * The "statically defined tracing" (SDT) provider for DTrace uses 977c478bd9Sstevel@tonic-gate * a mechanism similar to TNF, but somewhat simpler. (Surprise, 987c478bd9Sstevel@tonic-gate * surprise.) The SDT mechanism works by replacing calls to the 997c478bd9Sstevel@tonic-gate * undefined routine __dtrace_probe_[name] with nop instructions. 1007c478bd9Sstevel@tonic-gate * The relocations are logged, and SDT itself will later patch the 1017c478bd9Sstevel@tonic-gate * running binary appropriately. 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate if (strncmp(symname, sdt_prefix, strlen(sdt_prefix)) != 0) 1047c478bd9Sstevel@tonic-gate return (1); 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate symname += strlen(sdt_prefix); 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate sdp = kobj_alloc(sizeof (sdt_probedesc_t), KM_WAIT); 1097c478bd9Sstevel@tonic-gate sdp->sdpd_name = kobj_alloc(strlen(symname) + 1, KM_WAIT); 1107c478bd9Sstevel@tonic-gate bcopy(symname, sdp->sdpd_name, strlen(symname) + 1); 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate sdp->sdpd_offset = (uintptr_t)instr; 1137c478bd9Sstevel@tonic-gate sdp->sdpd_next = mp->sdt_probes; 1147c478bd9Sstevel@tonic-gate mp->sdt_probes = sdp; 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate for (i = 0; i < SDT_NOPS; i++) 1177c478bd9Sstevel@tonic-gate instr[i - 1] = SDT_NOP; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate return (0); 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate int 1237c478bd9Sstevel@tonic-gate /* ARGSUSED2 */ 1247c478bd9Sstevel@tonic-gate do_relocate(struct module *mp, char *reltbl, Word relshtype, int nreloc, 1257c478bd9Sstevel@tonic-gate int relocsize, Addr baseaddr) 1267c478bd9Sstevel@tonic-gate { 1277c478bd9Sstevel@tonic-gate unsigned long stndx; 1287c478bd9Sstevel@tonic-gate unsigned long off; /* can't be register for tnf_reloc_resolve() */ 1297c478bd9Sstevel@tonic-gate register unsigned long reladdr, rend; 1307c478bd9Sstevel@tonic-gate register unsigned int rtype; 1317c478bd9Sstevel@tonic-gate unsigned long value; 1327c478bd9Sstevel@tonic-gate Elf64_Sxword addend; 1337c478bd9Sstevel@tonic-gate Sym *symref; 1347c478bd9Sstevel@tonic-gate int err = 0; 1357c478bd9Sstevel@tonic-gate tnf_probe_control_t *probelist = NULL; 1367c478bd9Sstevel@tonic-gate tnf_tag_data_t *taglist = NULL; 1377c478bd9Sstevel@tonic-gate int symnum; 1387c478bd9Sstevel@tonic-gate reladdr = (unsigned long)reltbl; 1397c478bd9Sstevel@tonic-gate rend = reladdr + nreloc * relocsize; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate #ifdef KOBJ_DEBUG 1427c478bd9Sstevel@tonic-gate if (kobj_debug & D_RELOCATIONS) { 1437c478bd9Sstevel@tonic-gate _kobj_printf(ops, "krtld:\ttype\t\t\toffset\t addend" 1447c478bd9Sstevel@tonic-gate " symbol\n"); 1457c478bd9Sstevel@tonic-gate _kobj_printf(ops, "krtld:\t\t\t\t\t value\n"); 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate #endif 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate symnum = -1; 1507c478bd9Sstevel@tonic-gate /* loop through relocations */ 1517c478bd9Sstevel@tonic-gate while (reladdr < rend) { 1527c478bd9Sstevel@tonic-gate symnum++; 1537c478bd9Sstevel@tonic-gate rtype = ELF_R_TYPE(((Rela *)reladdr)->r_info); 1547c478bd9Sstevel@tonic-gate off = ((Rela *)reladdr)->r_offset; 1557c478bd9Sstevel@tonic-gate stndx = ELF_R_SYM(((Rela *)reladdr)->r_info); 1567c478bd9Sstevel@tonic-gate if (stndx >= mp->nsyms) { 1577c478bd9Sstevel@tonic-gate _kobj_printf(ops, "do_relocate: bad strndx %d\n", 1587c478bd9Sstevel@tonic-gate symnum); 1597c478bd9Sstevel@tonic-gate return (-1); 1607c478bd9Sstevel@tonic-gate } 161d326b23bSrie if ((rtype > R_AMD64_NUM) || IS_TLS_INS(rtype)) { 1627c478bd9Sstevel@tonic-gate _kobj_printf(ops, "krtld: invalid relocation type %d", 1637c478bd9Sstevel@tonic-gate rtype); 1647c478bd9Sstevel@tonic-gate _kobj_printf(ops, " at 0x%llx:", off); 1657c478bd9Sstevel@tonic-gate _kobj_printf(ops, " file=%s\n", mp->filename); 1667c478bd9Sstevel@tonic-gate err = 1; 1677c478bd9Sstevel@tonic-gate continue; 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate addend = (long)(((Rela *)reladdr)->r_addend); 1727c478bd9Sstevel@tonic-gate reladdr += relocsize; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate if (rtype == R_AMD64_NONE) 1767c478bd9Sstevel@tonic-gate continue; 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate #ifdef KOBJ_DEBUG 1797c478bd9Sstevel@tonic-gate if (kobj_debug & D_RELOCATIONS) { 1807c478bd9Sstevel@tonic-gate Sym * symp; 1817c478bd9Sstevel@tonic-gate symp = (Sym *) 1827c478bd9Sstevel@tonic-gate (mp->symtbl+(stndx * mp->symhdr->sh_entsize)); 1837c478bd9Sstevel@tonic-gate _kobj_printf(ops, "krtld:\t%s", 1845aefb655Srie conv_reloc_amd64_type(rtype)); 1857c478bd9Sstevel@tonic-gate _kobj_printf(ops, "\t0x%8llx", off); 1867c478bd9Sstevel@tonic-gate _kobj_printf(ops, " 0x%8llx", addend); 1877c478bd9Sstevel@tonic-gate _kobj_printf(ops, " %s\n", 1887c478bd9Sstevel@tonic-gate (const char *)mp->strings + symp->st_name); 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate #endif 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate if (!(mp->flags & KOBJ_EXEC)) 1937c478bd9Sstevel@tonic-gate off += baseaddr; 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* 1967c478bd9Sstevel@tonic-gate * if R_AMD64_RELATIVE, simply add base addr 1977c478bd9Sstevel@tonic-gate * to reloc location 1987c478bd9Sstevel@tonic-gate */ 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate if (rtype == R_AMD64_RELATIVE) { 2017c478bd9Sstevel@tonic-gate value = baseaddr; 2027c478bd9Sstevel@tonic-gate } else { 2037c478bd9Sstevel@tonic-gate /* 2047c478bd9Sstevel@tonic-gate * get symbol table entry - if symbol is local 2057c478bd9Sstevel@tonic-gate * value is base address of this object 2067c478bd9Sstevel@tonic-gate */ 2077c478bd9Sstevel@tonic-gate symref = (Sym *) 2087c478bd9Sstevel@tonic-gate (mp->symtbl+(stndx * mp->symhdr->sh_entsize)); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate if (ELF_ST_BIND(symref->st_info) == STB_LOCAL) { 2117c478bd9Sstevel@tonic-gate /* *** this is different for .o and .so */ 2127c478bd9Sstevel@tonic-gate value = symref->st_value; 2137c478bd9Sstevel@tonic-gate } else { 2147c478bd9Sstevel@tonic-gate /* 2157c478bd9Sstevel@tonic-gate * It's global. Allow weak references. If 2167c478bd9Sstevel@tonic-gate * the symbol is undefined, give TNF (the 2177c478bd9Sstevel@tonic-gate * kernel probes facility) a chance to see 2187c478bd9Sstevel@tonic-gate * if it's a probe site, and fix it up if so. 2197c478bd9Sstevel@tonic-gate */ 2207c478bd9Sstevel@tonic-gate if (symref->st_shndx == SHN_UNDEF && 2217c478bd9Sstevel@tonic-gate sdt_reloc_resolve(mp, mp->strings + 2227c478bd9Sstevel@tonic-gate symref->st_name, (uint8_t *)off) == 0) 2237c478bd9Sstevel@tonic-gate continue; 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate if (symref->st_shndx == SHN_UNDEF && 2267c478bd9Sstevel@tonic-gate tnf_reloc_resolve(mp->strings + 2277c478bd9Sstevel@tonic-gate symref->st_name, &symref->st_value, 228*f3324781Sab196087 &addend, off, &probelist, &taglist) != 0) { 2297c478bd9Sstevel@tonic-gate if (ELF_ST_BIND(symref->st_info) 2307c478bd9Sstevel@tonic-gate != STB_WEAK) { 2317c478bd9Sstevel@tonic-gate _kobj_printf(ops, 2327c478bd9Sstevel@tonic-gate "not found: %s\n", 2337c478bd9Sstevel@tonic-gate mp->strings + 2347c478bd9Sstevel@tonic-gate symref->st_name); 2357c478bd9Sstevel@tonic-gate err = 1; 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate continue; 2387c478bd9Sstevel@tonic-gate } else { /* symbol found - relocate */ 2397c478bd9Sstevel@tonic-gate /* 2407c478bd9Sstevel@tonic-gate * calculate location of definition 2417c478bd9Sstevel@tonic-gate * - symbol value plus base address of 2427c478bd9Sstevel@tonic-gate * containing shared object 2437c478bd9Sstevel@tonic-gate */ 2447c478bd9Sstevel@tonic-gate value = symref->st_value; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate } /* end else symbol found */ 2477c478bd9Sstevel@tonic-gate } /* end global or weak */ 2487c478bd9Sstevel@tonic-gate } /* end not R_AMD64_RELATIVE */ 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate value += addend; 2517c478bd9Sstevel@tonic-gate /* 2527c478bd9Sstevel@tonic-gate * calculate final value - 2537c478bd9Sstevel@tonic-gate * if PC-relative, subtract ref addr 2547c478bd9Sstevel@tonic-gate */ 2557c478bd9Sstevel@tonic-gate if (IS_PC_RELATIVE(rtype)) 2567c478bd9Sstevel@tonic-gate value -= off; 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate #ifdef KOBJ_DEBUG 2597c478bd9Sstevel@tonic-gate if (kobj_debug & D_RELOCATIONS) { 2607c478bd9Sstevel@tonic-gate _kobj_printf(ops, "krtld:\t\t\t\t0x%8llx", off); 2617c478bd9Sstevel@tonic-gate _kobj_printf(ops, " 0x%8llx\n", value); 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate #endif 2647c478bd9Sstevel@tonic-gate 265*f3324781Sab196087 if (do_reloc_krtld(rtype, (unsigned char *)off, &value, 2667c478bd9Sstevel@tonic-gate (const char *)mp->strings + symref->st_name, 267*f3324781Sab196087 mp->filename) == 0) 2687c478bd9Sstevel@tonic-gate err = 1; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate } /* end of while loop */ 2717c478bd9Sstevel@tonic-gate if (err) 2727c478bd9Sstevel@tonic-gate return (-1); 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate if (tnf_splice_probes(mp->flags & KOBJ_PRIM, probelist, taglist)) 2757c478bd9Sstevel@tonic-gate mp->flags |= KOBJ_TNF_PROBE; 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate return (0); 2787c478bd9Sstevel@tonic-gate } 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate int 2817c478bd9Sstevel@tonic-gate do_relocations(struct module *mp) 2827c478bd9Sstevel@tonic-gate { 2837c478bd9Sstevel@tonic-gate uint_t shn; 2847c478bd9Sstevel@tonic-gate Shdr *shp, *rshp; 2857c478bd9Sstevel@tonic-gate uint_t nreloc; 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate /* do the relocations */ 2887c478bd9Sstevel@tonic-gate for (shn = 1; shn < mp->hdr.e_shnum; shn++) { 2897c478bd9Sstevel@tonic-gate rshp = (Shdr *) 2907c478bd9Sstevel@tonic-gate (mp->shdrs + shn * mp->hdr.e_shentsize); 2917c478bd9Sstevel@tonic-gate if (rshp->sh_type == SHT_REL) { 2927c478bd9Sstevel@tonic-gate _kobj_printf(ops, "%s can't process type SHT_REL\n", 2937c478bd9Sstevel@tonic-gate mp->filename); 2947c478bd9Sstevel@tonic-gate return (-1); 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate if (rshp->sh_type != SHT_RELA) 2977c478bd9Sstevel@tonic-gate continue; 2987c478bd9Sstevel@tonic-gate if (rshp->sh_link != mp->symtbl_section) { 2997c478bd9Sstevel@tonic-gate _kobj_printf(ops, "%s reloc for non-default symtab\n", 3007c478bd9Sstevel@tonic-gate mp->filename); 3017c478bd9Sstevel@tonic-gate return (-1); 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate if (rshp->sh_info >= mp->hdr.e_shnum) { 3047c478bd9Sstevel@tonic-gate _kobj_printf(ops, "do_relocations: %s sh_info ", 3057c478bd9Sstevel@tonic-gate mp->filename); 3067c478bd9Sstevel@tonic-gate _kobj_printf(ops, "out of range %d\n", shn); 3077c478bd9Sstevel@tonic-gate goto bad; 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate nreloc = rshp->sh_size / rshp->sh_entsize; 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate /* get the section header that this reloc table refers to */ 3127c478bd9Sstevel@tonic-gate shp = (Shdr *) 3137c478bd9Sstevel@tonic-gate (mp->shdrs + rshp->sh_info * mp->hdr.e_shentsize); 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate /* 3167c478bd9Sstevel@tonic-gate * Do not relocate any section that isn't loaded into memory. 3177c478bd9Sstevel@tonic-gate * Most commonly this will skip over the .rela.stab* sections 3187c478bd9Sstevel@tonic-gate */ 3197c478bd9Sstevel@tonic-gate if (!(shp->sh_flags & SHF_ALLOC)) 3207c478bd9Sstevel@tonic-gate continue; 3217c478bd9Sstevel@tonic-gate #ifdef KOBJ_DEBUG 3227c478bd9Sstevel@tonic-gate if (kobj_debug & D_RELOCATIONS) { 3237c478bd9Sstevel@tonic-gate _kobj_printf(ops, "krtld: relocating: file=%s ", 3247c478bd9Sstevel@tonic-gate mp->filename); 3257c478bd9Sstevel@tonic-gate _kobj_printf(ops, "section=%d\n", shn); 3267c478bd9Sstevel@tonic-gate } 3277c478bd9Sstevel@tonic-gate #endif 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate if (do_relocate(mp, (char *)rshp->sh_addr, rshp->sh_type, 3307c478bd9Sstevel@tonic-gate nreloc, rshp->sh_entsize, shp->sh_addr) < 0) { 3317c478bd9Sstevel@tonic-gate _kobj_printf(ops, 3327c478bd9Sstevel@tonic-gate "do_relocations: %s do_relocate failed\n", 3337c478bd9Sstevel@tonic-gate mp->filename); 3347c478bd9Sstevel@tonic-gate goto bad; 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate kobj_free((void *)rshp->sh_addr, rshp->sh_size); 3377c478bd9Sstevel@tonic-gate rshp->sh_addr = 0; 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate mp->flags |= KOBJ_RELOCATED; 3407c478bd9Sstevel@tonic-gate return (0); 3417c478bd9Sstevel@tonic-gate bad: 3427c478bd9Sstevel@tonic-gate kobj_free((void *)rshp->sh_addr, rshp->sh_size); 3437c478bd9Sstevel@tonic-gate rshp->sh_addr = 0; 3447c478bd9Sstevel@tonic-gate return (-1); 3457c478bd9Sstevel@tonic-gate } 346