* [PATCH v2] cris: arch-v10: kgdb: Add volatile for static variable is_dyn_brkp
@ 2015-07-10 21:50 Chen Gang
2015-08-04 15:01 ` Hans-Peter Nilsson
0 siblings, 1 reply; 3+ messages in thread
From: Chen Gang @ 2015-07-10 21:50 UTC (permalink / raw)
To: starvik, jesper.nilsson
Cc: linux-cris-kernel, linux-kernel, Hans-Peter Nilsson
Within one C file, current gcc can optimize the global static variables
according to the C code, but it will skip assembly code -- it will pass
them to gas directly.
if the static variable is used between C code and assembly code in one C
file (e.g. is_dyn_brkp in kgdb.c), it needs volatile to let gcc know it
should not be optimized, or it may cause issue.
The related error in this case:
LD init/built-in.o
arch/cris/arch-v10/kernel/built-in.o: In function `kgdb_handle_breakpoint':
(.text+0x2aca): undefined reference to `is_dyn_brkp'
arch/cris/arch-v10/kernel/built-in.o: In function `is_static':
kgdb.c:(.text+0x2ada): undefined reference to `is_dyn_brkp'
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
arch/cris/arch-v10/kernel/kgdb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/cris/arch-v10/kernel/kgdb.c b/arch/cris/arch-v10/kernel/kgdb.c
index 5b61335..8faddd3 100644
--- a/arch/cris/arch-v10/kernel/kgdb.c
+++ b/arch/cris/arch-v10/kernel/kgdb.c
@@ -351,7 +351,7 @@ char internal_stack[INTERNAL_STACK_SIZE];
breakpoint to be handled. A static breakpoint uses the content of register
BRP as it is whereas a dynamic breakpoint requires subtraction with 2
in order to execute the instruction. The first breakpoint is static. */
-static unsigned char is_dyn_brkp = 0;
+static volatile unsigned char is_dyn_brkp;
/********************************* String library ****************************/
/* Single-step over library functions creates trap loops. */
--
1.9.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] cris: arch-v10: kgdb: Add volatile for static variable is_dyn_brkp
2015-07-10 21:50 [PATCH v2] cris: arch-v10: kgdb: Add volatile for static variable is_dyn_brkp Chen Gang
@ 2015-08-04 15:01 ` Hans-Peter Nilsson
2015-08-05 14:19 ` Chen Gang
0 siblings, 1 reply; 3+ messages in thread
From: Hans-Peter Nilsson @ 2015-08-04 15:01 UTC (permalink / raw)
To: xili_gchen_5257; +Cc: starvik, jespern, linux-cris-kernel, linux-kernel
> From: Chen Gang <xili_gchen_5257@hotmail.com>
> Date: Fri, 10 Jul 2015 23:50:07 +0200
> Within one C file, current gcc can optimize the global static variables
> according to the C code, but it will skip assembly code -- it will pass
> them to gas directly.
>
> if the static variable is used between C code and assembly code in one C
> file (e.g. is_dyn_brkp in kgdb.c), it needs volatile to let gcc know it
> should not be optimized, or it may cause issue.
In this case it's *mostly* a matter of taste but please avoid
using volatile as a hammer when there are other tools available.
> -static unsigned char is_dyn_brkp = 0;
> +static volatile unsigned char is_dyn_brkp;
Please instead use "__used", i.e.
+static unsigned char __used is_dyn_brkp = 0;
brgds, H-P
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] cris: arch-v10: kgdb: Add volatile for static variable is_dyn_brkp
2015-08-04 15:01 ` Hans-Peter Nilsson
@ 2015-08-05 14:19 ` Chen Gang
0 siblings, 0 replies; 3+ messages in thread
From: Chen Gang @ 2015-08-05 14:19 UTC (permalink / raw)
To: Hans-Peter Nilsson; +Cc: starvik, jespern, linux-cris-kernel, linux-kernel
On 8/4/15 23:01, Hans-Peter Nilsson wrote:
>> From: Chen Gang <xili_gchen_5257@hotmail.com>
>> Date: Fri, 10 Jul 2015 23:50:07 +0200
>
>> Within one C file, current gcc can optimize the global static variables
>> according to the C code, but it will skip assembly code -- it will pass
>> them to gas directly.
>>
>> if the static variable is used between C code and assembly code in one C
>> file (e.g. is_dyn_brkp in kgdb.c), it needs volatile to let gcc know it
>> should not be optimized, or it may cause issue.
>
> In this case it's *mostly* a matter of taste but please avoid
> using volatile as a hammer when there are other tools available.
>
>> -static unsigned char is_dyn_brkp = 0;
>> +static volatile unsigned char is_dyn_brkp;
>
> Please instead use "__used", i.e.
> +static unsigned char __used is_dyn_brkp = 0;
>
OK, thanks. I shall send patch v3 for it, next.
Thanks.
--
Chen Gang
Open, share, and attitude like air, water, and life which God blessed
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-05 14:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10 21:50 [PATCH v2] cris: arch-v10: kgdb: Add volatile for static variable is_dyn_brkp Chen Gang
2015-08-04 15:01 ` Hans-Peter Nilsson
2015-08-05 14:19 ` Chen Gang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome