Blame SOURCES/0002-dp.h-make-format_guid-handle-misaligned-guid-pointer.patch

d5c737
From 945a87340240b70b3c579773c9481ca913d95a92 Mon Sep 17 00:00:00 2001
d5c737
From: Peter Jones <pjones@redhat.com>
d5c737
Date: Mon, 7 Jan 2019 10:30:59 -0500
d5c737
Subject: [PATCH 02/63] dp.h: make format_guid() handle misaligned guid
d5c737
 pointers safely.
d5c737
d5c737
GCC 9 adds -Werror=address-of-packed-member, which causes us to see the
d5c737
build error reported at
d5c737
 https://bugzilla.opensuse.org/show_bug.cgi?id=1120862 .
d5c737
d5c737
That bug report shows us the following:
d5c737
d5c737
In file included from dp.c:26:
d5c737
dp.h: In function 'format_vendor_helper':
d5c737
dp.h:120:37: error: taking address of packed member of 'struct <anonymous>' may result in an unaligned pointer value [-Werror=address-of-packed-member]
d5c737
  120 |  format_guid(buf, size, off, label, &dp->hw_vendor.vendor_guid);
d5c737
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
d5c737
dp.h:74:25: note: in definition of macro 'format_guid'
d5c737
   74 |   _rc = efi_guid_to_str(guid, &_guidstr);   \
d5c737
      |                         ^~~~
d5c737
cc1: all warnings being treated as errors
d5c737
d5c737
This patch makes format_guid() use a local variable as a bounce buffer
d5c737
in the case that the guid we're passed is aligned as chaotic neutral.
d5c737
d5c737
Note that this only fixes this instance and there may be others that bz
d5c737
didn't show because it exited too soon, and I don't have a gcc 9 build
d5c737
in front of me right now.
d5c737
d5c737
Signed-off-by: Peter Jones <pjones@redhat.com>
d5c737
---
d5c737
 src/dp.h | 11 +++++++++--
d5c737
 1 file changed, 9 insertions(+), 2 deletions(-)
d5c737
d5c737
diff --git a/src/dp.h b/src/dp.h
d5c737
index aa4e3902992..20cb608d05f 100644
d5c737
--- a/src/dp.h
d5c737
+++ b/src/dp.h
d5c737
@@ -70,8 +70,15 @@
d5c737
 #define format_guid(buf, size, off, dp_type, guid) ({			\
d5c737
 		int _rc;						\
d5c737
 		char *_guidstr = NULL;					\
d5c737
-									\
d5c737
-		_rc = efi_guid_to_str(guid, &_guidstr);			\
d5c737
+		efi_guid_t _guid;					\
d5c737
+		const efi_guid_t * const _guid_p =			\
d5c737
+			likely(__alignof__(guid) == sizeof(guid))	\
d5c737
+				? guid					\
d5c737
+				: &_guid;				\
d5c737
+								        \
d5c737
+		if (unlikely(__alignof__(guid) == sizeof(guid)))	\
d5c737
+			memmove(&_guid, guid, sizeof(_guid));		\
d5c737
+		_rc = efi_guid_to_str(_guid_p, &_guidstr);		\
d5c737
 		if (_rc < 0) {						\
d5c737
 			efi_error("could not build %s GUID DP string",	\
d5c737
 				  dp_type);				\
d5c737
-- 
d5c737
2.26.2
d5c737