Commit b75dcd9c authored by Vineet Gupta's avatar Vineet Gupta

ARC: module: print pretty section names

Now that we have referece to section name string table in
apply_relocate_add(), use it to

 - print the name of section being relocated
 - print symbol with NULL name (since it refers to a section)

before

| Section to fixup 7000a060
| =========================================================
| rela->r_off | rela->addend | sym->st_value | ADDR | VALUE
| =========================================================
|	1c		0		7000e000  7000a07c 7000e000 []
|	40		0		7000a000  7000a0a0 7000a000 []

after

| Section to fixup .eh_frame @7000a060
| =========================================================
| r_off	r_add	st_value ADDRESS  VALUE
| =========================================================
|    1c	0	7000e000 7000a07c 7000e000 [.init.text]
|    40	0	7000a000 7000a0a0 7000a000 [.exit.text]
Signed-off-by: default avatarVineet Gupta <vgupta@synopsys.com>
parent d65283f7
...@@ -51,31 +51,33 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, ...@@ -51,31 +51,33 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
unsigned int relsec, /* sec index for relo sec */ unsigned int relsec, /* sec index for relo sec */
struct module *module) struct module *module)
{ {
int i, n; int i, n, relo_type;
Elf32_Rela *rel_entry = (void *)sechdrs[relsec].sh_addr; Elf32_Rela *rel_entry = (void *)sechdrs[relsec].sh_addr;
Elf32_Sym *sym_entry, *sym_sec; Elf32_Sym *sym_entry, *sym_sec;
Elf32_Addr relocation; Elf32_Addr relocation, location, tgt_addr;
Elf32_Addr location;
Elf32_Addr sec_to_patch;
int relo_type;
unsigned int tgtsec; unsigned int tgtsec;
/*
* @relsec has relocations e.g. .rela.init.text
* @tgtsec is section to patch e.g. .init.text
*/
tgtsec = sechdrs[relsec].sh_info; tgtsec = sechdrs[relsec].sh_info;
sec_to_patch = sechdrs[tgtsec].sh_addr; tgt_addr = sechdrs[tgtsec].sh_addr;
sym_sec = (Elf32_Sym *) sechdrs[symindex].sh_addr; sym_sec = (Elf32_Sym *) sechdrs[symindex].sh_addr;
n = sechdrs[relsec].sh_size / sizeof(*rel_entry); n = sechdrs[relsec].sh_size / sizeof(*rel_entry);
pr_debug("\n========== Module Sym reloc ===========================\n"); pr_debug("\nSection to fixup %s @%x\n",
pr_debug("Section to fixup %x\n", sec_to_patch); module->arch.secstr + sechdrs[tgtsec].sh_name, tgt_addr);
pr_debug("=========================================================\n"); pr_debug("=========================================================\n");
pr_debug("rela->r_off | rela->addend | sym->st_value | ADDR | VALUE\n"); pr_debug("r_off\tr_add\tst_value ADDRESS VALUE\n");
pr_debug("=========================================================\n"); pr_debug("=========================================================\n");
/* Loop thru entries in relocation section */ /* Loop thru entries in relocation section */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
const char *s;
/* This is where to make the change */ /* This is where to make the change */
location = sec_to_patch + rel_entry[i].r_offset; location = tgt_addr + rel_entry[i].r_offset;
/* This is the symbol it is referring to. Note that all /* This is the symbol it is referring to. Note that all
undefined symbols have been resolved. */ undefined symbols have been resolved. */
...@@ -83,10 +85,15 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, ...@@ -83,10 +85,15 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
relocation = sym_entry->st_value + rel_entry[i].r_addend; relocation = sym_entry->st_value + rel_entry[i].r_addend;
pr_debug("\t%x\t\t%x\t\t%x %x %x [%s]\n", if (sym_entry->st_name == 0 && ELF_ST_TYPE (sym_entry->st_info) == STT_SECTION) {
s = module->arch.secstr + sechdrs[sym_entry->st_shndx].sh_name;
} else {
s = strtab + sym_entry->st_name;
}
pr_debug(" %x\t%x\t%x %x %x [%s]\n",
rel_entry[i].r_offset, rel_entry[i].r_addend, rel_entry[i].r_offset, rel_entry[i].r_addend,
sym_entry->st_value, location, relocation, sym_entry->st_value, location, relocation, s);
strtab + sym_entry->st_name);
/* This assumes modules are built with -mlong-calls /* This assumes modules are built with -mlong-calls
* so any branches/jumps are absolute 32 bit jmps * so any branches/jumps are absolute 32 bit jmps
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment