Skip to content

Commit 8931360

Browse files
author
Russell King
committed
ARM: module: clean up handling of ELF unwind tables
There's no need to keep pointers to the ELF sections available while the module is loaded - we only need the section pointers while we're finding and registering the unwind tables, which can all be done during the finalize stage of loading. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent f6614b7 commit 8931360

2 files changed

Lines changed: 56 additions & 65 deletions

File tree

‎arch/arm/include/asm/module.h‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
struct unwind_table;
99

1010
#ifdef CONFIG_ARM_UNWIND
11-
struct arm_unwind_mapping {
12-
Elf_Shdr *unw_sec;
13-
Elf_Shdr *sec_text;
14-
struct unwind_table *unwind;
15-
};
1611
enum {
1712
ARM_SEC_INIT,
1813
ARM_SEC_DEVINIT,
@@ -21,13 +16,13 @@ enum {
2116
ARM_SEC_DEVEXIT,
2217
ARM_SEC_MAX,
2318
};
19+
#endif
20+
2421
struct mod_arch_specific {
25-
struct arm_unwind_mapping map[ARM_SEC_MAX];
26-
};
27-
#else
28-
struct mod_arch_specific {
29-
};
22+
#ifdef CONFIG_ARM_UNWIND
23+
struct unwind_table *unwind[ARM_SEC_MAX];
3024
#endif
25+
};
3126

3227
/*
3328
* Include the ARM architecture version.

‎arch/arm/kernel/module.c‎

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,6 @@ int module_frob_arch_sections(Elf_Ehdr *hdr,
6767
char *secstrings,
6868
struct module *mod)
6969
{
70-
#ifdef CONFIG_ARM_UNWIND
71-
Elf_Shdr *s, *sechdrs_end = sechdrs + hdr->e_shnum;
72-
struct arm_unwind_mapping *maps = mod->arch.map;
73-
74-
for (s = sechdrs; s < sechdrs_end; s++) {
75-
char const *secname = secstrings + s->sh_name;
76-
77-
if (strcmp(".ARM.exidx.init.text", secname) == 0)
78-
maps[ARM_SEC_INIT].unw_sec = s;
79-
else if (strcmp(".ARM.exidx.devinit.text", secname) == 0)
80-
maps[ARM_SEC_DEVINIT].unw_sec = s;
81-
else if (strcmp(".ARM.exidx", secname) == 0)
82-
maps[ARM_SEC_CORE].unw_sec = s;
83-
else if (strcmp(".ARM.exidx.exit.text", secname) == 0)
84-
maps[ARM_SEC_EXIT].unw_sec = s;
85-
else if (strcmp(".ARM.exidx.devexit.text", secname) == 0)
86-
maps[ARM_SEC_DEVEXIT].unw_sec = s;
87-
else if (strcmp(".init.text", secname) == 0)
88-
maps[ARM_SEC_INIT].sec_text = s;
89-
else if (strcmp(".devinit.text", secname) == 0)
90-
maps[ARM_SEC_DEVINIT].sec_text = s;
91-
else if (strcmp(".text", secname) == 0)
92-
maps[ARM_SEC_CORE].sec_text = s;
93-
else if (strcmp(".exit.text", secname) == 0)
94-
maps[ARM_SEC_EXIT].sec_text = s;
95-
else if (strcmp(".devexit.text", secname) == 0)
96-
maps[ARM_SEC_DEVEXIT].sec_text = s;
97-
}
98-
#endif
9970
return 0;
10071
}
10172

@@ -300,41 +271,66 @@ apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab,
300271
return -ENOEXEC;
301272
}
302273

303-
#ifdef CONFIG_ARM_UNWIND
304-
static void register_unwind_tables(struct module *mod)
274+
struct mod_unwind_map {
275+
const Elf_Shdr *unw_sec;
276+
const Elf_Shdr *txt_sec;
277+
};
278+
279+
int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
280+
struct module *mod)
305281
{
282+
#ifdef CONFIG_ARM_UNWIND
283+
const char *secstrs = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
284+
const Elf_Shdr *s, *sechdrs_end = sechdrs + hdr->e_shnum;
285+
struct mod_unwind_map maps[ARM_SEC_MAX];
306286
int i;
307-
for (i = 0; i < ARM_SEC_MAX; ++i) {
308-
struct arm_unwind_mapping *map = &mod->arch.map[i];
309-
if (map->unw_sec && map->sec_text)
310-
map->unwind = unwind_table_add(map->unw_sec->sh_addr,
311-
map->unw_sec->sh_size,
312-
map->sec_text->sh_addr,
313-
map->sec_text->sh_size);
287+
288+
memset(maps, 0, sizeof(maps));
289+
290+
for (s = sechdrs; s < sechdrs_end; s++) {
291+
const char *secname = secstrs + s->sh_name;
292+
293+
if (strcmp(".ARM.exidx.init.text", secname) == 0)
294+
maps[ARM_SEC_INIT].unw_sec = s;
295+
else if (strcmp(".ARM.exidx.devinit.text", secname) == 0)
296+
maps[ARM_SEC_DEVINIT].unw_sec = s;
297+
else if (strcmp(".ARM.exidx", secname) == 0)
298+
maps[ARM_SEC_CORE].unw_sec = s;
299+
else if (strcmp(".ARM.exidx.exit.text", secname) == 0)
300+
maps[ARM_SEC_EXIT].unw_sec = s;
301+
else if (strcmp(".ARM.exidx.devexit.text", secname) == 0)
302+
maps[ARM_SEC_DEVEXIT].unw_sec = s;
303+
else if (strcmp(".init.text", secname) == 0)
304+
maps[ARM_SEC_INIT].txt_sec = s;
305+
else if (strcmp(".devinit.text", secname) == 0)
306+
maps[ARM_SEC_DEVINIT].txt_sec = s;
307+
else if (strcmp(".text", secname) == 0)
308+
maps[ARM_SEC_CORE].txt_sec = s;
309+
else if (strcmp(".exit.text", secname) == 0)
310+
maps[ARM_SEC_EXIT].txt_sec = s;
311+
else if (strcmp(".devexit.text", secname) == 0)
312+
maps[ARM_SEC_DEVEXIT].txt_sec = s;
314313
}
315-
}
316314

317-
static void unregister_unwind_tables(struct module *mod)
318-
{
319-
int i = ARM_SEC_MAX;
320-
while (--i >= 0)
321-
unwind_table_del(mod->arch.map[i].unwind);
322-
}
323-
#else
324-
static inline void register_unwind_tables(struct module *mod) { }
325-
static inline void unregister_unwind_tables(struct module *mod) { }
315+
for (i = 0; i < ARM_SEC_MAX; i++)
316+
if (maps[i].unw_sec && maps[i].txt_sec)
317+
mod->arch.unwind[i] =
318+
unwind_table_add(maps[i].unw_sec->sh_addr,
319+
maps[i].unw_sec->sh_size,
320+
maps[i].txt_sec->sh_addr,
321+
maps[i].txt_sec->sh_size);
326322
#endif
327-
328-
int
329-
module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
330-
struct module *module)
331-
{
332-
register_unwind_tables(module);
333323
return 0;
334324
}
335325

336326
void
337327
module_arch_cleanup(struct module *mod)
338328
{
339-
unregister_unwind_tables(mod);
329+
#ifdef CONFIG_ARM_UNWIND
330+
int i;
331+
332+
for (i = 0; i < ARM_SEC_MAX; i++)
333+
if (mod->arch.unwind[i])
334+
unwind_table_del(mod->arch.unwind[i]);
335+
#endif
340336
}

0 commit comments

Comments
 (0)