Skip to content

Commit 854a0d9

Browse files
committed
ARC: DWARF2 .debug_frame based stack unwinder
-Originally written by Rajeshwar Ranga -Derived off of generic unwinder in 2.6.19 and adapted to ARC Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Cc: Rajeshwar Ranga <rajeshwar.ranga@gmail.com>
1 parent 41195d2 commit 854a0d9

9 files changed

Lines changed: 1612 additions & 1 deletion

File tree

‎arch/arc/Kconfig‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ config ARC
2525
select HAVE_ARCH_TRACEHOOK
2626
select HAVE_GENERIC_HARDIRQS
2727
select HAVE_MEMBLOCK
28+
select HAVE_MOD_ARCH_SPECIFIC if ARC_DW2_UNWIND
2829
select HAVE_OPROFILE
2930
select IRQ_DOMAIN
3031
select MODULES_USE_ELF_RELA
@@ -344,6 +345,20 @@ menuconfig ARC_DBG
344345
bool "ARC debugging"
345346
default y
346347

348+
config ARC_DW2_UNWIND
349+
bool "Enable DWARF specific kernel stack unwind"
350+
depends on ARC_DBG
351+
default y
352+
select KALLSYMS
353+
help
354+
Compiles the kernel with DWARF unwind information and can be used
355+
to get stack backtraces.
356+
357+
If you say Y here the resulting kernel image will be slightly larger
358+
but not slower, and it will give very useful debugging information.
359+
If you don't debug the kernel, you can say N, but we may not be able
360+
to solve problems without frame unwind information
361+
347362
config ARC_DBG_TLB_PARANOIA
348363
bool "Paranoia Checks in Low Level TLB Handlers"
349364
depends on ARC_DBG && !SMP

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
#include <asm-generic/module.h>
1616

17+
#ifdef CONFIG_ARC_DW2_UNWIND
18+
struct mod_arch_specific {
19+
void *unw_info;
20+
int unw_sec_idx;
21+
};
22+
#endif
23+
1724
#define MODULE_PROC_FAMILY "ARC700"
1825

1926
#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY

‎arch/arc/include/asm/unwind.h‎

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*/
8+
9+
#ifndef _ASM_ARC_UNWIND_H
10+
#define _ASM_ARC_UNWIND_H
11+
12+
#ifdef CONFIG_ARC_DW2_UNWIND
13+
14+
#include <linux/sched.h>
15+
16+
struct arc700_regs {
17+
unsigned long r0;
18+
unsigned long r1;
19+
unsigned long r2;
20+
unsigned long r3;
21+
unsigned long r4;
22+
unsigned long r5;
23+
unsigned long r6;
24+
unsigned long r7;
25+
unsigned long r8;
26+
unsigned long r9;
27+
unsigned long r10;
28+
unsigned long r11;
29+
unsigned long r12;
30+
unsigned long r13;
31+
unsigned long r14;
32+
unsigned long r15;
33+
unsigned long r16;
34+
unsigned long r17;
35+
unsigned long r18;
36+
unsigned long r19;
37+
unsigned long r20;
38+
unsigned long r21;
39+
unsigned long r22;
40+
unsigned long r23;
41+
unsigned long r24;
42+
unsigned long r25;
43+
unsigned long r26;
44+
unsigned long r27; /* fp */
45+
unsigned long r28; /* sp */
46+
unsigned long r29;
47+
unsigned long r30;
48+
unsigned long r31; /* blink */
49+
unsigned long r63; /* pc */
50+
};
51+
52+
struct unwind_frame_info {
53+
struct arc700_regs regs;
54+
struct task_struct *task;
55+
unsigned call_frame:1;
56+
};
57+
58+
#define UNW_PC(frame) ((frame)->regs.r63)
59+
#define UNW_SP(frame) ((frame)->regs.r28)
60+
#define UNW_BLINK(frame) ((frame)->regs.r31)
61+
62+
/* Rajesh FIXME */
63+
#ifdef CONFIG_FRAME_POINTER
64+
#define UNW_FP(frame) ((frame)->regs.r27)
65+
#define FRAME_RETADDR_OFFSET 4
66+
#define FRAME_LINK_OFFSET 0
67+
#define STACK_BOTTOM_UNW(tsk) STACK_LIMIT((tsk)->thread.ksp)
68+
#define STACK_TOP_UNW(tsk) ((tsk)->thread.ksp)
69+
#else
70+
#define UNW_FP(frame) ((void)(frame), 0)
71+
#endif
72+
73+
#define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1))
74+
75+
#define UNW_REGISTER_INFO \
76+
PTREGS_INFO(r0), \
77+
PTREGS_INFO(r1), \
78+
PTREGS_INFO(r2), \
79+
PTREGS_INFO(r3), \
80+
PTREGS_INFO(r4), \
81+
PTREGS_INFO(r5), \
82+
PTREGS_INFO(r6), \
83+
PTREGS_INFO(r7), \
84+
PTREGS_INFO(r8), \
85+
PTREGS_INFO(r9), \
86+
PTREGS_INFO(r10), \
87+
PTREGS_INFO(r11), \
88+
PTREGS_INFO(r12), \
89+
PTREGS_INFO(r13), \
90+
PTREGS_INFO(r14), \
91+
PTREGS_INFO(r15), \
92+
PTREGS_INFO(r16), \
93+
PTREGS_INFO(r17), \
94+
PTREGS_INFO(r18), \
95+
PTREGS_INFO(r19), \
96+
PTREGS_INFO(r20), \
97+
PTREGS_INFO(r21), \
98+
PTREGS_INFO(r22), \
99+
PTREGS_INFO(r23), \
100+
PTREGS_INFO(r24), \
101+
PTREGS_INFO(r25), \
102+
PTREGS_INFO(r26), \
103+
PTREGS_INFO(r27), \
104+
PTREGS_INFO(r28), \
105+
PTREGS_INFO(r29), \
106+
PTREGS_INFO(r30), \
107+
PTREGS_INFO(r31), \
108+
PTREGS_INFO(r63)
109+
110+
#define UNW_DEFAULT_RA(raItem, dataAlign) \
111+
((raItem).where == Memory && !((raItem).value * (dataAlign) + 4))
112+
113+
extern int arc_unwind(struct unwind_frame_info *frame);
114+
extern void arc_unwind_init(void);
115+
extern void arc_unwind_setup(void);
116+
extern void *unwind_add_table(struct module *module, const void *table_start,
117+
unsigned long table_size);
118+
extern void unwind_remove_table(void *handle, int init_only);
119+
120+
static inline int
121+
arch_unwind_init_running(struct unwind_frame_info *info,
122+
int (*callback) (struct unwind_frame_info *info,
123+
void *arg),
124+
void *arg)
125+
{
126+
return 0;
127+
}
128+
129+
static inline int arch_unw_user_mode(const struct unwind_frame_info *info)
130+
{
131+
return 0;
132+
}
133+
134+
static inline void arch_unw_init_blocked(struct unwind_frame_info *info)
135+
{
136+
return;
137+
}
138+
139+
static inline void arch_unw_init_frame_info(struct unwind_frame_info *info,
140+
struct pt_regs *regs)
141+
{
142+
return;
143+
}
144+
145+
#else
146+
147+
#define UNW_PC(frame) ((void)(frame), 0)
148+
#define UNW_SP(frame) ((void)(frame), 0)
149+
#define UNW_FP(frame) ((void)(frame), 0)
150+
151+
static inline void arc_unwind_init(void)
152+
{
153+
}
154+
155+
static inline void arc_unwind_setup(void)
156+
{
157+
}
158+
#define unwind_add_table(a, b, c)
159+
#define unwind_remove_table(a, b)
160+
161+
#endif /* CONFIG_ARC_DW2_UNWIND */
162+
163+
#endif /* _ASM_ARC_UNWIND_H */

‎arch/arc/kernel/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ obj-y += devtree.o
1414

1515
obj-$(CONFIG_MODULES) += arcksyms.o module.o
1616
obj-$(CONFIG_SMP) += smp.o
17+
obj-$(CONFIG_ARC_DW2_UNWIND) += unwind.o
1718

1819
obj-$(CONFIG_ARC_FPU_SAVE_RESTORE) += fpu.o
1920
CFLAGS_fpu.o += -mdpfp
2021

22+
ifdef CONFIG_ARC_DW2_UNWIND
23+
CFLAGS_ctx_sw.o += -fno-omit-frame-pointer
24+
obj-y += ctx_sw.o
25+
else
2126
obj-y += ctx_sw_asm.o
27+
endif
2228

2329
extra-y := vmlinux.lds head.o

‎arch/arc/kernel/entry.S‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,3 +815,12 @@ ARC_ENTRY sys_clone_wrapper
815815

816816
b ret_from_system_call
817817
ARC_EXIT sys_clone_wrapper
818+
819+
#ifdef CONFIG_ARC_DW2_UNWIND
820+
; Workaround for bug 94179 (STAR ):
821+
; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
822+
; section (.debug_frame) as loadable. So we force it here.
823+
; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
824+
; would not work after a clean build due to kernel build system dependencies.
825+
.section .debug_frame, "wa",@progbits
826+
#endif

‎arch/arc/kernel/module.c‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,50 @@
1414
#include <linux/slab.h>
1515
#include <linux/fs.h>
1616
#include <linux/string.h>
17+
#include <asm/unwind.h>
1718

1819
static inline void arc_write_me(unsigned short *addr, unsigned long value)
1920
{
2021
*addr = (value & 0xffff0000) >> 16;
2122
*(addr + 1) = (value & 0xffff);
2223
}
2324

25+
/* ARC specific section quirks - before relocation loop in generic loader
26+
*
27+
* For dwarf unwinding out of modules, this needs to
28+
* 1. Ensure the .debug_frame is allocatable (ARC Linker bug: despite
29+
* -fasynchronous-unwind-tables it doesn't).
30+
* 2. Since we are iterating thru sec hdr tbl anyways, make a note of
31+
* the exact section index, for later use.
32+
*/
33+
int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
34+
char *secstr, struct module *mod)
35+
{
36+
#ifdef CONFIG_ARC_DW2_UNWIND
37+
int i;
38+
39+
mod->arch.unw_sec_idx = 0;
40+
mod->arch.unw_info = NULL;
41+
42+
for (i = 1; i < hdr->e_shnum; i++) {
43+
if (strcmp(secstr+sechdrs[i].sh_name, ".debug_frame") == 0) {
44+
sechdrs[i].sh_flags |= SHF_ALLOC;
45+
mod->arch.unw_sec_idx = i;
46+
break;
47+
}
48+
}
49+
#endif
50+
return 0;
51+
}
52+
53+
void module_arch_cleanup(struct module *mod)
54+
{
55+
#ifdef CONFIG_ARC_DW2_UNWIND
56+
if (mod->arch.unw_info)
57+
unwind_remove_table(mod->arch.unw_info, 0);
58+
#endif
59+
}
60+
2461
int apply_relocate_add(Elf32_Shdr *sechdrs,
2562
const char *strtab,
2663
unsigned int symindex, /* sec index for sym tbl */
@@ -85,3 +122,24 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
85122
return -ENOEXEC;
86123

87124
}
125+
126+
/* Just before lift off: After sections have been relocated, we add the
127+
* dwarf section to unwinder table pool
128+
* This couldn't be done in module_frob_arch_sections() because
129+
* relocations had not been applied by then
130+
*/
131+
int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
132+
struct module *mod)
133+
{
134+
#ifdef CONFIG_ARC_DW2_UNWIND
135+
void *unw;
136+
int unwsec = mod->arch.unw_sec_idx;
137+
138+
if (unwsec) {
139+
unw = unwind_add_table(mod, (void *)sechdrs[unwsec].sh_addr,
140+
sechdrs[unwsec].sh_size);
141+
mod->arch.unw_info = unw;
142+
}
143+
#endif
144+
return 0;
145+
}

‎arch/arc/kernel/setup.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <asm/irq.h>
2424
#include <asm/arcregs.h>
2525
#include <asm/prom.h>
26+
#include <asm/unwind.h>
2627

2728
#define FIX_PTR(x) __asm__ __volatile__(";" : "+r"(x))
2829

@@ -105,6 +106,8 @@ void __init setup_arch(char **cmdline_p)
105106
conswitchp = &dummy_con;
106107
#endif
107108

109+
arc_unwind_init();
110+
arc_unwind_setup();
108111
}
109112

110113
/*

0 commit comments

Comments
 (0)