[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] tcg: Sanitize shift constants on ppc64le so that shift opera
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH] tcg: Sanitize shift constants on ppc64le so that shift operations with large constants don't generate invalid instructions. |
Date: |
Wed, 3 Jun 2020 08:43:31 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
Hi Catherine,
On 6/3/20 7:23 AM, agrecascino123@gmail.com wrote:
> From: "Catherine A. Frederick" <chocola@animebitch.es>
>
> Signed-off-by: "Catherine A. Frederick" <chocola@animebitch.es>
> ---
> tcg/ppc/tcg-target.inc.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c
> index ee1f9227c1..a5450a5e67 100644
> --- a/tcg/ppc/tcg-target.inc.c
> +++ b/tcg/ppc/tcg-target.inc.c
> @@ -790,21 +790,25 @@ static inline void tcg_out_ext32u(TCGContext *s, TCGReg
> dst, TCGReg src)
>
> static inline void tcg_out_shli32(TCGContext *s, TCGReg dst, TCGReg src, int
> c)
> {
> + c = ((unsigned)c > 32) ? 32 : c;
> tcg_out_rlw(s, RLWINM, dst, src, c, 0, 31 - c);
> }
>
> static inline void tcg_out_shli64(TCGContext *s, TCGReg dst, TCGReg src, int
> c)
> {
> + c = ((unsigned)c > 64) ? 64 : c;
> tcg_out_rld(s, RLDICR, dst, src, c, 63 - c);
> }
>
> static inline void tcg_out_shri32(TCGContext *s, TCGReg dst, TCGReg src, int
> c)
> {
> + c = ((unsigned)c > 32) ? 32 : c;
> tcg_out_rlw(s, RLWINM, dst, src, 32 - c, c, 31);
> }
>
> static inline void tcg_out_shri64(TCGContext *s, TCGReg dst, TCGReg src, int
> c)
> {
> + c = ((unsigned)c > 64) ? 64 : c;
> tcg_out_rld(s, RLDICL, dst, src, 64 - c, c);
> }
I agree there is a bug, but I am not sure we should silently cap the
value this way. I'd rather see the caller provide a value in range, and
maybe the callee use 'tcg_debug_assert(c <= RANGE);' to catch future new
caller added missing the range check.