elf_machdep.c revision 298352
180708Sjake/*- 280708Sjake * Copyright (c) 2001 Jake Burkholder. 385586Sjake * Copyright (c) 2000 Eduardo Horvath. 485586Sjake * Copyright (c) 1999 The NetBSD Foundation, Inc. 580708Sjake * All rights reserved. 680708Sjake * 785586Sjake * This code is derived from software contributed to The NetBSD Foundation 885586Sjake * by Paul Kranenburg. 985586Sjake * 1080708Sjake * Redistribution and use in source and binary forms, with or without 1180708Sjake * modification, are permitted provided that the following conditions 1280708Sjake * are met: 1380708Sjake * 1. Redistributions of source code must retain the above copyright 1480708Sjake * notice, this list of conditions and the following disclaimer. 1580708Sjake * 2. Redistributions in binary form must reproduce the above copyright 1680708Sjake * notice, this list of conditions and the following disclaimer in the 1780708Sjake * documentation and/or other materials provided with the distribution. 1880708Sjake * 1985586Sjake * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2085586Sjake * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2185586Sjake * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2285586Sjake * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2385586Sjake * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2485586Sjake * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2585586Sjake * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2685586Sjake * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2785586Sjake * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2885586Sjake * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2985586Sjake * POSSIBILITY OF SUCH DAMAGE. 3080708Sjake * 31219532Smarius * from: NetBSD: mdreloc.c,v 1.42 2008/04/28 20:23:04 martin Exp 3280708Sjake */ 3380708Sjake 34172708Smarius#include <sys/cdefs.h> 35172708Smarius__FBSDID("$FreeBSD: head/sys/sparc64/sparc64/elf_machdep.c 298352 2016-04-20 15:45:55Z pfg $"); 36172708Smarius 3780708Sjake#include <sys/param.h> 38100384Speter#include <sys/kernel.h> 3980708Sjake#include <sys/systm.h> 40102808Sjake#include <sys/exec.h> 41102808Sjake#include <sys/imgact.h> 4280708Sjake#include <sys/linker.h> 43208453Skib#include <sys/proc.h> 44100384Speter#include <sys/sysent.h> 45100384Speter#include <sys/imgact_elf.h> 46100384Speter#include <sys/syscall.h> 47100384Speter#include <sys/signalvar.h> 48100384Speter#include <sys/vnode.h> 49102808Sjake 50102808Sjake#include <vm/vm.h> 51102808Sjake#include <vm/vm_param.h> 52102808Sjake 5380708Sjake#include <machine/elf.h> 5480708Sjake 5585586Sjake#include "linker_if.h" 5685586Sjake 57172708Smariusstatic struct sysentvec elf64_freebsd_sysvec = { 58183322Skib .sv_size = SYS_MAXSYSCALL, 59183322Skib .sv_table = sysent, 60183322Skib .sv_mask = 0, 61183322Skib .sv_errsize = 0, 62183322Skib .sv_errtbl = NULL, 63183322Skib .sv_transtrap = NULL, 64183322Skib .sv_fixup = __elfN(freebsd_fixup), 65183322Skib .sv_sendsig = sendsig, 66183322Skib .sv_sigcode = NULL, 67183322Skib .sv_szsigcode = NULL, 68183322Skib .sv_name = "FreeBSD ELF64", 69183322Skib .sv_coredump = __elfN(coredump), 70183322Skib .sv_imgact_try = NULL, 71183322Skib .sv_minsigstksz = MINSIGSTKSZ, 72183322Skib .sv_pagesize = PAGE_SIZE, 73183322Skib .sv_minuser = VM_MIN_ADDRESS, 74183322Skib .sv_maxuser = VM_MAXUSER_ADDRESS, 75183322Skib .sv_usrstack = USRSTACK, 76183322Skib .sv_psstrings = PS_STRINGS, 77183322Skib .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE, 78183322Skib .sv_copyout_strings = exec_copyout_strings, 79183322Skib .sv_setregs = exec_setregs, 80183322Skib .sv_fixlimit = NULL, 81185169Skib .sv_maxssiz = NULL, 82208453Skib .sv_flags = SV_ABI_FREEBSD | SV_LP64, 83208453Skib .sv_set_syscall_retval = cpu_set_syscall_retval, 84208453Skib .sv_fetch_syscall_args = cpu_fetch_syscall_args, 85208453Skib .sv_syscallnames = syscallnames, 86219405Sdchagin .sv_schedtail = NULL, 87283382Sdchagin .sv_thread_detach = NULL, 88293613Sdchagin .sv_trap = NULL, 89100384Speter}; 90100384Speter 91100384Speterstatic Elf64_Brandinfo freebsd_brand_info = { 92183322Skib .brand = ELFOSABI_FREEBSD, 93183322Skib .machine = EM_SPARCV9, 94183322Skib .compat_3_brand = "FreeBSD", 95183322Skib .emul_path = NULL, 96183322Skib .interp_path = "/libexec/ld-elf.so.1", 97183322Skib .sysvec = &elf64_freebsd_sysvec, 98183322Skib .interp_newpath = NULL, 99189771Sdchagin .brand_note = &elf64_freebsd_brandnote, 100190708Sdchagin .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE 101183322Skib}; 102100384Speter 103197729SbzSYSINIT(elf64, SI_SUB_EXEC, SI_ORDER_FIRST, 104219533Smarius (sysinit_cfunc_t)elf64_insert_brand_entry, &freebsd_brand_info); 105100384Speter 106123742Speterstatic Elf64_Brandinfo freebsd_brand_oinfo = { 107183322Skib .brand = ELFOSABI_FREEBSD, 108183322Skib .machine = EM_SPARCV9, 109183322Skib .compat_3_brand = "FreeBSD", 110183322Skib .emul_path = NULL, 111183322Skib .interp_path = "/usr/libexec/ld-elf.so.1", 112183322Skib .sysvec = &elf64_freebsd_sysvec, 113183322Skib .interp_newpath = NULL, 114189771Sdchagin .brand_note = &elf64_freebsd_brandnote, 115190708Sdchagin .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE 116183322Skib}; 117123742Speter 118123742SpeterSYSINIT(oelf64, SI_SUB_EXEC, SI_ORDER_ANY, 119219533Smarius (sysinit_cfunc_t)elf64_insert_brand_entry, &freebsd_brand_oinfo); 120123742Speter 121133464Smarcelvoid 122133464Smarcelelf64_dump_thread(struct thread *td __unused, void *dst __unused, 123133464Smarcel size_t *off __unused) 124133464Smarcel{ 125213104Smarius 126133464Smarcel} 127133464Smarcel 12885586Sjake/* 12985586Sjake * The following table holds for each relocation type: 13085586Sjake * - the width in bits of the memory location the relocation 13185586Sjake * applies to (not currently used) 13285586Sjake * - the number of bits the relocation value must be shifted to the 13385586Sjake * right (i.e. discard least significant bits) to fit into 13485586Sjake * the appropriate field in the instruction word. 13585586Sjake * - flags indicating whether 13685586Sjake * * the relocation involves a symbol 13785586Sjake * * the relocation is relative to the current position 13885586Sjake * * the relocation is for a GOT entry 13985586Sjake * * the relocation is relative to the load address 14085586Sjake * 14185586Sjake */ 142219532Smarius#define _RF_S 0x80000000 /* Resolve symbol */ 143219532Smarius#define _RF_A 0x40000000 /* Use addend */ 144219532Smarius#define _RF_P 0x20000000 /* Location relative */ 145219532Smarius#define _RF_G 0x10000000 /* GOT offset */ 146219532Smarius#define _RF_B 0x08000000 /* Load address relative */ 147219532Smarius#define _RF_U 0x04000000 /* Unaligned */ 148212998Skib#define _RF_X 0x02000000 /* Bare symbols, needs proc */ 149219533Smarius#define _RF_D 0x01000000 /* Use dynamic TLS offset */ 150219533Smarius#define _RF_O 0x00800000 /* Use static TLS offset */ 151219533Smarius#define _RF_I 0x00400000 /* Use TLS object ID */ 152219532Smarius#define _RF_SZ(s) (((s) & 0xff) << 8) /* memory target size */ 153219532Smarius#define _RF_RS(s) ( (s) & 0xff) /* right shift */ 154172708Smariusstatic const int reloc_target_flags[] = { 15585586Sjake 0, /* NONE */ 156219532Smarius _RF_S|_RF_A| _RF_SZ(8) | _RF_RS(0), /* 8 */ 157219532Smarius _RF_S|_RF_A| _RF_SZ(16) | _RF_RS(0), /* 16 */ 158219532Smarius _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* 32 */ 15985586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(8) | _RF_RS(0), /* DISP_8 */ 16085586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(16) | _RF_RS(0), /* DISP_16 */ 16185586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* DISP_32 */ 16285586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP_30 */ 16385586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP_22 */ 164212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(10), /* HI22 */ 165212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* 22 */ 166212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* 13 */ 167212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* LO10 */ 16885586Sjake _RF_G| _RF_SZ(32) | _RF_RS(0), /* GOT10 */ 16985586Sjake _RF_G| _RF_SZ(32) | _RF_RS(0), /* GOT13 */ 17085586Sjake _RF_G| _RF_SZ(32) | _RF_RS(10), /* GOT22 */ 17185586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PC10 */ 17285586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PC22 */ 17385586Sjake _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WPLT30 */ 17485586Sjake _RF_SZ(32) | _RF_RS(0), /* COPY */ 17585586Sjake _RF_S|_RF_A| _RF_SZ(64) | _RF_RS(0), /* GLOB_DAT */ 17685586Sjake _RF_SZ(32) | _RF_RS(0), /* JMP_SLOT */ 177104072Sjake _RF_A| _RF_B| _RF_SZ(64) | _RF_RS(0), /* RELATIVE */ 178104072Sjake _RF_S|_RF_A| _RF_U| _RF_SZ(32) | _RF_RS(0), /* UA_32 */ 17985586Sjake 18085586Sjake _RF_A| _RF_SZ(32) | _RF_RS(0), /* PLT32 */ 18185586Sjake _RF_A| _RF_SZ(32) | _RF_RS(10), /* HIPLT22 */ 18285586Sjake _RF_A| _RF_SZ(32) | _RF_RS(0), /* LOPLT10 */ 18385586Sjake _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PCPLT32 */ 18485586Sjake _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PCPLT22 */ 18585586Sjake _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(0), /* PCPLT10 */ 186212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* 10 */ 187212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* 11 */ 188212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(64) | _RF_RS(0), /* 64 */ 18985586Sjake _RF_S|_RF_A|/*extra*/ _RF_SZ(32) | _RF_RS(0), /* OLO10 */ 190212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(42), /* HH22 */ 191212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(32), /* HM10 */ 192212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(10), /* LM22 */ 19385586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(42), /* PC_HH22 */ 19485586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(32), /* PC_HM10 */ 19585586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(10), /* PC_LM22 */ 19685586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP16 */ 19785586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* WDISP19 */ 19885586Sjake _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* GLOB_JMP */ 199212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* 7 */ 200212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* 5 */ 201212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* 6 */ 20285586Sjake _RF_S|_RF_A|_RF_P| _RF_SZ(64) | _RF_RS(0), /* DISP64 */ 20385586Sjake _RF_A| _RF_SZ(64) | _RF_RS(0), /* PLT64 */ 204212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(10), /* HIX22 */ 205212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* LOX10 */ 206212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(22), /* H44 */ 207212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(12), /* M44 */ 208212998Skib _RF_S|_RF_A|_RF_X| _RF_SZ(32) | _RF_RS(0), /* L44 */ 20985586Sjake _RF_S|_RF_A| _RF_SZ(64) | _RF_RS(0), /* REGISTER */ 21085586Sjake _RF_S|_RF_A| _RF_U| _RF_SZ(64) | _RF_RS(0), /* UA64 */ 21185586Sjake _RF_S|_RF_A| _RF_U| _RF_SZ(16) | _RF_RS(0), /* UA16 */ 212219533Smarius 213219533Smarius#if 0 214219533Smarius /* TLS */ 215219533Smarius _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* GD_HI22 */ 216219533Smarius _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* GD_LO10 */ 217219533Smarius 0, /* GD_ADD */ 218219533Smarius _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* GD_CALL */ 219219533Smarius _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* LDM_HI22 */ 220219533Smarius _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* LDM_LO10 */ 221219533Smarius 0, /* LDM_ADD */ 222219533Smarius _RF_A|_RF_P| _RF_SZ(32) | _RF_RS(2), /* LDM_CALL */ 223219533Smarius _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* LDO_HIX22 */ 224219533Smarius _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* LDO_LOX10 */ 225219533Smarius 0, /* LDO_ADD */ 226219533Smarius _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(10), /* IE_HI22 */ 227219533Smarius _RF_S|_RF_A| _RF_SZ(32) | _RF_RS(0), /* IE_LO10 */ 228219533Smarius 0, /* IE_LD */ 229219533Smarius 0, /* IE_LDX */ 230219533Smarius 0, /* IE_ADD */ 231219533Smarius _RF_S|_RF_A| _RF_O| _RF_SZ(32) | _RF_RS(10), /* LE_HIX22 */ 232219533Smarius _RF_S|_RF_A| _RF_O| _RF_SZ(32) | _RF_RS(0), /* LE_LOX10 */ 233219533Smarius _RF_S| _RF_I| _RF_SZ(32) | _RF_RS(0), /* DTPMOD32 */ 234219533Smarius _RF_S| _RF_I| _RF_SZ(64) | _RF_RS(0), /* DTPMOD64 */ 235219533Smarius _RF_S|_RF_A| _RF_D| _RF_SZ(32) | _RF_RS(0), /* DTPOFF32 */ 236219533Smarius _RF_S|_RF_A| _RF_D| _RF_SZ(64) | _RF_RS(0), /* DTPOFF64 */ 237219533Smarius _RF_S|_RF_A| _RF_O| _RF_SZ(32) | _RF_RS(0), /* TPOFF32 */ 238219533Smarius _RF_S|_RF_A| _RF_O| _RF_SZ(64) | _RF_RS(0) /* TPOFF64 */ 239219533Smarius#endif 24085586Sjake}; 24185586Sjake 242104072Sjake#if 0 243213104Smariusstatic const char *const reloc_names[] = { 244219532Smarius "NONE", "8", "16", "32", "DISP_8", "DISP_16", "DISP_32", "WDISP_30", 245219532Smarius "WDISP_22", "HI22", "22", "13", "LO10", "GOT10", "GOT13", "GOT22", 246219532Smarius "PC10", "PC22", "WPLT30", "COPY", "GLOB_DAT", "JMP_SLOT", "RELATIVE", 247219532Smarius "UA_32", "PLT32", "HIPLT22", "LOPLT10", "LOPLT10", "PCPLT22", 248219532Smarius "PCPLT32", "10", "11", "64", "OLO10", "HH22", "HM10", "LM22", 249219532Smarius "PC_HH22", "PC_HM10", "PC_LM22", "WDISP16", "WDISP19", "GLOB_JMP", 250219532Smarius "7", "5", "6", "DISP64", "PLT64", "HIX22", "LOX10", "H44", "M44", 251219533Smarius "L44", "REGISTER", "UA64", "UA16", "GD_HI22", "GD_LO10", "GD_ADD", 252219533Smarius "GD_CALL", "LDM_HI22", "LDMO10", "LDM_ADD", "LDM_CALL", "LDO_HIX22", 253219533Smarius "LDO_LOX10", "LDO_ADD", "IE_HI22", "IE_LO10", "IE_LD", "IE_LDX", 254219533Smarius "IE_ADD", "LE_HIX22", "LE_LOX10", "DTPMOD32", "DTPMOD64", "DTPOFF32", 255219533Smarius "DTPOFF64", "TPOFF32", "TPOFF64" 256104072Sjake}; 257104072Sjake#endif 258104072Sjake 259219532Smarius#define RELOC_RESOLVE_SYMBOL(t) ((reloc_target_flags[t] & _RF_S) != 0) 260219532Smarius#define RELOC_PC_RELATIVE(t) ((reloc_target_flags[t] & _RF_P) != 0) 261219532Smarius#define RELOC_BASE_RELATIVE(t) ((reloc_target_flags[t] & _RF_B) != 0) 262219532Smarius#define RELOC_UNALIGNED(t) ((reloc_target_flags[t] & _RF_U) != 0) 263219532Smarius#define RELOC_USE_ADDEND(t) ((reloc_target_flags[t] & _RF_A) != 0) 264212998Skib#define RELOC_BARE_SYMBOL(t) ((reloc_target_flags[t] & _RF_X) != 0) 265219533Smarius#define RELOC_USE_TLS_DOFF(t) ((reloc_target_flags[t] & _RF_D) != 0) 266219533Smarius#define RELOC_USE_TLS_OFF(t) ((reloc_target_flags[t] & _RF_O) != 0) 267219533Smarius#define RELOC_USE_TLS_ID(t) ((reloc_target_flags[t] & _RF_I) != 0) 268219532Smarius#define RELOC_TARGET_SIZE(t) ((reloc_target_flags[t] >> 8) & 0xff) 269219532Smarius#define RELOC_VALUE_RIGHTSHIFT(t) (reloc_target_flags[t] & 0xff) 27085586Sjake 271172708Smariusstatic const long reloc_target_bitmask[] = { 272219532Smarius#define _BM(x) (~(-(1ULL << (x)))) 27385586Sjake 0, /* NONE */ 274219532Smarius _BM(8), _BM(16), _BM(32), /* 8, 16, 32 */ 27585586Sjake _BM(8), _BM(16), _BM(32), /* DISP8, DISP16, DISP32 */ 27685586Sjake _BM(30), _BM(22), /* WDISP30, WDISP22 */ 277219532Smarius _BM(22), _BM(22), /* HI22, 22 */ 278219532Smarius _BM(13), _BM(10), /* 13, LO10 */ 27985586Sjake _BM(10), _BM(13), _BM(22), /* GOT10, GOT13, GOT22 */ 280219339Smarius _BM(10), _BM(22), /* PC10, PC22 */ 281219339Smarius _BM(30), 0, /* WPLT30, COPY */ 282219339Smarius _BM(32), _BM(32), _BM(32), /* GLOB_DAT, JMP_SLOT, RELATIVE */ 283219339Smarius _BM(32), _BM(32), /* UA32, PLT32 */ 284219339Smarius _BM(22), _BM(10), /* HIPLT22, LOPLT10 */ 285219532Smarius _BM(32), _BM(22), _BM(10), /* PCPLT32, PCPLT22, PCPLT10 */ 286219339Smarius _BM(10), _BM(11), -1, /* 10, 11, 64 */ 287219339Smarius _BM(13), _BM(22), /* OLO10, HH22 */ 288219339Smarius _BM(10), _BM(22), /* HM10, LM22 */ 289219339Smarius _BM(22), _BM(10), _BM(22), /* PC_HH22, PC_HM10, PC_LM22 */ 290219339Smarius _BM(16), _BM(19), /* WDISP16, WDISP19 */ 29185586Sjake -1, /* GLOB_JMP */ 292219532Smarius _BM(7), _BM(5), _BM(6), /* 7, 5, 6 */ 29385586Sjake -1, -1, /* DISP64, PLT64 */ 29485586Sjake _BM(22), _BM(13), /* HIX22, LOX10 */ 29585586Sjake _BM(22), _BM(10), _BM(13), /* H44, M44, L44 */ 29685586Sjake -1, -1, _BM(16), /* REGISTER, UA64, UA16 */ 297219533Smarius#if 0 298219533Smarius _BM(22), _BM(10), 0, _BM(30), /* GD_HI22, GD_LO10, GD_ADD, GD_CALL */ 299219533Smarius _BM(22), _BM(10), 0, /* LDM_HI22, LDMO10, LDM_ADD */ 300219533Smarius _BM(30), /* LDM_CALL */ 301219533Smarius _BM(22), _BM(10), 0, /* LDO_HIX22, LDO_LOX10, LDO_ADD */ 302219533Smarius _BM(22), _BM(10), 0, 0, /* IE_HI22, IE_LO10, IE_LD, IE_LDX */ 303219533Smarius 0, /* IE_ADD */ 304219533Smarius _BM(22), _BM(13), /* LE_HIX22, LE_LOX10 */ 305219533Smarius _BM(32), -1, /* DTPMOD32, DTPMOD64 */ 306219533Smarius _BM(32), -1, /* DTPOFF32, DTPOFF64 */ 307219533Smarius _BM(32), -1 /* TPOFF32, TPOFF64 */ 308219533Smarius#endif 30985586Sjake#undef _BM 31085586Sjake}; 311219532Smarius#define RELOC_VALUE_BITMASK(t) (reloc_target_bitmask[t]) 31285586Sjake 313109605Sjakeint 314129282Speterelf_reloc_local(linker_file_t lf, Elf_Addr relocbase, const void *data, 315213104Smarius int type, elf_lookup_fn lookup __unused) 316109605Sjake{ 317109605Sjake const Elf_Rela *rela; 318109605Sjake Elf_Addr *where; 319109605Sjake 320109605Sjake if (type != ELF_RELOC_RELA) 321109605Sjake return (-1); 322109605Sjake 323109605Sjake rela = (const Elf_Rela *)data; 324172708Smarius if (ELF64_R_TYPE_ID(rela->r_info) != R_SPARC_RELATIVE) 325109605Sjake return (-1); 326109605Sjake 327213104Smarius where = (Elf_Addr *)(relocbase + rela->r_offset); 328213104Smarius *where = elf_relocaddr(lf, rela->r_addend + relocbase); 329109605Sjake 330109605Sjake return (0); 331109605Sjake} 332109605Sjake 33385586Sjake/* Process one elf relocation with addend. */ 33480708Sjakeint 335129282Speterelf_reloc(linker_file_t lf, Elf_Addr relocbase, const void *data, int type, 336129282Speter elf_lookup_fn lookup) 33780708Sjake{ 33885586Sjake const Elf_Rela *rela; 339153504Smarcel Elf_Word *where32; 34085586Sjake Elf_Addr *where; 341153504Smarcel Elf_Size rtype, symidx; 34285586Sjake Elf_Addr value; 34385586Sjake Elf_Addr mask; 34498635Smux Elf_Addr addr; 345288000Skib int error; 34685586Sjake 34785586Sjake if (type != ELF_RELOC_RELA) 34885586Sjake return (-1); 34985586Sjake 35085586Sjake rela = (const Elf_Rela *)data; 35185586Sjake where = (Elf_Addr *)(relocbase + rela->r_offset); 352153504Smarcel where32 = (Elf_Word *)where; 353172708Smarius rtype = ELF64_R_TYPE_ID(rela->r_info); 35495410Smarcel symidx = ELF_R_SYM(rela->r_info); 35585586Sjake 356109605Sjake if (rtype == R_SPARC_NONE || rtype == R_SPARC_RELATIVE) 35785586Sjake return (0); 35885586Sjake 35985586Sjake if (rtype == R_SPARC_JMP_SLOT || rtype == R_SPARC_COPY || 360298352Spfg rtype >= nitems(reloc_target_bitmask)) { 361219533Smarius printf("kldload: unexpected relocation type %ld\n", rtype); 36285586Sjake return (-1); 363219533Smarius } 36485586Sjake 365219533Smarius if (RELOC_UNALIGNED(rtype)) { 366219533Smarius printf("kldload: unaligned relocation type %ld\n", rtype); 36785586Sjake return (-1); 368219533Smarius } 36985586Sjake 37085586Sjake value = rela->r_addend; 37185586Sjake 37285586Sjake if (RELOC_RESOLVE_SYMBOL(rtype)) { 373288000Skib error = lookup(lf, symidx, 1, &addr); 374288000Skib if (error != 0) 375107517Stmm return (-1); 376219531Smarius value += addr; 377212998Skib if (RELOC_BARE_SYMBOL(rtype)) 378212998Skib value = elf_relocaddr(lf, value); 37985586Sjake } 38085586Sjake 381172708Smarius if (rtype == R_SPARC_OLO10) 382172708Smarius value = (value & 0x3ff) + ELF64_R_TYPE_DATA(rela->r_info); 383172708Smarius 384219340Smarius if (rtype == R_SPARC_HIX22) 385219340Smarius value ^= 0xffffffffffffffff; 386219340Smarius 38785586Sjake if (RELOC_PC_RELATIVE(rtype)) 38885586Sjake value -= (Elf_Addr)where; 38985586Sjake 390213104Smarius if (RELOC_BASE_RELATIVE(rtype)) 391194784Sjeff value = elf_relocaddr(lf, value + relocbase); 39285586Sjake 39385586Sjake mask = RELOC_VALUE_BITMASK(rtype); 39485586Sjake value >>= RELOC_VALUE_RIGHTSHIFT(rtype); 39585586Sjake value &= mask; 39685586Sjake 397219533Smarius if (rtype == R_SPARC_LOX10) 398219533Smarius value |= 0x1c00; 399219533Smarius 40085586Sjake if (RELOC_TARGET_SIZE(rtype) > 32) { 40185586Sjake *where &= ~mask; 40285586Sjake *where |= value; 40385586Sjake } else { 40485586Sjake *where32 &= ~mask; 40585586Sjake *where32 |= value; 40685586Sjake } 40785586Sjake 40880708Sjake return (0); 40980708Sjake} 410105469Smarcel 411105469Smarcelint 412105469Smarcelelf_cpu_load_file(linker_file_t lf __unused) 413105469Smarcel{ 414105469Smarcel 415105469Smarcel return (0); 416105469Smarcel} 417105469Smarcel 418105469Smarcelint 419105469Smarcelelf_cpu_unload_file(linker_file_t lf __unused) 420105469Smarcel{ 421105469Smarcel 422105469Smarcel return (0); 423105469Smarcel} 424