Skip to contentSkip to conversation

linux-user: limit check to HOST_LONG_BITS == 32

PATCH In review Alex Bennée 3 participants 3 messages May 21, 2020 – May 22, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 linux-user: limit check to HOST_LONG_BITS == 32

Newer clangs rightly spot that you can never exceed the full address space of 64 bit hosts with:

linux-user/elfload.c:2076:41: error: result of comparison 'unsigned long' > 18446744073709551615 is always false [-Werror,-Wtautological-type-limit-compare]
4685 if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) {
4686 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~
4687 1 error generated.

So lets limit the check to 32 bit hosts only.

Fixes ee94743034bf

---
v2
- move inside else bracket

---
 linux-user/elfload.c | 2 ++
 1 file changed, 2 insertions(+)
linux-user/elfload.c +2 -0
index 01a9323a637..de82eaf5420 100644
@@ -2073,12 +2073,14 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
             exit(EXIT_FAILURE);
         }
     } else {
+#if HOST_LONG_BITS == 32
         if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) {
             error_report("%s: requires more virtual address space "
                          "than the host can provide (0x%" PRIx64 ")",
                          image_name, (uint64_t)guest_hiaddr - guest_base);
             exit(EXIT_FAILURE);
         }
+#endif
     }
 
     /*
Signature · 1 line
2.20.1
#1 lore raw
Quoted 13 lines · Alex Bennée

Newer clangs rightly spot that you can never exceed the full address space of 64 bit hosts with:

linux-user/elfload.c:2076:41: error: result of comparison 'unsigned long' > 18446744073709551615 is always false [-Werror,-Wtautological-type-limit-compare]
4685 if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) {
4686 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~
4687 1 error generated.

So lets limit the check to 32 bit hosts only.

linux-user/elfload.c static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, · line 2083

Quoted 8 lines
linux-user/elfload.c +2 -0
+#if HOST_LONG_BITS == 32
         if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) {
             error_report("%s: requires more virtual address space "
                          "than the host can provide (0x%" PRIx64 ")",
                          image_name, (uint64_t)guest_hiaddr - guest_base);
             exit(EXIT_FAILURE);
         }
+#endif

Is this also a tautological compare in the host==32 && guest==32 case? Do we maybe want "#if HOST_LONG_BITS < TARGET_ABI_BITS" ?

thanks
-- PMM

#2 lore raw
In reply to Alex Bennée
Quoted 10 lines · Alex Bennée

Newer clangs rightly spot that you can never exceed the full address space of 64 bit hosts with:

linux-user/elfload.c:2076:41: error: result of comparison 'unsigned long' > 18446744073709551615 is always false [-Werror,-Wtautological-type-limit-compare]
4685 if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) {
4686 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~
4687 1 error generated.

Quoted 7 lines

So lets limit the check to 32 bit hosts only.

Fixes ee94743034bf

---

I say again that I'd prefer that we disable this warning.

r~