Skip to content

Commit 912626a

Browse files
efivar: Fix build errors with newer GCC
Bring in two upstream patches that resolve address-of-packed-member errors. Ensure we pass the correct CFLAGS when building efivars. Signed-off-by: Chris Packham <[email protected]>
1 parent 3c04516 commit 912626a

File tree

3 files changed

+227
-0
lines changed

3 files changed

+227
-0
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
From c3c553db85ff10890209d0fe48fb4856ad68e4e0 Mon Sep 17 00:00:00 2001
2+
From: Peter Jones <[email protected]>
3+
Date: Thu, 21 Feb 2019 15:20:12 -0500
4+
Subject: [PATCH] Fix all the places -Werror=address-of-packed-member catches.
5+
6+
This gets rid of all the places GCC 9's -Werror=address-of-packed-member
7+
flags as problematic.
8+
9+
Fixes github issue #123
10+
11+
Signed-off-by: Peter Jones <[email protected]>
12+
---
13+
src/dp-message.c | 6 ++++--
14+
src/dp.h | 12 ++++--------
15+
src/guid.c | 2 +-
16+
src/include/efivar/efivar.h | 2 +-
17+
src/ucs2.h | 27 +++++++++++++++++++--------
18+
5 files changed, 29 insertions(+), 20 deletions(-)
19+
20+
diff --git a/src/dp-message.c b/src/dp-message.c
21+
index 3724e5f..9f96466 100644
22+
--- a/src/dp-message.c
23+
+++ b/src/dp-message.c
24+
@@ -620,11 +620,13 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
25+
) / sizeof(efi_ip_addr_t);
26+
format(buf, size, off, "Dns", "Dns(");
27+
for (int i=0; i < end; i++) {
28+
- const efi_ip_addr_t *addr = &dp->dns.addrs[i];
29+
+ efi_ip_addr_t addr;
30+
+
31+
+ memcpy(&addr, &dp->dns.addrs[i], sizeof(addr));
32+
if (i != 0)
33+
format(buf, size, off, "Dns", ",");
34+
format_ip_addr(buf, size, off, "Dns",
35+
- dp->dns.is_ipv6, addr);
36+
+ dp->dns.is_ipv6, &addr);
37+
}
38+
format(buf, size, off, "Dns", ")");
39+
break;
40+
diff --git a/src/dp.h b/src/dp.h
41+
index 20cb608..1f921d5 100644
42+
--- a/src/dp.h
43+
+++ b/src/dp.h
44+
@@ -71,13 +71,9 @@
45+
int _rc; \
46+
char *_guidstr = NULL; \
47+
efi_guid_t _guid; \
48+
- const efi_guid_t * const _guid_p = \
49+
- likely(__alignof__(guid) == sizeof(guid)) \
50+
- ? guid \
51+
- : &_guid; \
52+
- \
53+
- if (unlikely(__alignof__(guid) == sizeof(guid))) \
54+
- memmove(&_guid, guid, sizeof(_guid)); \
55+
+ const efi_guid_t * const _guid_p = &_guid; \
56+
+ \
57+
+ memmove(&_guid, guid, sizeof(_guid)); \
58+
_rc = efi_guid_to_str(_guid_p, &_guidstr); \
59+
if (_rc < 0) { \
60+
efi_error("could not build %s GUID DP string", \
61+
@@ -86,7 +82,7 @@
62+
_guidstr = onstack(_guidstr, \
63+
strlen(_guidstr)+1); \
64+
_rc = format(buf, size, off, dp_type, "%s", \
65+
- _guidstr); \
66+
+ _guidstr); \
67+
} \
68+
_rc; \
69+
})
70+
diff --git a/src/guid.c b/src/guid.c
71+
index 306c9ff..3156b3b 100644
72+
--- a/src/guid.c
73+
+++ b/src/guid.c
74+
@@ -31,7 +31,7 @@
75+
extern const efi_guid_t efi_guid_zero;
76+
77+
int NONNULL(1, 2) PUBLIC
78+
-efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b)
79+
+efi_guid_cmp(const void * const a, const void * const b)
80+
{
81+
return memcmp(a, b, sizeof (efi_guid_t));
82+
}
83+
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
84+
index 316891c..ad6449d 100644
85+
--- a/src/include/efivar/efivar.h
86+
+++ b/src/include/efivar/efivar.h
87+
@@ -128,7 +128,7 @@ extern int efi_symbol_to_guid(const char *symbol, efi_guid_t *guid)
88+
89+
extern int efi_guid_is_zero(const efi_guid_t *guid);
90+
extern int efi_guid_is_empty(const efi_guid_t *guid);
91+
-extern int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b);
92+
+extern int efi_guid_cmp(const void * const a, const void * const b);
93+
94+
/* import / export functions */
95+
typedef struct efi_variable efi_variable_t;
96+
diff --git a/src/ucs2.h b/src/ucs2.h
97+
index dbb5900..edd8367 100644
98+
--- a/src/ucs2.h
99+
+++ b/src/ucs2.h
100+
@@ -23,16 +23,21 @@
101+
(((val) & ((mask) << (shift))) >> (shift))
102+
103+
static inline size_t UNUSED
104+
-ucs2len(const uint16_t * const s, ssize_t limit)
105+
+ucs2len(const void *vs, ssize_t limit)
106+
{
107+
ssize_t i;
108+
- for (i = 0; i < (limit >= 0 ? limit : i+1) && s[i] != (uint16_t)0; i++)
109+
+ const uint16_t *s = vs;
110+
+ const uint8_t *s8 = vs;
111+
+
112+
+ for (i = 0;
113+
+ i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0;
114+
+ i++, s8 += 2, s++)
115+
;
116+
return i;
117+
}
118+
119+
static inline size_t UNUSED
120+
-ucs2size(const uint16_t * const s, ssize_t limit)
121+
+ucs2size(const void *s, ssize_t limit)
122+
{
123+
size_t rc = ucs2len(s, limit);
124+
rc *= sizeof (uint16_t);
125+
@@ -69,10 +74,11 @@ utf8size(uint8_t *s, ssize_t limit)
126+
}
127+
128+
static inline unsigned char * UNUSED
129+
-ucs2_to_utf8(const uint16_t * const chars, ssize_t limit)
130+
+ucs2_to_utf8(const void * const voidchars, ssize_t limit)
131+
{
132+
ssize_t i, j;
133+
unsigned char *ret;
134+
+ const uint16_t * const chars = voidchars;
135+
136+
if (limit < 0)
137+
limit = ucs2len(chars, -1);
138+
@@ -124,10 +130,12 @@ ucs2_to_utf8(const uint16_t * const chars, ssize_t limit)
139+
}
140+
141+
static inline ssize_t UNUSED NONNULL(4)
142+
-utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8)
143+
+utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8)
144+
{
145+
ssize_t req;
146+
ssize_t i, j;
147+
+ uint16_t *ucs2 = ucs2void;
148+
+ uint16_t val16;
149+
150+
if (!ucs2 && size > 0) {
151+
errno = EINVAL;
152+
@@ -162,10 +170,13 @@ utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8)
153+
val = utf8[i] & 0x7f;
154+
i += 1;
155+
}
156+
- ucs2[j] = val;
157+
+ val16 = val;
158+
+ ucs2[j] = val16;
159+
+ }
160+
+ if (terminate) {
161+
+ val16 = 0;
162+
+ ucs2[j++] = val16;
163+
}
164+
- if (terminate)
165+
- ucs2[j++] = (uint16_t)0;
166+
return j;
167+
};
168+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
From b98ba8921010d03f46704a476c69861515deb1ca Mon Sep 17 00:00:00 2001
2+
From: Peter Jones <[email protected]>
3+
Date: Mon, 7 Jan 2019 10:30:59 -0500
4+
Subject: [PATCH] dp.h: make format_guid() handle misaligned guid pointers
5+
safely.
6+
7+
GCC 9 adds -Werror=address-of-packed-member, which causes us to see the
8+
build error reported at
9+
https://bugzilla.opensuse.org/show_bug.cgi?id=1120862 .
10+
11+
That bug report shows us the following:
12+
13+
In file included from dp.c:26:
14+
dp.h: In function 'format_vendor_helper':
15+
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]
16+
120 | format_guid(buf, size, off, label, &dp->hw_vendor.vendor_guid);
17+
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
18+
dp.h:74:25: note: in definition of macro 'format_guid'
19+
74 | _rc = efi_guid_to_str(guid, &_guidstr); \
20+
| ^~~~
21+
cc1: all warnings being treated as errors
22+
23+
This patch makes format_guid() use a local variable as a bounce buffer
24+
in the case that the guid we're passed is aligned as chaotic neutral.
25+
26+
Note that this only fixes this instance and there may be others that bz
27+
didn't show because it exited too soon, and I don't have a gcc 9 build
28+
in front of me right now.
29+
30+
Signed-off-by: Peter Jones <[email protected]>
31+
---
32+
src/dp.h | 11 +++++++++--
33+
1 file changed, 9 insertions(+), 2 deletions(-)
34+
35+
diff --git a/src/dp.h b/src/dp.h
36+
index aa4e390..20cb608 100644
37+
--- a/src/dp.h
38+
+++ b/src/dp.h
39+
@@ -70,8 +70,15 @@
40+
#define format_guid(buf, size, off, dp_type, guid) ({ \
41+
int _rc; \
42+
char *_guidstr = NULL; \
43+
- \
44+
- _rc = efi_guid_to_str(guid, &_guidstr); \
45+
+ efi_guid_t _guid; \
46+
+ const efi_guid_t * const _guid_p = \
47+
+ likely(__alignof__(guid) == sizeof(guid)) \
48+
+ ? guid \
49+
+ : &_guid; \
50+
+ \
51+
+ if (unlikely(__alignof__(guid) == sizeof(guid))) \
52+
+ memmove(&_guid, guid, sizeof(_guid)); \
53+
+ _rc = efi_guid_to_str(_guid_p, &_guidstr); \
54+
if (_rc < 0) { \
55+
efi_error("could not build %s GUID DP string", \
56+
dp_type); \

patches/efivar/37/series

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ remove-arrows.patch
1010
0005-Fix-variable-sz-uninitialized-error.patch
1111
0006-Fix-parsing-for-nvme-subsystem-devices.patch
1212
Always-initialize-any-variable-we-use-with-sscanf-s-.patch
13+
dp.h-make-format_guid-handle-misaligned-guid-pointer.patch
14+
Fix-all-the-places-Werror-address-of-packed-member-c.patch
15+

0 commit comments

Comments
 (0)