Skip to contentSkip to conversation

build: Fixes for memory-debugging builds

PATCH In review Patrick Steinhardt 3 participants 10 messages Mar 7, 2020 – Mar 9, 2020

lore
Share & tools
lore
#0 lore raw

cover build: Fixes for memory-debugging builds

Hi,

this series fixes two issues I've found after investigating the build failures for LUKS2:

- Including <config-util.h> in base64.h is the wrong thing to do as it's also used in the luks2 module, which shouldn't include the util header at all.

- Ironically, explicitly disabling memory debugging enables memory debugging while it would've been disabled if just passing no option at all.

These patches fix both issues so that GRUB now builds correctly with and without memory debugging on my system.

Patrick

Patrick Steinhardt (2):
build: Fix option to explicitly disable memory debugging
gnulib: Fix build of base64 when compiling with memory debugging

 configure.ac                                  |  8 +++++---
 grub-core/lib/gnulib-patches/fix-base64.patch | 14 ++++++--------
 2 files changed, 11 insertions(+), 11 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 build: Fix option to explicitly disable memory debugging

The memory management system supports a debug mode that can be enabled at build time by passing "--enable-mm-debug" to the configure script. Passing the option will cause us define MM_DEBUG as expected, but in fact the reverse option "--disable-mm-deubg" will do the exact same thing and also set up the define. This currently causes the build of "lib/gnulib/base64.c" to fail as it tries to use grub_debug_malloc() and grub_debug_free() even though both symbols aren't defined.

Seemingly, AC_ARG_ENABLE() will always execute the third argument if either the positive or negative option was passed. Let's thus fix the issue by moving the call toAC_DEFINE() into an explicit if test $xenable_mm_debug block, similar to how other defines work.

---
 configure.ac | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
configure.ac +5 -3
index f19489418..9eeec2d76 100644
@@ -1448,9 +1448,11 @@ LIBS="$tmp_LIBS"
 # Memory manager debugging.
 AC_ARG_ENABLE([mm-debug],
 	      AS_HELP_STRING([--enable-mm-debug],
-                             [include memory manager debugging]),
-              [AC_DEFINE([MM_DEBUG], [1],
-                         [Define to 1 if you enable memory manager debugging.])])
+                             [include memory manager debugging]))
+if test x$enable_mm_debug = xyes; then
+    AC_DEFINE([MM_DEBUG], [1],
+            [Define to 1 if you enable memory manager debugging.])
+fi
 
 AC_ARG_ENABLE([cache-stats],
 	      AS_HELP_STRING([--enable-cache-stats],
Signature · 1 line
2.25.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] build: Fix option to explicitly disable memory debugging

Quoted 8 lines · Patrick Steinhardt

The memory management system supports a debug mode that can be enabled at build time by passing "--enable-mm-debug" to the configure script. Passing the option will cause us define MM_DEBUG as expected, but in fact the reverse option "--disable-mm-deubg" will do the exact same thing and also set up the define. This currently causes the build of "lib/gnulib/base64.c" to fail as it tries to use grub_debug_malloc() and grub_debug_free() even though both symbols aren't defined.

Quoted 6 lines

Seemingly, AC_ARG_ENABLE() will always execute the third argument if either the positive or negative option was passed. Let's thus fix the issue by moving the call toAC_DEFINE() into an explicit if test $xenable_mm_debug block, similar to how other defines work.

Daniel

Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] build: Fix option to explicitly disable memory debugging

In reply to Patrick Steinhardt

Dear Patrick,

Quoted 4 lines · Patrick Steinhardt

The memory management system supports a debug mode that can be enabled at build time by passing "--enable-mm-debug" to the configure script. Passing the option will cause us define MM_DEBUG as expected, but in fact the reverse option "--disable-mm-deubg" will do the exact same

s/deubg/debug/

Quoted 23 lines

thing and also set up the define. This currently causes the build of "lib/gnulib/base64.c" to fail as it tries to use grub_debug_malloc() and grub_debug_free() even though both symbols aren't defined.

Seemingly, AC_ARG_ENABLE() will always execute the third argument if either the positive or negative option was passed. Let's thus fix the issue by moving the call toAC_DEFINE() into an explicit if test $xenable_mm_debug block, similar to how other defines work.

---
 configure.ac | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
configure.ac +0 -1
index f19489418..9eeec2d76 100644
@@ -1448,9 +1448,11 @@ LIBS="$tmp_LIBS"
 # Memory manager debugging.
 AC_ARG_ENABLE([mm-debug],
 	      AS_HELP_STRING([--enable-mm-debug],
-                             [include memory manager debugging]),

configure.ac LIBS="$tmp_LIBS" · line 1458

Quoted 10 lines
configure.ac +5 -2
-              [AC_DEFINE([MM_DEBUG], [1],
-                         [Define to 1 if you enable memory manager debugging.])])
+                             [include memory manager debugging]))
+if test x$enable_mm_debug = xyes; then
+    AC_DEFINE([MM_DEBUG], [1],
+            [Define to 1 if you enable memory manager debugging.])
+fi
 
 AC_ARG_ENABLE([cache-stats],
 	      AS_HELP_STRING([--enable-cache-stats],

Kind regards,

Paul

#4 lore raw

Re: [PATCH 1/2] build: Fix option to explicitly disable memory debugging

Quoted 10 lines · Paul Menzel

Dear Patrick,

Quoted 4 lines · Patrick Steinhardt

The memory management system supports a debug mode that can be enabled at build time by passing "--enable-mm-debug" to the configure script. Passing the option will cause us define MM_DEBUG as expected, but in fact the reverse option "--disable-mm-deubg" will do the exact same

s/deubg/debug/

Thanks for pointing this out! Daniel, you want me to send out a v2 of this to fix the typo or will you fix it up locally?

Patrick

#5 lore raw

Re: [PATCH 1/2] build: Fix option to explicitly disable memory debugging

Quoted 9 lines · Patrick Steinhardt
Quoted 8 lines · Paul Menzel

Dear Patrick,

Quoted 4 lines · Patrick Steinhardt

The memory management system supports a debug mode that can be enabled at build time by passing "--enable-mm-debug" to the configure script. Passing the option will cause us define MM_DEBUG as expected, but in fact the reverse option "--disable-mm-deubg" will do the exact same

Quoted 4 lines
Quoted 1 line

s/deubg/debug/

Thanks for pointing this out! Daniel, you want me to send out a v2 of this to fix the typo or will you fix it up locally?

I will fix it locally...

Daniel

#6 lore raw

PATCH 2/2 gnulib: Fix build of base64 when compiling with memory debugging

In reply to Patrick Steinhardt

When building GRUB with memory management debugging enabled, then the build fails because of grub_debug_malloc() and grub_debug_free() being undefined in the luks2 module. The cause is that we patch "base64.h" to unconditionaly include "config-util.h", which shouldn't be included for modules at all. As a result, MM_DEBUG is defined when building the module, causing it to use the debug memory allocation functions. As these are not built into modules, we end up with a linker error.

Fix the issue by removing the <config-util.h> include altogether. The sole reason it was included was for the _GL_ATTRIBUTE_CONST macro, which we can simply define as empty in case it's not set.

---
 grub-core/lib/gnulib-patches/fix-base64.patch | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
grub-core/lib/gnulib-patches/fix-base64.patch +6 -8
index e075b6fab..985db1279 100644
@@ -1,14 +1,8 @@
 diff --git a/lib/base64.h b/lib/base64.h
-index 9cd0183b8..a2aaa2d4a 100644
+index 9cd0183b8..185a2afa1 100644
 --- a/lib/base64.h
 +++ b/lib/base64.h
-@@ -18,11 +18,16 @@
- #ifndef BASE64_H
- # define BASE64_H
- 
-+/* Get _GL_ATTRIBUTE_CONST */
-+# include <config-util.h>
-+
+@@ -21,8 +21,14 @@
  /* Get size_t. */
  # include <stddef.h>
  
@@ -17,6 +11,10 @@ index 9cd0183b8..a2aaa2d4a 100644
 +#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
Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH 2/2] gnulib: Fix build of base64 when compiling with memory debugging

Quoted 23 lines · Patrick Steinhardt

When building GRUB with memory management debugging enabled, then the build fails because of grub_debug_malloc() and grub_debug_free() being undefined in the luks2 module. The cause is that we patch "base64.h" to unconditionaly include "config-util.h", which shouldn't be included for modules at all. As a result, MM_DEBUG is defined when building the module, causing it to use the debug memory allocation functions. As these are not built into modules, we end up with a linker error.

Fix the issue by removing the <config-util.h> include altogether. The sole reason it was included was for the _GL_ATTRIBUTE_CONST macro, which we can simply define as empty in case it's not set.

---
 grub-core/lib/gnulib-patches/fix-base64.patch | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
grub-core/lib/gnulib-patches/fix-base64.patch +0 -0
index e075b6fab..985db1279 100644

grub-core/lib/gnulib-patches/fix-base64.patch line 7

Quoted 8 lines
grub-core/lib/gnulib-patches/fix-base64.patch +1 -4
@@ -1,14 +1,8 @@
 diff --git a/lib/base64.h b/lib/base64.h
-index 9cd0183b8..a2aaa2d4a 100644
+index 9cd0183b8..185a2afa1 100644
 --- a/lib/base64.h
 +++ b/lib/base64.h
-@@ -18,11 +18,16 @@
- #ifndef BASE64_H
- # define BASE64_H

Hmmm... It seems to me that you should not drop this...

Quoted 20 lines
grub-core/lib/gnulib-patches/fix-base64.patch +5 -5
-
-+/* Get _GL_ATTRIBUTE_CONST */
-+# include <config-util.h>
-+
+@@ -21,8 +21,14 @@
  /* Get size_t. */
  # include <stddef.h>
 
@@ -17,6 +11,10 @@ index 9cd0183b8..a2aaa2d4a 100644
 +#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
--
Quoted 1 line

2.25.1

Daniel

#8 lore raw

Re: [PATCH 2/2] gnulib: Fix build of base64 when compiling with memory debugging

Quoted 19 lines · Daniel Kiper
Quoted 18 lines · Patrick Steinhardt

When building GRUB with memory management debugging enabled, then the build fails because of grub_debug_malloc() and grub_debug_free() being undefined in the luks2 module. The cause is that we patch "base64.h" to unconditionaly include "config-util.h", which shouldn't be included for modules at all. As a result, MM_DEBUG is defined when building the module, causing it to use the debug memory allocation functions. As these are not built into modules, we end up with a linker error.

Fix the issue by removing the <config-util.h> include altogether. The sole reason it was included was for the _GL_ATTRIBUTE_CONST macro, which we can simply define as empty in case it's not set.

---
 grub-core/lib/gnulib-patches/fix-base64.patch | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
Quoted 15 lines

grub-core/lib/gnulib-patches/fix-base64.patch line 7

Quoted 13 lines
grub-core/lib/gnulib-patches/fix-base64.patch +1 -4
index e075b6fab..985db1279 100644
@@ -1,14 +1,8 @@
 diff --git a/lib/base64.h b/lib/base64.h
-index 9cd0183b8..a2aaa2d4a 100644
+index 9cd0183b8..185a2afa1 100644
 --- a/lib/base64.h
 +++ b/lib/base64.h
-@@ -18,11 +18,16 @@
- #ifndef BASE64_H
- # define BASE64_H

Hmmm... It seems to me that you should not drop this...

Note that this is a diff of a patch. So all that's getting dropped is the patch that added the #include. So after applying this, "base64.h" doesn't get touched by fix-base64.patch at all anymore.

Patrick

Reviewed-by
#9 lore raw

Re: [PATCH 2/2] gnulib: Fix build of base64 when compiling with memory debugging

Quoted 36 lines · Patrick Steinhardt
Quoted 19 lines · Daniel Kiper
Quoted 18 lines · Patrick Steinhardt

When building GRUB with memory management debugging enabled, then the build fails because of grub_debug_malloc() and grub_debug_free() being undefined in the luks2 module. The cause is that we patch "base64.h" to unconditionaly include "config-util.h", which shouldn't be included for modules at all. As a result, MM_DEBUG is defined when building the module, causing it to use the debug memory allocation functions. As these are not built into modules, we end up with a linker error.

Fix the issue by removing the <config-util.h> include altogether. The sole reason it was included was for the _GL_ATTRIBUTE_CONST macro, which we can simply define as empty in case it's not set.

---
 grub-core/lib/gnulib-patches/fix-base64.patch | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
Quoted 15 lines

grub-core/lib/gnulib-patches/fix-base64.patch line 7

Quoted 13 lines
grub-core/lib/gnulib-patches/fix-base64.patch +1 -4
index e075b6fab..985db1279 100644
@@ -1,14 +1,8 @@
 diff --git a/lib/base64.h b/lib/base64.h
-index 9cd0183b8..a2aaa2d4a 100644
+index 9cd0183b8..185a2afa1 100644
 --- a/lib/base64.h
 +++ b/lib/base64.h
-@@ -18,11 +18,16 @@
- #ifndef BASE64_H
- # define BASE64_H

Hmmm... It seems to me that you should not drop this...

Quoted 3 lines

Note that this is a diff of a patch. So all that's getting dropped is the patch that added the #include. So after applying this, "base64.h" doesn't get touched by fix-base64.patch at all anymore.

Ahhh... Right, these are reference lines. So, sorry for the confusion...

Daniel