Skip to contentSkip to conversation

Drop gnulib fix-base64.patch

PATCH In review Robbie Harwood 5 participants 12 messages Oct 28, 2021 – Dec 9, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Drop gnulib fix-base64.patch

Originally added in 9fbdec2f6b4fa8b549daa4d49134d1fe89d95ef9 and subsequently modified in 552c9fd08122a3036c724ce96dfe68aa2f75705f, fix-base64.patch handled two problems we have using gnulib, which are exerciesd by the base64 module but not directly caused by it.

First, grub2 defines its own bool type, while gnulib expects the equivalent of stdbool.h to be present. Rather than patching gnulib, instead use gnulib's stdbool module to provide a bool type if needed. (Suggested by Simon Josefsson.)

Second, our config.h doesn't always inherit config-util.h, which is where gnulib-related options like _GL_ATTRIBUTE_CONST end up. fix-base64.h worked around this by defining the attribute away, but this workaround is better placed in config.h itself, not a gnulib patch.

---
 bootstrap.conf                                |  3 ++-
 config.h.in                                   |  3 +++
 grub-core/lib/gnulib-patches/fix-base64.patch | 21 -------------------
 grub-core/lib/posix_wrap/sys/types.h          |  7 +++----
 grub-core/lib/xzembed/xz.h                    |  5 +----
 5 files changed, 9 insertions(+), 30 deletions(-)
 delete mode 100644 grub-core/lib/gnulib-patches/fix-base64.patch
bootstrap.conf +2 -1
index 0dd893c5c..21a8cf15d 100644
@@ -35,6 +35,7 @@ gnulib_modules="
   realloc-gnu
   regex
   save-cwd
+  stdbool
 "
 
 gnulib_tool_option_extras="\
@@ -80,7 +81,7 @@ cp -a INSTALL INSTALL.grub
 
 bootstrap_post_import_hook () {
   set -e
-  for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \
+  for patchname in fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \
       fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort; do
     patch -d grub-core/lib/gnulib -p2 \
       < "grub-core/lib/gnulib-patches/$patchname.patch"
config.h.in +3 -0
index 9e8f9911b..2b65c86c4 100644
@@ -64,4 +64,7 @@
 
 #define _GNU_SOURCE 1
 
+/* For gnulib's base64 code. */
+#define _GL_ATTRIBUTE_CONST /* empty */
+
 #endif
grub-core/lib/gnulib-patches/fix-base64.patch deleted +0 -21
deleted file mode 100644
index 985db1279..000000000
@@ -1,21 +0,0 @@
-diff --git a/lib/base64.h b/lib/base64.h
-index 9cd0183b8..185a2afa1 100644
---- a/lib/base64.h
-+++ b/lib/base64.h
-@@ -21,8 +21,14 @@
- /* Get size_t. */
- # include <stddef.h>
- 
--/* Get bool. */
--# include <stdbool.h>
-+#ifndef GRUB_POSIX_BOOL_DEFINED
-+typedef enum { false = 0, true = 1 } bool;
-+#define GRUB_POSIX_BOOL_DEFINED 1
-+#endif
-+
-+#ifndef _GL_ATTRIBUTE_CONST
-+# define _GL_ATTRIBUTE_CONST /* empty */
-+#endif
- 
- # ifdef __cplusplus
- extern "C" {
grub-core/lib/posix_wrap/sys/types.h +3 -4
index 854eb0122..eeda543c4 100644
@@ -23,11 +23,10 @@
 
 #include <stddef.h>
 
+/* Provided by gnulib if not present. */
+#include <stdbool.h>
+
 typedef grub_ssize_t ssize_t;
-#ifndef GRUB_POSIX_BOOL_DEFINED
-typedef enum { false = 0, true = 1 } bool;
-#define GRUB_POSIX_BOOL_DEFINED 1
-#endif
 
 typedef grub_uint8_t uint8_t;
 typedef grub_uint16_t uint16_t;
grub-core/lib/xzembed/xz.h +1 -4
index f7b32d800..d1417039a 100644
@@ -29,10 +29,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <grub/misc.h>
-
-#ifndef GRUB_POSIX_BOOL_DEFINED
-typedef enum { false = 0, true = 1 } bool;
-#endif
+#include <stdbool.h>
 
 /**
  * enum xz_ret - Return codes
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Robbie,

Just tried it in a build, and it works for me.

Quoted 10 lines · Robbie Harwood

Originally added in 9fbdec2f6b4fa8b549daa4d49134d1fe89d95ef9 and subsequently modified in 552c9fd08122a3036c724ce96dfe68aa2f75705f, fix-base64.patch handled two problems we have using gnulib, which are exerciesd by the base64 module but not directly caused by it.

First, grub2 defines its own bool type, while gnulib expects the equivalent of stdbool.h to be present. Rather than patching gnulib, instead use gnulib's stdbool module to provide a bool type if needed. (Suggested by Simon Josefsson.)

Quoted 6 lines

Second, our config.h doesn't always inherit config-util.h, which is where gnulib-related options like _GL_ATTRIBUTE_CONST end up. fix-base64.h worked around this by defining the attribute away, but this workaround is better placed in config.h itself, not a gnulib patch.

Thanks,

Darren.

Quoted 112 lines
---
 bootstrap.conf                                |  3 ++-
 config.h.in                                   |  3 +++
 grub-core/lib/gnulib-patches/fix-base64.patch | 21 -------------------
 grub-core/lib/posix_wrap/sys/types.h          |  7 +++----
 grub-core/lib/xzembed/xz.h                    |  5 +----
 5 files changed, 9 insertions(+), 30 deletions(-)
 delete mode 100644 grub-core/lib/gnulib-patches/fix-base64.patch
bootstrap.conf +2 -1
index 0dd893c5c..21a8cf15d 100644
@@ -35,6 +35,7 @@ gnulib_modules="
   realloc-gnu
   regex
   save-cwd
+  stdbool
 "
 
 gnulib_tool_option_extras="\
@@ -80,7 +81,7 @@ cp -a INSTALL INSTALL.grub
 
 bootstrap_post_import_hook () {
   set -e
-  for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \
+  for patchname in fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \
       fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort; do
     patch -d grub-core/lib/gnulib -p2 \
       < "grub-core/lib/gnulib-patches/$patchname.patch"
config.h.in +3 -0
index 9e8f9911b..2b65c86c4 100644
@@ -64,4 +64,7 @@
 
 #define _GNU_SOURCE 1
 
+/* For gnulib's base64 code. */
+#define _GL_ATTRIBUTE_CONST /* empty */
+
 #endif
grub-core/lib/gnulib-patches/fix-base64.patch deleted +0 -21
deleted file mode 100644
index 985db1279..000000000
@@ -1,21 +0,0 @@
-diff --git a/lib/base64.h b/lib/base64.h
-index 9cd0183b8..185a2afa1 100644
---- a/lib/base64.h
-+++ b/lib/base64.h
-@@ -21,8 +21,14 @@
- /* Get size_t. */
- # include <stddef.h>
- 
--/* Get bool. */
--# include <stdbool.h>
-+#ifndef GRUB_POSIX_BOOL_DEFINED
-+typedef enum { false = 0, true = 1 } bool;
-+#define GRUB_POSIX_BOOL_DEFINED 1
-+#endif
-+
-+#ifndef _GL_ATTRIBUTE_CONST
-+# define _GL_ATTRIBUTE_CONST /* empty */
-+#endif
- 
- # ifdef __cplusplus
- extern "C" {
grub-core/lib/posix_wrap/sys/types.h +3 -4
index 854eb0122..eeda543c4 100644
@@ -23,11 +23,10 @@
 
 #include <stddef.h>
 
+/* Provided by gnulib if not present. */
+#include <stdbool.h>
+
 typedef grub_ssize_t ssize_t;
-#ifndef GRUB_POSIX_BOOL_DEFINED
-typedef enum { false = 0, true = 1 } bool;
-#define GRUB_POSIX_BOOL_DEFINED 1
-#endif
 
 typedef grub_uint8_t uint8_t;
 typedef grub_uint16_t uint16_t;
grub-core/lib/xzembed/xz.h +1 -4
index f7b32d800..d1417039a 100644
@@ -29,10 +29,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <grub/misc.h>
-
-#ifndef GRUB_POSIX_BOOL_DEFINED
-typedef enum { false = 0, true = 1 } bool;
-#endif
+#include <stdbool.h>
 
 /**
  * enum xz_ret - Return codes
Signature · 7 lines
2.33.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#2 lore raw
In reply to Robbie Harwood
Quoted 10 lines · Robbie Harwood

Originally added in 9fbdec2f6b4fa8b549daa4d49134d1fe89d95ef9 and subsequently modified in 552c9fd08122a3036c724ce96dfe68aa2f75705f, fix-base64.patch handled two problems we have using gnulib, which are exerciesd by the base64 module but not directly caused by it.

First, grub2 defines its own bool type, while gnulib expects the equivalent of stdbool.h to be present. Rather than patching gnulib, instead use gnulib's stdbool module to provide a bool type if needed. (Suggested by Simon Josefsson.)

Quoted 6 lines

Second, our config.h doesn't always inherit config-util.h, which is where gnulib-related options like _GL_ATTRIBUTE_CONST end up. fix-base64.h worked around this by defining the attribute away, but this workaround is better placed in config.h itself, not a gnulib patch.

I agree this looks a lot cleaner than patching in support for booleans. Thanks for the patch!

Patrick

Quoted 112 lines
---
 bootstrap.conf                                |  3 ++-
 config.h.in                                   |  3 +++
 grub-core/lib/gnulib-patches/fix-base64.patch | 21 -------------------
 grub-core/lib/posix_wrap/sys/types.h          |  7 +++----
 grub-core/lib/xzembed/xz.h                    |  5 +----
 5 files changed, 9 insertions(+), 30 deletions(-)
 delete mode 100644 grub-core/lib/gnulib-patches/fix-base64.patch
bootstrap.conf +2 -1
index 0dd893c5c..21a8cf15d 100644
@@ -35,6 +35,7 @@ gnulib_modules="
   realloc-gnu
   regex
   save-cwd
+  stdbool
 "
 
 gnulib_tool_option_extras="\
@@ -80,7 +81,7 @@ cp -a INSTALL INSTALL.grub
 
 bootstrap_post_import_hook () {
   set -e
-  for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \
+  for patchname in fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \
       fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort; do
     patch -d grub-core/lib/gnulib -p2 \
       < "grub-core/lib/gnulib-patches/$patchname.patch"
config.h.in +3 -0
index 9e8f9911b..2b65c86c4 100644
@@ -64,4 +64,7 @@
 
 #define _GNU_SOURCE 1
 
+/* For gnulib's base64 code. */
+#define _GL_ATTRIBUTE_CONST /* empty */
+
 #endif
grub-core/lib/gnulib-patches/fix-base64.patch deleted +0 -21
deleted file mode 100644
index 985db1279..000000000
@@ -1,21 +0,0 @@
-diff --git a/lib/base64.h b/lib/base64.h
-index 9cd0183b8..185a2afa1 100644
---- a/lib/base64.h
-+++ b/lib/base64.h
-@@ -21,8 +21,14 @@
- /* Get size_t. */
- # include <stddef.h>
- 
--/* Get bool. */
--# include <stdbool.h>
-+#ifndef GRUB_POSIX_BOOL_DEFINED
-+typedef enum { false = 0, true = 1 } bool;
-+#define GRUB_POSIX_BOOL_DEFINED 1
-+#endif
-+
-+#ifndef _GL_ATTRIBUTE_CONST
-+# define _GL_ATTRIBUTE_CONST /* empty */
-+#endif
- 
- # ifdef __cplusplus
- extern "C" {
grub-core/lib/posix_wrap/sys/types.h +3 -4
index 854eb0122..eeda543c4 100644
@@ -23,11 +23,10 @@
 
 #include <stddef.h>
 
+/* Provided by gnulib if not present. */
+#include <stdbool.h>
+
 typedef grub_ssize_t ssize_t;
-#ifndef GRUB_POSIX_BOOL_DEFINED
-typedef enum { false = 0, true = 1 } bool;
-#define GRUB_POSIX_BOOL_DEFINED 1
-#endif
 
 typedef grub_uint8_t uint8_t;
 typedef grub_uint16_t uint16_t;
grub-core/lib/xzembed/xz.h +1 -4
index f7b32d800..d1417039a 100644
@@ -29,10 +29,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <grub/misc.h>
-
-#ifndef GRUB_POSIX_BOOL_DEFINED
-typedef enum { false = 0, true = 1 } bool;
-#endif
+#include <stdbool.h>
 
 /**
  * enum xz_ret - Return codes
Signature · 7 lines
2.33.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#3 lore raw
In reply to Robbie Harwood
Quoted 51 lines · Robbie Harwood

Originally added in 9fbdec2f6b4fa8b549daa4d49134d1fe89d95ef9 and subsequently modified in 552c9fd08122a3036c724ce96dfe68aa2f75705f, fix-base64.patch handled two problems we have using gnulib, which are exerciesd by the base64 module but not directly caused by it.

First, grub2 defines its own bool type, while gnulib expects the equivalent of stdbool.h to be present. Rather than patching gnulib, instead use gnulib's stdbool module to provide a bool type if needed. (Suggested by Simon Josefsson.)

Second, our config.h doesn't always inherit config-util.h, which is where gnulib-related options like _GL_ATTRIBUTE_CONST end up. fix-base64.h worked around this by defining the attribute away, but this workaround is better placed in config.h itself, not a gnulib patch.

---
 bootstrap.conf                                |  3 ++-
 config.h.in                                   |  3 +++
 grub-core/lib/gnulib-patches/fix-base64.patch | 21 -------------------
 grub-core/lib/posix_wrap/sys/types.h          |  7 +++----
 grub-core/lib/xzembed/xz.h                    |  5 +----
 5 files changed, 9 insertions(+), 30 deletions(-)
 delete mode 100644 grub-core/lib/gnulib-patches/fix-base64.patch
bootstrap.conf +2 -1
index 0dd893c5c..21a8cf15d 100644
@@ -35,6 +35,7 @@ gnulib_modules="
   realloc-gnu
   regex
   save-cwd
+  stdbool
 "
 
 gnulib_tool_option_extras="\
@@ -80,7 +81,7 @@ cp -a INSTALL INSTALL.grub
 
 bootstrap_post_import_hook () {
   set -e
-  for patchname in fix-base64 fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \
+  for patchname in fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \
       fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width no-abort; do
     patch -d grub-core/lib/gnulib -p2 \
       < "grub-core/lib/gnulib-patches/$patchname.patch"
config.h.in +0 -0
index 9e8f9911b..2b65c86c4 100644

config.h.in line 68

Quoted 5 lines
config.h.in +2 -0
@@ -64,4 +64,7 @@
 
 #define _GNU_SOURCE 1
 
+/* For gnulib's base64 code. */
+#define _GL_ATTRIBUTE_CONST /* empty */

Do we support any compiler so old or configuration so weird that we can't simply use 'const' here?

Kind regards,
Daniel

#4 lore raw
Quoted 7 lines · Daniel Axtens

config.h.in line 68

Quoted 2 lines · Robbie Harwood
config.h.in +2 -0
+/* For gnulib's base64 code. */
+#define _GL_ATTRIBUTE_CONST /* empty */

Do we support any compiler so old or configuration so weird that we can't simply use 'const' here?

Unfortunately it's not quite that simple. _GL_ATTRIBUTE_CONST actually gates turning on __attribute ((__const__)), which if memory serves is a GCC extension. I don't know what the support matrix on grub is, but based on the original patch there was a need to support non-gcc-likes. Would be fine with changing that, though.

(Personally, I think it should be obvious to a reasonable compiler that isbase64() is purely arithmetic. However, gnulib upstream did not like my proposal to drop the attribute marker, so we're stuck with it.)

Be well,
--Robbie

#5 lore raw

CC-ing Daren, Patrick and Vladimir...

Quoted 16 lines · Robbie Harwood
Quoted 7 lines · Daniel Axtens

config.h.in line 68

Quoted 2 lines · Robbie Harwood
config.h.in +2 -0
+/* For gnulib's base64 code. */
+#define _GL_ATTRIBUTE_CONST /* empty */

Do we support any compiler so old or configuration so weird that we can't simply use 'const' here?

Unfortunately it's not quite that simple. _GL_ATTRIBUTE_CONST actually gates turning on __attribute ((__const__)), which if memory serves is a GCC extension. I don't know what the support matrix on grub is, but based on the original patch there was a need to support non-gcc-likes. Would be fine with changing that, though.

Quoted 3 lines

(Personally, I think it should be obvious to a reasonable compiler that isbase64() is purely arithmetic. However, gnulib upstream did not like my proposal to drop the attribute marker, so we're stuck with it.)

When I started looking at this issue I realized we have bigger problem here than lack of _GL_ATTRIBUTE_CONST definition. In general all _GL_* constants land in config-util.h.in and finally in config-util.h. It does not make a lot of sense because config-util.h is not included when you build GRUB core. Instead it is included when you build GRUB utils. Huh! AFAICT this means the gnulib is deprived of all its specific constants. I am not sure how it worked at all in so far. Anyway, I think we have to fix it properly.

Robbie, may I ask you to talk to gnulib folks and ask them how we should solve this problem? Please CC all folks CC-ed in this email.

Daniel

#6 lore raw
Quoted 11 lines · Daniel Kiper

CC-ing Daren, Patrick and Vladimir...

When I started looking at this issue I realized we have bigger problem here than lack of _GL_ATTRIBUTE_CONST definition. In general all _GL_* constants land in config-util.h.in and finally in config-util.h. It does not make a lot of sense because config-util.h is not included when you build GRUB core. Instead it is included when you build GRUB utils. Huh! AFAICT this means the gnulib is deprived of all its specific constants. I am not sure how it worked at all in so far. Anyway, I think we have to fix it properly.

Quoted 2 lines

Robbie, may I ask you to talk to gnulib folks and ask them how we should solve this problem? Please CC all folks CC-ed in this email.

I'm not opposed to getting gnulib's opinion, but don't we already know what they suggest from
https://lists.gnu.org/archive/html/bug-gnulib/2021-11/msg00009.html
(i.e., run configure twice)?

(Though if other folks on CC want to provide more input on
https://lists.gnu.org/archive/html/bug-gnulib/2021-11/msg00028.html that would be helpful.)

Be well,
--Robbie

#7 lore raw
Quoted 13 lines · Robbie Harwood
Quoted 11 lines · Daniel Kiper

CC-ing Daren, Patrick and Vladimir...

When I started looking at this issue I realized we have bigger problem here than lack of _GL_ATTRIBUTE_CONST definition. In general all _GL_* constants land in config-util.h.in and finally in config-util.h. It does not make a lot of sense because config-util.h is not included when you build GRUB core. Instead it is included when you build GRUB utils. Huh! AFAICT this means the gnulib is deprived of all its specific constants. I am not sure how it worked at all in so far. Anyway, I think we have to fix it properly.

Quoted 7 lines
Quoted 2 lines

Robbie, may I ask you to talk to gnulib folks and ask them how we should solve this problem? Please CC all folks CC-ed in this email.

I'm not opposed to getting gnulib's opinion, but don't we already know what they suggest from
https://lists.gnu.org/archive/html/bug-gnulib/2021-11/msg00009.html
(i.e., run configure twice)?

Yeah, but I think it would require major overhaul. Does not it? If yes then maybe we should consider move to the Kconfig or something like that.

Quoted 3 lines

(Though if other folks on CC want to provide more input on
https://lists.gnu.org/archive/html/bug-gnulib/2021-11/msg00028.html that would be helpful.)

Yeah, that would be perfect.

Daniel

#8 lore raw
Quoted 3 lines · Daniel Kiper

Yeah, but I think it would require major overhaul. Does not it? If yes then maybe we should consider move to the Kconfig or something like that.

Perhaps, but please don't mistake me as volunteering for build system hacking - I'm mostly just here to upstream patches :)

In the end, I submit that you as the upstream maintainer have should something you can work with and solve problems in. If what's there isn't that, then something needs to change in order for things to get better - and maybe a major overhaul would be worth it.

Be well,
--Robbie

#9 lore raw
Quoted 7 lines · Robbie Harwood
Quoted 3 lines · Daniel Kiper

Yeah, but I think it would require major overhaul. Does not it? If yes then maybe we should consider move to the Kconfig or something like that.

Perhaps, but please don't mistake me as volunteering for build system

I do not... I am not sure how you inferred I do.

Quoted 1 line

hacking - I'm mostly just here to upstream patches :)

Cool! I have just asked you to investigate how to improve your patch. Currently I am not happy with it. I still hope you will send me some proposals (I do not expect patches immediately; if you prefer just tell me how do you want to fix the issue in better way). If I get them then we can continue discussion...

Daniel

#10 lore raw
Quoted 11 lines · Daniel Kiper
Quoted 7 lines · Robbie Harwood
Quoted 3 lines · Daniel Kiper

Yeah, but I think it would require major overhaul. Does not it? If yes then maybe we should consider move to the Kconfig or something like that.

Perhaps, but please don't mistake me as volunteering for build system

I do not... I am not sure how you inferred I do.

Quoted 7 lines
Quoted 1 line

hacking - I'm mostly just here to upstream patches :)

Cool! I have just asked you to investigate how to improve your patch. Currently I am not happy with it. I still hope you will send me some proposals (I do not expect patches immediately; if you prefer just tell me how do you want to fix the issue in better way). If I get them then we can continue discussion...

Sorry, I think I missed this - what are you unhappy about with this patch?

Be well,
--Robbie

#11 lore raw
Quoted 14 lines · Robbie Harwood
Quoted 13 lines · Daniel Kiper
Quoted 7 lines · Robbie Harwood
Quoted 3 lines · Daniel Kiper

Yeah, but I think it would require major overhaul. Does not it? If yes then maybe we should consider move to the Kconfig or something like that.

Perhaps, but please don't mistake me as volunteering for build system

I do not... I am not sure how you inferred I do.

Quoted 1 line

hacking - I'm mostly just here to upstream patches :)

Quoted 8 lines
Quoted 5 lines

Cool! I have just asked you to investigate how to improve your patch. Currently I am not happy with it. I still hope you will send me some proposals (I do not expect patches immediately; if you prefer just tell me how do you want to fix the issue in better way). If I get them then we can continue discussion...

Sorry, I think I missed this - what are you unhappy about with this patch?

It tries to fix one specific issue and do not address other problems which we have with the gnulib _GL_* constants. I would prefer to fix them at once now. I hope this should not be difficult. In the worst case we can copy _GL_* constants to config.h.in from config-util.h.in. Though I would prefer to avoid this manual work if we are able to find quite simple solution doing this automatically.

Daniel