Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/ianos/elfload/elfreloc_arm.c
1476 views
1
/*
2
* ----------------------------------------------------------------------------
3
* "THE BEER-WARE LICENSE" (Revision 42):
4
* <[email protected]> wrote this file. As long as you retain this notice you can do
5
* whatever you want with this stuff. If we meet some day, and you think this
6
* stuff is worth it, you can buy me a beer in return. M4xw
7
* ----------------------------------------------------------------------------
8
*/
9
10
#include "elfload.h"
11
12
#if defined(__arm__)
13
14
// Taken from http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf
15
#define R_ARM_NONE 0
16
#define R_ARM_ABS32 2
17
#define R_ARM_JUMP_SLOT 22
18
#define R_ARM_GLOB_DAT 21
19
#define R_ARM_RELATIVE 23
20
21
el_status el_applyrel(el_ctx *ctx, Elf_Rel *rel)
22
{
23
u32 sym = ELF_R_SYM(rel->r_info); // Symbol offset
24
u32 type = ELF_R_TYPE(rel->r_info); // Relocation Type
25
uptr *p = (uptr *)(rel->r_offset + ctx->base_load_paddr); // Target Addr
26
27
#if 0 // For later symbol usage
28
Elf32_Sym *elfSym;
29
const char *symbolName;
30
31
// We resolve relocs from the originating elf-image
32
elfSym = (Elf32_Sym *)(ctx->symtab.sh_offset + (char *)buffteg) + sym;
33
int strtab_offset = ctx->shstr.sh_offset;
34
char *strtab = (char *)buffteg + strtab_offset;
35
symbolName = strtab + elfSym->st_name;
36
//EL_DEBUG("Str: %s sz: %x val: %x\n", symbolName, elfSym->st_size, elfSym->st_value);
37
#endif
38
39
switch (type)
40
{
41
case R_ARM_NONE:
42
EL_DEBUG("R_ARM_NONE\n");
43
break;
44
case R_ARM_JUMP_SLOT:
45
case R_ARM_ABS32:
46
case R_ARM_GLOB_DAT:
47
// Stubbed for later purpose
48
//*p += elfSym->st_value; // + vaddr from sec
49
//*p |= 0; // 1 if Thumb && STT_FUNC, ignored for now
50
break;
51
case R_ARM_RELATIVE: // Needed for PIE
52
if (sym)
53
{
54
return EL_BADREL;
55
}
56
*p += ctx->base_load_vaddr;
57
break;
58
59
default:
60
return EL_BADREL;
61
}
62
63
return EL_OK;
64
}
65
66
#endif
67
68