ef_sparc64.c revision 153504
118099Spst/*- 251178Sache * Copyright (c) 2003 Jake Burkholder. 3104868Sru * All rights reserved. 418099Spst * 518099Spst * Redistribution and use in source and binary forms, with or without 6104868Sru * modification, are permitted provided that the following conditions 7151503Sru * are met: 8151503Sru * 1. Redistributions of source code must retain the above copyright 9151503Sru * notice, this list of conditions and the following disclaimer. 1018099Spst * 2. Redistributions in binary form must reproduce the above copyright 1118099Spst * notice, this list of conditions and the following disclaimer in the 1275590Sru * documentation and/or other materials provided with the distribution. 1375590Sru * 1475590Sru * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1575590Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1675590Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1775590Sru * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1875590Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1975590Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2075590Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2175590Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2275590Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2375590Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2475590Sru * SUCH DAMAGE. 2575590Sru * 26114410Sru * $FreeBSD: head/usr.sbin/kldxref/ef_sparc64.c 153504 2005-12-18 04:52:37Z marcel $ 2718099Spst */ 2818099Spst 2918099Spst#include <sys/types.h> 3069631Sru#include <machine/elf.h> 31104868Sru 32104868Sru#include <err.h> 33104868Sru#include <string.h> 34119887Sru 35119887Sru#include "ef.h" 36119887Sru 37119887Sru/* 38104868Sru * Apply relocations to the values we got from the file. `relbase' is the 39104868Sru * target relocation address of the section, and `dataoff' is the target 40104868Sru * relocation address of the data in `dest'. 4169631Sru */ 4218099Spstint 43104868Sruef_reloc(struct elf_file *ef, const void *reldata, int reltype, Elf_Off relbase, 44114410Sru Elf_Off dataoff, size_t len, void *dest) 4518099Spst{ 46114410Sru const Elf_Rela *a; 47119887Sru Elf_Size w; 48119887Sru 49104868Sru switch (reltype) { 50114410Sru case EF_RELOC_RELA: 51114410Sru a = reldata; 52114410Sru if (relbase + a->r_offset >= dataoff && relbase + a->r_offset < 5318099Spst dataoff + len) { 54 switch (ELF_R_TYPE(a->r_info)) { 55 case R_SPARC_RELATIVE: 56 w = a->r_addend + relbase; 57 memcpy((u_char *)dest + (relbase + a->r_offset - 58 dataoff), &w, sizeof(w)); 59 break; 60 default: 61 warnx("unhandled relocation type %u", 62 (unsigned int)ELF_R_TYPE(a->r_info)); 63 break; 64 } 65 } 66 break; 67 } 68 return (0); 69} 70