-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 360156 b: refs/heads/master c: fa1c3ff h: refs/heads/master v: v3
- Loading branch information
Vineet Gupta
committed
Feb 15, 2013
1 parent
4e4c72d
commit f3df385
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 4788a5942bc896803c87005be8c6dd14c373a2d3 | ||
refs/heads/master: fa1c3ff935179453801d763940c38c3ac2d581eb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
*/ | ||
|
||
#include <linux/module.h> | ||
#include <linux/moduleloader.h> | ||
#include <linux/kernel.h> | ||
#include <linux/elf.h> | ||
#include <linux/vmalloc.h> | ||
#include <linux/slab.h> | ||
#include <linux/fs.h> | ||
#include <linux/string.h> | ||
|
||
static inline void arc_write_me(unsigned short *addr, unsigned long value) | ||
{ | ||
*addr = (value & 0xffff0000) >> 16; | ||
*(addr + 1) = (value & 0xffff); | ||
} | ||
|
||
int apply_relocate_add(Elf32_Shdr *sechdrs, | ||
const char *strtab, | ||
unsigned int symindex, /* sec index for sym tbl */ | ||
unsigned int relsec, /* sec index for relo sec */ | ||
struct module *module) | ||
{ | ||
int i, n; | ||
Elf32_Rela *rel_entry = (void *)sechdrs[relsec].sh_addr; | ||
Elf32_Sym *sym_entry, *sym_sec; | ||
Elf32_Addr relocation; | ||
Elf32_Addr location; | ||
Elf32_Addr sec_to_patch; | ||
int relo_type; | ||
|
||
sec_to_patch = sechdrs[sechdrs[relsec].sh_info].sh_addr; | ||
sym_sec = (Elf32_Sym *) sechdrs[symindex].sh_addr; | ||
n = sechdrs[relsec].sh_size / sizeof(*rel_entry); | ||
|
||
pr_debug("\n========== Module Sym reloc ===========================\n"); | ||
pr_debug("Section to fixup %x\n", sec_to_patch); | ||
pr_debug("=========================================================\n"); | ||
pr_debug("rela->r_off | rela->addend | sym->st_value | ADDR | VALUE\n"); | ||
pr_debug("=========================================================\n"); | ||
|
||
/* Loop thru entries in relocation section */ | ||
for (i = 0; i < n; i++) { | ||
|
||
/* This is where to make the change */ | ||
location = sec_to_patch + rel_entry[i].r_offset; | ||
|
||
/* This is the symbol it is referring to. Note that all | ||
undefined symbols have been resolved. */ | ||
sym_entry = sym_sec + ELF32_R_SYM(rel_entry[i].r_info); | ||
|
||
relocation = sym_entry->st_value + rel_entry[i].r_addend; | ||
|
||
pr_debug("\t%x\t\t%x\t\t%x %x %x [%s]\n", | ||
rel_entry[i].r_offset, rel_entry[i].r_addend, | ||
sym_entry->st_value, location, relocation, | ||
strtab + sym_entry->st_name); | ||
|
||
/* This assumes modules are built with -mlong-calls | ||
* so any branches/jumps are absolute 32 bit jmps | ||
* global data access again is abs 32 bit. | ||
* Both of these are handled by same relocation type | ||
*/ | ||
relo_type = ELF32_R_TYPE(rel_entry[i].r_info); | ||
|
||
if (likely(R_ARC_32_ME == relo_type)) | ||
arc_write_me((unsigned short *)location, relocation); | ||
else if (R_ARC_32 == relo_type) | ||
*((Elf32_Addr *) location) = relocation; | ||
else | ||
goto relo_err; | ||
|
||
} | ||
return 0; | ||
|
||
relo_err: | ||
pr_err("%s: unknown relocation: %u\n", | ||
module->name, ELF32_R_TYPE(rel_entry[i].r_info)); | ||
return -ENOEXEC; | ||
|
||
} |