/*1* ----------------------------------------------------------------------------2* "THE BEER-WARE LICENSE" (Revision 42):3* <[email protected]> wrote this file. As long as you retain this notice you can do4* whatever you want with this stuff. If we meet some day, and you think this5* stuff is worth it, you can buy me a beer in return. M4xw6* ----------------------------------------------------------------------------7*/89#include "elfload.h"1011#if defined(__arm__)1213// Taken from http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf14#define R_ARM_NONE 015#define R_ARM_ABS32 216#define R_ARM_JUMP_SLOT 2217#define R_ARM_GLOB_DAT 2118#define R_ARM_RELATIVE 231920el_status el_applyrel(el_ctx *ctx, Elf_Rel *rel)21{22u32 sym = ELF_R_SYM(rel->r_info); // Symbol offset23u32 type = ELF_R_TYPE(rel->r_info); // Relocation Type24uptr *p = (uptr *)(rel->r_offset + ctx->base_load_paddr); // Target Addr2526#if 0 // For later symbol usage27Elf32_Sym *elfSym;28const char *symbolName;2930// We resolve relocs from the originating elf-image31elfSym = (Elf32_Sym *)(ctx->symtab.sh_offset + (char *)buffteg) + sym;32int strtab_offset = ctx->shstr.sh_offset;33char *strtab = (char *)buffteg + strtab_offset;34symbolName = strtab + elfSym->st_name;35//EL_DEBUG("Str: %s sz: %x val: %x\n", symbolName, elfSym->st_size, elfSym->st_value);36#endif3738switch (type)39{40case R_ARM_NONE:41EL_DEBUG("R_ARM_NONE\n");42break;43case R_ARM_JUMP_SLOT:44case R_ARM_ABS32:45case R_ARM_GLOB_DAT:46// Stubbed for later purpose47//*p += elfSym->st_value; // + vaddr from sec48//*p |= 0; // 1 if Thumb && STT_FUNC, ignored for now49break;50case R_ARM_RELATIVE: // Needed for PIE51if (sym)52{53return EL_BADREL;54}55*p += ctx->base_load_vaddr;56break;5758default:59return EL_BADREL;60}6162return EL_OK;63}6465#endif666768