Skip to contentSkip to conversation

tools: fix gcc 8.1 build

PATCH In review Wei Liu 2 participants 5 messages Jul 26, 2018 – Aug 20, 2018

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover tools: fix gcc 8.1 build

Wei Liu (2):
tools: update ipxe changeset
xenpmd: make 32 bit gcc 8.1 non-debug build work

 tools/firmware/etherboot/Makefile |  2 +-
 tools/xenpmd/xenpmd.c             | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#1 lore raw

PATCH 1/2 tools: update ipxe changeset

This placates gcc 8.1. The commit comes from ipxe master branch as of July 25, 2018.

---
 tools/firmware/etherboot/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/firmware/etherboot/Makefile +1 -1
index 4de6d24a13..3868f876ea 100644
@@ -10,7 +10,7 @@ else
 IPXE_GIT_URL ?= git://git.ipxe.org/ipxe.git
 endif
 
-IPXE_GIT_TAG := 356f6c1b64d7a97746d1816cef8ca22bdd8d0b5d
+IPXE_GIT_TAG := d2063b7693e0e35db97b2264aa987eb6341ae779
 
 IPXE_TARBALL_URL ?= $(XEN_EXTFILES_URL)/ipxe-git-$(IPXE_GIT_TAG).tar.gz
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] tools: update ipxe changeset

Wei Liu writes ("[PATCH 1/2] tools: update ipxe changeset"):

Quoted 2 lines

This placates gcc 8.1. The commit comes from ipxe master branch as of July 25, 2018.

Fine, whatever. FTR, I don't think it is useful to ask for an ack of this kind of patch, assuming the commit is indeed from ipxe master. (And if some kind of review were needed, we would need much more information in the commit message about what changed.)

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#3 lore raw

PATCH 2/2 xenpmd: make 32 bit gcc 8.1 non-debug build work

In reply to Wei Liu

32 bit gcc 8.1 non-debug build yields:

xenpmd.c:354:23: error: '%02x' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Werror=format-truncation=]

     snprintf(val, 3, "%02x",
                       ^~~~
xenpmd.c:354:22: note: directive argument in the range [40, 2147483778]
     snprintf(val, 3, "%02x",
                      ^~~~~~
xenpmd.c:354:5: note: 'snprintf' output between 3 and 9 bytes into a destination of size 3
     snprintf(val, 3, "%02x",
     ^~~~~~~~~~~~~~~~~~~~~~~~
              (unsigned int)(9*4 +
              ~~~~~~~~~~~~~~~~~~~~
                             strlen(info->model_number) +
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                             strlen(info->serial_number) +
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                             strlen(info->battery_type) +
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                             strlen(info->oem_info) + 4));
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All info->* used in calculation are 32 bytes long, and the parsing code makes sure they are null-terminated, so the end result of the expression won't exceed 255, which should be able to be fit into 3 bytes in hexadecimal format.

Add an assertion to make gcc happy.

---
 tools/xenpmd/xenpmd.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/xenpmd/xenpmd.c +6 -6
index 56412a9a81..1c801caa71 100644
@@ -40,6 +40,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <xenstore.h>
+#include <assert.h>
 
 /* #define RUN_STANDALONE */
 #define RUN_IN_SIMULATE_MODE
@@ -345,18 +346,17 @@ void write_ulong_lsb_first(char *temp_val, unsigned long val)
 void write_battery_info_to_xenstore(struct battery_info *info)
 {
     char val[1024], string_info[256];
+    unsigned int len;
 
     xs_mkdir(xs, XBT_NULL, "/pm");
    
     memset(val, 0, 1024);
     memset(string_info, 0, 256);
     /* write 9 dwords (so 9*4) + length of 4 strings + 4 null terminators */
-    snprintf(val, 3, "%02x", 
-             (unsigned int)(9*4 +
-                            strlen(info->model_number) +
-                            strlen(info->serial_number) +
-                            strlen(info->battery_type) +
-                            strlen(info->oem_info) + 4));
+    len = 9 * 4 + strlen(info->model_number) + strlen(info->serial_number) +
+          strlen(info->battery_type) + strlen(info->oem_info) + 4;
+    assert(len < 255);
+    snprintf(val, 3, "%02x", len);
     write_ulong_lsb_first(val+2, info->present);
     write_ulong_lsb_first(val+10, info->design_capacity);
     write_ulong_lsb_first(val+18, info->last_full_capacity);
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] xenpmd: make 32 bit gcc 8.1 non-debug build work

Wei Liu writes ("[PATCH 2/2] xenpmd: make 32 bit gcc 8.1 non-debug build work"):

Quoted 1 line

32 bit gcc 8.1 non-debug build yields:

...

tools/xenpmd/xenpmd.c void write_ulong_lsb_first(char *temp_val, unsigned long val) · line 359

Quoted 7 lines
     /* write 9 dwords (so 9*4) + length of 4 strings + 4 null terminators */
tools/xenpmd/xenpmd.c +0 -6
-    snprintf(val, 3, "%02x", 
-             (unsigned int)(9*4 +
-                            strlen(info->model_number) +
-                            strlen(info->serial_number) +
-                            strlen(info->battery_type) +
-                            strlen(info->oem_info) + 4));

This is pretty unpleasant!

tools/xenpmd/xenpmd.c void write_ulong_lsb_first(char *temp_val, unsigned long val) · line 359

Quoted 4 lines
tools/xenpmd/xenpmd.c +4 -0
+    len = 9 * 4 + strlen(info->model_number) + strlen(info->serial_number) +
+          strlen(info->battery_type) + strlen(info->oem_info) + 4;
+    assert(len < 255);
+    snprintf(val, 3, "%02x", len);

This is slightly less unpleasant, I guess...

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel