4 * Linux architectural port borrowing liberally from similar works of
5 * others. All original copyrights apply as per the original source
8 * Modifications for the OpenRISC architecture:
9 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 #include <linux/moduleloader.h>
18 #include <linux/elf.h>
20 int apply_relocate_add(Elf32_Shdr *sechdrs,
22 unsigned int symindex,
27 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
32 pr_debug("Applying relocate section %u to %u\n", relsec,
33 sechdrs[relsec].sh_info);
34 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
35 /* This is where to make the change */
36 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
39 /* This is the symbol it is referring to. Note that all
40 undefined symbols have been resolved. */
41 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
42 + ELF32_R_SYM(rel[i].r_info);
43 value = sym->st_value + rel[i].r_addend;
45 switch (ELF32_R_TYPE(rel[i].r_info)) {
50 *((uint16_t *)location + 1) = value;
53 *((uint16_t *)location + 1) = value >> 16;
56 value -= (uint32_t)location;
59 value |= *location & 0xfc000000;
63 pr_err("module %s: Unknown relocation: %u\n",
64 me->name, ELF32_R_TYPE(rel[i].r_info));