Skip to contentSkip to conversation

linux-user: limit check to HOST_LONG_BITS == 32

PATCH Superseded Alex Bennée 2 participants 3 messages May 21, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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
---
 linux-user/elfload.c | 2 ++
 1 file changed, 2 insertions(+)
linux-user/elfload.c +2 -0
index 01a9323a637..797fbf2337a 100644
@@ -2072,6 +2072,7 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
                          image_name, (uint64_t)guest_hiaddr, reserved_va);
             exit(EXIT_FAILURE);
         }
+#if HOST_LONG_BITS == 32
     } else {
         if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) {
             error_report("%s: requires more virtual address space "
@@ -2079,6 +2080,7 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
                          image_name, (uint64_t)guest_hiaddr - guest_base);
             exit(EXIT_FAILURE);
         }
+#endif
     }
 
     /*
Signature · 1 line
2.20.1
#1 lore raw
Quoted 33 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.

Fixes ee94743034bf
---
 linux-user/elfload.c | 2 ++
 1 file changed, 2 insertions(+)
linux-user/elfload.c +1 -0
index 01a9323a637..797fbf2337a 100644
@@ -2072,6 +2072,7 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
                          image_name, (uint64_t)guest_hiaddr, reserved_va);
             exit(EXIT_FAILURE);
         }
+#if HOST_LONG_BITS == 32
     } else {
         if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) {
             error_report("%s: requires more virtual address space "

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

Quoted 4 lines
linux-user/elfload.c +1 -0
@@ -2079,6 +2080,7 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
                          image_name, (uint64_t)guest_hiaddr - guest_base);
             exit(EXIT_FAILURE);
         }
+#endif

Could we write this so that we have the #if...#endif conditional nested inside the if { ... } else { ... }, rather than having the two conditional constructs oddly intermeshed?

thanks
-- PMM

#2 lore raw
Quoted 35 lines · Peter Maydell
Quoted 34 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.

Fixes ee94743034bf
---
 linux-user/elfload.c | 2 ++
 1 file changed, 2 insertions(+)
linux-user/elfload.c +1 -0
index 01a9323a637..797fbf2337a 100644
@@ -2072,6 +2072,7 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
                          image_name, (uint64_t)guest_hiaddr, reserved_va);
             exit(EXIT_FAILURE);
         }
+#if HOST_LONG_BITS == 32
     } else {
         if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) {
             error_report("%s: requires more virtual address space "
@@ -2079,6 +2080,7 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
                          image_name, (uint64_t)guest_hiaddr - guest_base);
Quoted 8 lines

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

Quoted 3 lines
linux-user/elfload.c +1 -0
             exit(EXIT_FAILURE);
         }
+#endif

Could we write this so that we have the #if...#endif conditional nested inside the if { ... } else { ... }, rather than having the two conditional constructs oddly intermeshed?

Sure - I thought the compiler would complain about having an empty else leg but I've just checked and it doesn't seem to care.

Quoted 3 lines

thanks
-- PMM

Signature · 1 line
Alex Bennée