Re: [PATCH 2/4] msm: scm: Fix improper register assignment

From: Saravana Kannan
Date: Tue Mar 01 2011 - 16:29:21 EST


On 03/01/2011 02:37 AM, Will Deacon wrote:
Hi Nicolas,

On Sat, 2011-02-26 at 20:04 +0000, Nicolas Pitre wrote:
Right. A minimal test case may look like this if someone feels like
filling a gcc bug report:

extern int foo(int x);

int bar(int x)
{
register int a asm("r0") = 1;
x = foo(x);
asm ("add %0, %1, %2" : "=r" (x) : "r" (a), "r" (x));
return x;
}

And the produced code is:

bar:
stmfd sp!, {r3, lr}
bl foo
#APP
add r0, r0, r0
ldmfd sp!, {r3, pc}

So this is clearly bogus.


I agree that this is wrong, but the compiler people may try and argue
the other way. I'll ask some of the compiler guys at ARM and see what
they think.

Nicolas and Will,

Thanks for the sample bug code and thanks for checking with the compiler guys and validating (in another thread) that this is indeed a bug in GCC. Glad to know we weren't doing something stupid.

In any case, fortunately it works with the fix.

Please add a comment in your patch to explain the issue.


Perhaps a more robust fix would be to remove the register int
declarations and handle the parameter marshalling in the same asm block
that contains the smc?

I was thinking the same, but the opposing idea I heard was that not doing it inside the asm block would allow GCC to be make better use of the registers. Didn't have a strong opinion either way, so we went with the implementation that was sent out.

Thanks,
Saravana
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/