qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tcg: pointer size warning on x32 arch


From: Richard Henderson
Subject: Re: tcg: pointer size warning on x32 arch
Date: Sun, 12 Sep 2021 06:10:13 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

On 9/11/21 2:46 PM, Philippe Mathieu-Daudé wrote:
On 9/11/21 11:06 PM, Philippe Mathieu-Daudé wrote:
On 9/11/21 7:50 PM, Michael Tokarev wrote:
Hi.

The following warning is reported by the C compiler when compiling
tcg code on x32 architecture:

In file included from ../../tcg/tcg.c:429:
tcg/i386/tcg-target.c.inc: In function ‘tcg_out_movi_int’:
tcg/i386/tcg-target.c.inc:959:30: warning: cast to pointer from integer
of different size [-Wint-to-pointer-cast]
   959 |     diff = tcg_pcrel_diff(s, (const void *)arg) - 7;

Likely fixed by:

---
diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
index 98d924b91a8..0895f5670a1 100644
--- a/tcg/i386/tcg-target.c.inc
+++ b/tcg/i386/tcg-target.c.inc
@@ -956,7 +956,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType
type,
      }

      /* Try a 7 byte pc-relative lea before the 10 byte movq.  */
-    diff = tcg_pcrel_diff(s, (const void *)arg) - 7;
+    diff = tcg_pcrel_diff(s, (const void *)(uintptr_t)arg) - 7;

Hmm not quite. At this point tcg_out_movi_int() already checked 'arg'
does not fit into a 32-bit value... And on x32 we have sizeof(void*) = 4
so we can't cast a >32-bit value that way.

But tcg_out_movi_int() is called by tcg_out_movi(), and all 'arg' values
are either 0, 1 or a host address (often casted as uintptr_t).

That's false -- 'arg' is an arbitrary 64-bit constant here, for x32. But you're right that no x32 pointers will arrive here, because TCG_TYPE_PTR == TCG_TYPE_I32 for that case and we'll use the 5-byte mov immediate insn.

+    assert(sizeof(uintptr_t) > sizeof(uint32_t));
+
      /* Try a 7 byte pc-relative lea before the 10 byte movq.  */
      diff = tcg_pcrel_diff(s, (const void *)arg) - 7;
      if (diff == (int32_t)diff) {

We may need something like

    if (sizeof(void *) == 8) {
        diff = tcg_pcrel_diff(s, (const void *)(uintptr_t)arg) - 7;
        ...
    }

I wonder if I still have an x32 vmm hanging about.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]