ef_sparc64.c revision 109607
1109607Sjake/*-
2109607Sjake * Copyright (c) 2003 Jake Burkholder.
3109607Sjake * All rights reserved.
4109607Sjake *
5109607Sjake * Redistribution and use in source and binary forms, with or without
6109607Sjake * modification, are permitted provided that the following conditions
7109607Sjake * are met:
8109607Sjake * 1. Redistributions of source code must retain the above copyright
9109607Sjake *    notice, this list of conditions and the following disclaimer.
10109607Sjake * 2. Redistributions in binary form must reproduce the above copyright
11109607Sjake *    notice, this list of conditions and the following disclaimer in the
12109607Sjake *    documentation and/or other materials provided with the distribution.
13109607Sjake *
14109607Sjake * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15109607Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16109607Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17109607Sjake * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18109607Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19109607Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20109607Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21109607Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22109607Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23109607Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24109607Sjake * SUCH DAMAGE.
25109607Sjake *
26109607Sjake * $FreeBSD: head/usr.sbin/kldxref/ef_sparc64.c 109607 2003-01-21 03:51:53Z jake $
27109607Sjake */
28109607Sjake
29109607Sjake#include <sys/types.h>
30109607Sjake#include <machine/elf.h>
31109607Sjake
32109607Sjake#include <err.h>
33109607Sjake#include <string.h>
34109607Sjake
35109607Sjake#include "ef.h"
36109607Sjake
37109607Sjake/*
38109607Sjake * Apply relocations to the values we got from the file.
39109607Sjake */
40109607Sjakeint
41109607Sjakeef_reloc(elf_file_t ef, Elf_Off offset, size_t len, void *dest)
42109607Sjake{
43109607Sjake	const Elf_Rela *a;
44109607Sjake	Elf_Word w;
45109607Sjake
46109607Sjake	for (a = ef->ef_rela; a < &ef->ef_rela[ef->ef_relasz]; a++) {
47109607Sjake		if (a->r_offset >= offset && a->r_offset < offset + len) {
48109607Sjake			switch (ELF_R_TYPE(a->r_info)) {
49109607Sjake			case R_SPARC_RELATIVE:
50109607Sjake				/* load address is 0 */
51109607Sjake				w = a->r_addend;
52109607Sjake				memcpy((u_char *)dest + (a->r_offset - offset),
53109607Sjake				    &w, sizeof(w));
54109607Sjake				break;
55109607Sjake			default:
56109607Sjake				warnx("unhandled relocation type %u",
57109607Sjake				    ELF_R_TYPE(a->r_info));
58109607Sjake				break;
59109607Sjake			}
60109607Sjake		}
61109607Sjake	}
62109607Sjake	return (0);
63109607Sjake}
64