1 // SPDX-License-Identifier: GPL-2.0-only 1 2 /* 3 * Kernel module loader for Hexagon 4 * 5 * Copyright (c) 2010-2011, The Linux Foundati 6 */ 7 8 #include <asm/module.h> 9 #include <linux/elf.h> 10 #include <linux/module.h> 11 #include <linux/moduleloader.h> 12 #include <linux/vmalloc.h> 13 14 #if 0 15 #define DEBUGP printk 16 #else 17 #define DEBUGP(fmt , ...) 18 #endif 19 20 /* 21 * module_frob_arch_sections - tweak got/plt s 22 * @hdr - pointer to elf header 23 * @sechdrs - pointer to elf load section head 24 * @secstrings - symbol names 25 * @mod - pointer to module 26 */ 27 int module_frob_arch_sections(Elf_Ehdr *hdr, E 28 char *secstrin 29 struct module 30 { 31 unsigned int i; 32 int found = 0; 33 34 /* Look for .plt and/or .got.plt and/o 35 for (i = 0; i < hdr->e_shnum; i++) { 36 DEBUGP("Section %d is %s\n", i 37 secstrings + sechdrs[i] 38 if (strcmp(secstrings + sechdr 39 found = i+1; 40 if (strcmp(secstrings + sechdr 41 found = i+1; 42 if (strcmp(secstrings + sechdr 43 found = i+1; 44 } 45 46 /* At this time, we don't support modu 47 if (found) { 48 printk(KERN_WARNING 49 "Module '%s' contains 50 mod->name); 51 /* return -ENOEXEC; */ 52 } 53 54 return 0; 55 } 56 57 /* 58 * apply_relocate_add - perform rela relocatio 59 * @sechdrs - pointer to section headers 60 * @strtab - some sort of start address? 61 * @symindex - symbol index offset or somethin 62 * @relsec - address to relocate to? 63 * @module - pointer to module 64 * 65 * Perform rela relocations. 66 */ 67 int apply_relocate_add(Elf_Shdr *sechdrs, cons 68 unsigned int symindex, 69 struct module *module) 70 { 71 unsigned int i; 72 Elf32_Sym *sym; 73 uint32_t *location; 74 uint32_t value; 75 unsigned int nrelocs = sechdrs[relsec] 76 Elf32_Rela *rela = (void *)sechdrs[rel 77 Elf32_Word sym_info = sechdrs[relsec]. 78 Elf32_Sym *sym_base = (Elf32_Sym *) se 79 void *loc_base = (void *) sechdrs[sym_ 80 81 DEBUGP("Applying relocations in sectio 82 relsec, sym_info, loc_base); 83 84 for (i = 0; i < nrelocs; i++) { 85 86 /* Symbol to relocate */ 87 sym = sym_base + ELF32_R_SYM(r 88 89 /* Where to make the change */ 90 location = loc_base + rela[i]. 91 92 /* `Everything is relative'. * 93 value = sym->st_value + rela[i 94 95 DEBUGP("%d: value=%08x loc=%p 96 i, value, location, ELF 97 sym->st_name ? 98 &strtab[sym->st_name] : 99 100 switch (ELF32_R_TYPE(rela[i].r 101 case R_HEXAGON_B22_PCREL: { 102 int dist = (int)(value 103 if ((dist < -0x0080000 104 (dist >= 0x0080000 105 printk(KERN_ER 106 "%s: %s 107 module- 108 "R_HEXA 109 dist, v 110 sym->st 111 &strtab 112 return -ENOEXE 113 } 114 DEBUGP("B22_PCREL cont 115 *location &= ~0x01ff3f 116 *location |= 0x00003ff 117 *location |= 0x01ff000 118 DEBUGP("Contents after 119 break; 120 } 121 case R_HEXAGON_HI16: 122 value = (value>>16) & 123 fallthrough; 124 case R_HEXAGON_LO16: 125 *location &= ~0x00c03f 126 *location |= value & 0 127 *location |= (value & 128 break; 129 case R_HEXAGON_32: 130 *location = value; 131 break; 132 case R_HEXAGON_32_PCREL: 133 *location = value - (u 134 break; 135 case R_HEXAGON_PLT_B22_PCREL: 136 case R_HEXAGON_GOTOFF_LO16: 137 case R_HEXAGON_GOTOFF_HI16: 138 printk(KERN_ERR "%s: G 139 module->name); 140 return -ENOEXEC; 141 default: 142 printk(KERN_ERR "%s: u 143 module->name, 144 ELF32_R_TYPE(re 145 return -ENOEXEC; 146 } 147 } 148 return 0; 149 } 150
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.