[PATCH] riscv: Drop const annotation for sp

Palmer Dabbelt palmer at dabbelt.com
Tue Mar 30 06:15:44 BST 2021


On Wed, 17 Mar 2021 08:21:21 PDT (-0700), wangkefeng.wang at huawei.com wrote:
> Hi Palmer, I have a question about
>
> commit 52e7c52d2ded5908e6a4f8a7248e5fa6e0d6809a
> Author: Palmer Dabbelt <palmerdabbelt at google.com>
> Date:   Thu Feb 27 11:07:28 2020 -0800
>
>      RISC-V: Stop relying on GCC's register allocator's hueristics
>
> Why do you only use sp_in_global directly when CONFIG_FRAME_POINTER not
> enabled,
>
> and keep the current_sp part when CONFIG_FRAME_POINTER enabled?

I think I just missed that one when cleaning up the others.  The 
instances of using this locally are all wrong, it's just a hint to GCC.

The patch here is correct.  According to the GCC manual: "Do not use 
type qualifiers such as const and volatile, as the outcome may be 
contrary to expectations."  It doesn't mention in what way "const" may 
provide an unexpected outcome, but that's probably why I didn't have it 
the first time (despite us only reading the variable).  I must have 
forgotten about that when I saw the patch go by.

This is on fixes.

> If there are special reason, I think I should revert the dec822771b01,
> thanks.
>
>
> On 2021/3/17 23:08, Kefeng Wang wrote:
>> The const annotation should not be used for 'sp', or it will
>> become read only and lead to bad stack output.
>>
>> Fixes: dec822771b01 ("riscv: stacktrace: Move register keyword to beginning of declaration")
>> Signed-off-by: Kefeng Wang <wangkefeng.wang at huawei.com>
>> ---
>>   arch/riscv/kernel/stacktrace.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
>> index 3f893c9d9d85..2b3e0cb90d78 100644
>> --- a/arch/riscv/kernel/stacktrace.c
>> +++ b/arch/riscv/kernel/stacktrace.c
>> @@ -14,7 +14,7 @@
>>
>>   #include <asm/stacktrace.h>
>>
>> -register const unsigned long sp_in_global __asm__("sp");
>> +register unsigned long sp_in_global __asm__("sp");
>>
>>   #ifdef CONFIG_FRAME_POINTER
>>



More information about the linux-riscv mailing list