Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7438c4b authored by Tony Wu's avatar Tony Wu Committed by Ralf Baechle
Browse files

MIPS: Fix sibling call handling in get_frame_info



Given a function, get_frame_info() analyzes its instructions
to figure out frame size and return address. get_frame_info()
works as follows:

1. analyze up to 128 instructions if the function size is unknown
2. search for 'addiu/daddiu sp,sp,-immed' for frame size
3. search for 'sw ra,offset(sp)' for return address
4. end search when it sees jr/jal/jalr

This leads to an issue when the given function is a sibling
call, example shown as follows.

801ca110 <schedule>:
801ca110:       8f820000        lw      v0,0(gp)
801ca114:       8c420000        lw      v0,0(v0)
801ca118:       080726f0        j       801c9bc0 <__schedule>
801ca11c:       00000000        nop

801ca120 <io_schedule>:
801ca120:       27bdffe8        addiu   sp,sp,-24
801ca124:       3c028022        lui     v0,0x8022
801ca128:       afbf0014        sw      ra,20(sp)

In this case, get_frame_info() cannot properly detect schedule's
frame info, and eventually returns io_schedule's instead.

This patch adds 'j' to the end search condition to workaround
sibling call cases.

Signed-off-by: default avatarTony Wu <tung7970@gmail.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5236/


Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent d552b233
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -264,7 +264,7 @@ static inline int is_ra_save_ins(union mips_instruction *ip)
#endif
#endif
}
}


static inline int is_jal_jalr_jr_ins(union mips_instruction *ip)
static inline int is_jump_ins(union mips_instruction *ip)
{
{
#ifdef CONFIG_CPU_MICROMIPS
#ifdef CONFIG_CPU_MICROMIPS
	/*
	/*
@@ -288,6 +288,8 @@ static inline int is_jal_jalr_jr_ins(union mips_instruction *ip)
		return 0;
		return 0;
	return (((ip->u_format.uimmediate >> 6) & mm_jalr_op) == mm_jalr_op);
	return (((ip->u_format.uimmediate >> 6) & mm_jalr_op) == mm_jalr_op);
#else
#else
	if (ip->j_format.opcode == j_op)
		return 1;
	if (ip->j_format.opcode == jal_op)
	if (ip->j_format.opcode == jal_op)
		return 1;
		return 1;
	if (ip->r_format.opcode != spec_op)
	if (ip->r_format.opcode != spec_op)
@@ -350,7 +352,7 @@ static int get_frame_info(struct mips_frame_info *info)


	for (i = 0; i < max_insns; i++, ip++) {
	for (i = 0; i < max_insns; i++, ip++) {


		if (is_jal_jalr_jr_ins(ip))
		if (is_jump_ins(ip))
			break;
			break;
		if (!info->frame_size) {
		if (!info->frame_size) {
			if (is_sp_move_ins(ip))
			if (is_sp_move_ins(ip))