Skip to content

Commit b955873

Browse files
committed
sh: Try again at getting the initial return address for an unwind
The previous hack for calculating the return address for the first frame we unwind (dwarf_unwinder_dump) didn't always work. The problem was that it assumed once it read the rule for calculating the return address, there would be no new rules for calculating it. This isn't true because the way in which the CFA is calculated can change as you progress through a function and the return address is figured out using the CFA. Therefore, the way to calculate the return address can change. So, instead of using some offset from the beginning of dwarf_unwind_stack which is just a flakey approach, and instead of executing instructions from the FDE until the return address is setup, we now figure out the pc in dwarf_unwind_stack() just before we call dwarf_cfa_execute_insns(). Signed-off-by: Matt Fleming <matt@console-pimps.org>
1 parent 38f9ddf commit b955873

1 file changed

Lines changed: 6 additions & 35 deletions

File tree

‎arch/sh/kernel/dwarf.c‎

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ struct dwarf_fde *dwarf_lookup_fde(unsigned long pc)
330330
* @fde: the FDE for this function
331331
* @frame: the instructions calculate the CFA for this frame
332332
* @pc: the program counter of the address we're interested in
333-
* @define_ra: keep executing insns until the return addr reg is defined?
334333
*
335334
* Execute the Call Frame instruction sequence starting at
336335
* @insn_start and ending at @insn_end. The instructions describe
@@ -342,36 +341,17 @@ static int dwarf_cfa_execute_insns(unsigned char *insn_start,
342341
struct dwarf_cie *cie,
343342
struct dwarf_fde *fde,
344343
struct dwarf_frame *frame,
345-
unsigned long pc,
346-
bool define_ra)
344+
unsigned long pc)
347345
{
348346
unsigned char insn;
349347
unsigned char *current_insn;
350348
unsigned int count, delta, reg, expr_len, offset;
351-
bool seen_ra_reg;
352349

353350
current_insn = insn_start;
354351

355-
/*
356-
* If we're executing instructions for the dwarf_unwind_stack()
357-
* FDE we need to keep executing instructions until the value of
358-
* DWARF_ARCH_RA_REG is defined. See the comment in
359-
* dwarf_unwind_stack() for more details.
360-
*/
361-
if (define_ra)
362-
seen_ra_reg = false;
363-
else
364-
seen_ra_reg = true;
365-
366-
while (current_insn < insn_end && (frame->pc <= pc || !seen_ra_reg) ) {
352+
while (current_insn < insn_end && frame->pc <= pc) {
367353
insn = __raw_readb(current_insn++);
368354

369-
if (!seen_ra_reg) {
370-
if (frame->num_regs >= DWARF_ARCH_RA_REG &&
371-
frame->regs[DWARF_ARCH_RA_REG].flags)
372-
seen_ra_reg = true;
373-
}
374-
375355
/*
376356
* Firstly, handle the opcodes that embed their operands
377357
* in the instructions.
@@ -511,26 +491,17 @@ struct dwarf_frame *dwarf_unwind_stack(unsigned long pc,
511491
struct dwarf_fde *fde;
512492
unsigned long addr;
513493
int i, offset;
514-
bool define_ra = false;
515494

516495
/*
517496
* If this is the first invocation of this recursive function we
518497
* need get the contents of a physical register to get the CFA
519498
* in order to begin the virtual unwinding of the stack.
520499
*
521-
* Setting "define_ra" to true indictates that we want
522-
* dwarf_cfa_execute_insns() to continue executing instructions
523-
* until we know how to calculate the value of DWARF_ARCH_RA_REG
524-
* (which we need in order to kick off the whole unwinding
525-
* process).
526-
*
527500
* NOTE: the return address is guaranteed to be setup by the
528501
* time this function makes its first function call.
529502
*/
530-
if (!pc && !prev) {
531-
pc = (unsigned long)&dwarf_unwind_stack;
532-
define_ra = true;
533-
}
503+
if (!pc && !prev)
504+
pc = (unsigned long)current_text_addr();
534505

535506
frame = kzalloc(sizeof(*frame), GFP_ATOMIC);
536507
if (!frame)
@@ -566,11 +537,11 @@ struct dwarf_frame *dwarf_unwind_stack(unsigned long pc,
566537
/* CIE initial instructions */
567538
dwarf_cfa_execute_insns(cie->initial_instructions,
568539
cie->instructions_end, cie, fde,
569-
frame, pc, false);
540+
frame, pc);
570541

571542
/* FDE instructions */
572543
dwarf_cfa_execute_insns(fde->instructions, fde->end, cie,
573-
fde, frame, pc, define_ra);
544+
fde, frame, pc);
574545

575546
/* Calculate the CFA */
576547
switch (frame->flags) {

0 commit comments

Comments
 (0)