Skip to contentSkip to conversation

Patch for successful compilation on FreeBSD Release-6.1

PATCH Harley D. Eades III 4 participants 10 messages Jun 11, 2006 – Jun 14, 2006

lore
Share & tools
lore
#0 lore raw

Hello,
I managed to work up a small patch for grub2. She makes it possible to build grub2 on FreeBSD Release-6.1. There is one thing I am not sure on. In configure.ac I had to move the lines which restore the compiler flags above the checks for _start etc..see the patch. I would like as much feedback as possible. Thanks. :)

2006-06-10 Harley D. Eades III <[email protected]>

* configure.ac: Check for <malloc.h>. Check for memalign().
* include/grub/util/misc.h: Include <unistd.h>.
* util/grub-emu.c [HAVE_MALLOC_H]: Include <malloc.h>.
* util/misc.c: Likewise.
(grub_memalign) [!HAVE_MEMALIGN]: Don't call memalign, but generate an error instead.

diff --exclude=CVS --exclude=configure --exclude=config.log --exclude=config.h.in -ru grub2/configure.ac grub2Hacked/configure.ac

configure.ac Mon Jun 5 15:50:36 2006 renamed from configure.ac Mon May 29 19:32:29 2006 +4 -0
@@ -122,6 +122,15 @@
 AC_CHECK_SIZEOF(void *)
 AC_CHECK_SIZEOF(long)
 
+# BSD checks. 
+AC_CHECK_HEADER([malloc.h],
+               [AC_DEFINE(HAVE_MALLOC_H, [], 
+               [Define to 1 if you have the malloc.h header file.])],

,)
+
+AC_CHECK_FUNC([memalign],
+ [AC_DEFINE(HAVE_MEMALIGN, [],
+ [Define to 1 if you have the memalign function.])], ,)
+
if test "x$host_m32" = x1; then
# Force 32-bit mode.
CFLAGS="$CFLAGS -m32"
@@ -232,6 +241,12 @@
AC_SUBST(TARGET_CPPFLAGS)
AC_SUBST(TARGET_LDFLAGS)

+# Restore the flags.
+CC="$tmp_CC"
+CFLAGS="$tmp_CFLAGS" +CPPFLAGS="$tmp_CPPFLAGS" +LDFLAGS="$tmp_LDFLAGS"
+
# Defined in aclocal.m4. grub_PROG_OBJCOPY_ABSOLUTE
grub_ASM_USCORE
@@ -246,12 +261,6 @@
else
AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
fi
-
-# Restore the flags.
-CC="$tmp_CC"
-CFLAGS="$tmp_CFLAGS" -CPPFLAGS="$tmp_CPPFLAGS" -LDFLAGS="$tmp_LDFLAGS"

# Check for options.
AC_ARG_ENABLE([mm-debug],
diff --exclude=CVS --exclude=configure --exclude=config.log
--exclude=config.h.in -ru grub2/include/grub/util/misc.h grub2Hacked/include/grub/util/misc.h
--- grub2/include/grub/util/misc.h Mon Feb 14 18:07:01 2005
+++ grub2Hacked/include/grub/util/misc.h Mon Jun 5 15:25:38
2006
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
+#include <unistd.h>

extern char *progname;
extern int verbosity;
diff --exclude=CVS --exclude=configure --exclude=config.log
--exclude=config.h.in -ru grub2/util/grub-emu.c grub2Hacked/util/grub-emu.c

util/grub-emu.c Mon Jun 5 15:26:30 2006 renamed from util/grub-emu.c Wed Apr 26 16:58:36 2006 +4 -0
@@ -18,7 +18,11 @@
  */
 
 #include <stdlib.h>
+
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
+
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>

diff --exclude=CVS --exclude=configure --exclude=config.log --exclude=config.h.in -ru grub2/util/misc.c grub2Hacked/util/misc.c

util/misc.c Mon Jun 5 15:28:12 2006 renamed from util/misc.c Sun Apr 23 08:37:36 2006 +10 -1
@@ -24,7 +24,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif 
+
 #include <unistd.h>
 
 #include <grub/util/misc.h>
@@ -228,8 +232,13 @@
 grub_memalign (grub_size_t align, grub_size_t size)
 {
   void *p;
-  
+
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  grub_util_error ("memalign not available");
+#endif
+  
   if (! p)
     grub_util_error ("out of memory");
 
#1 lore raw
Quoted 5 lines · Harley D. Eades III

Hello, I managed to work up a small patch for grub2. She makes it possible to build grub2 on FreeBSD Release-6.1. There is one thing I am not sure on. In configure.ac I had to move the lines which restore the compiler flags above the checks for _start etc..see the patch. I would like as much feedback as possible. Thanks. :)

The problem with the compiler flags should have been fixed with this change:

2006-05-31 Jeroen Dekkers <[email protected]>

* configure.ac: Don't set host_m32 for x86_64. Also reset LIBS for the target-specific tests. Make sure that we also have the up-to-date target variables for those tests.

If I read your patch correctly you haven't updated to recent CVS yet. Can you try whether this fix also works for you?

Jeroen Dekkers

#2 lore raw
Quoted 12 lines · Jeroen Dekkers
Quoted 5 lines · Harley D. Eades III

Hello, I managed to work up a small patch for grub2. She makes it possible to build grub2 on FreeBSD Release-6.1. There is one thing I am not sure on. In configure.ac I had to move the lines which restore the compiler flags above the checks for _start etc..see the patch. I would like as much feedback as possible. Thanks. :)

The problem with the compiler flags should have been fixed with this change:

2006-05-31 Jeroen Dekkers <[email protected]>

Quoted 8 lines

* configure.ac: Don't set host_m32 for x86_64. Also reset LIBS for the target-specific tests. Make sure that we also have the up-to-date target variables for those tests.

If I read your patch correctly you haven't updated to recent CVS yet. Can you try whether this fix also works for you?

Sure thing. :) Thanks for the reply.

Cheers
Harley

#3 lore raw
Quoted 19 lines · [email protected] (Harley D. Eades III) writes:
Quoted 17 lines · Jeroen Dekkers
Quoted 5 lines · Harley D. Eades III

Hello, I managed to work up a small patch for grub2. She makes it possible to build grub2 on FreeBSD Release-6.1. There is one thing I am not sure on. In configure.ac I had to move the lines which restore the compiler flags above the checks for _start etc..see the patch. I would like as much feedback as possible. Thanks. :)

The problem with the compiler flags should have been fixed with this change:

2006-05-31 Jeroen Dekkers <[email protected]>

* configure.ac: Don't set host_m32 for x86_64. Also reset LIBS for the target-specific tests. Make sure that we also have the up-to-date target variables for those tests.

Quoted 4 lines
Quoted 3 lines

If I read your patch correctly you haven't updated to recent CVS yet. Can you try whether this fix also works for you?

Sure thing. :) Thanks for the reply.

Your patch does fix that issue. Here is my updated patch. :)

Cheers
Harley

diff --exclude=CVS --exclude=configure --exclude=config.log --exclude=config.h.in -ru grub2/ChangeLog grub2Hacked/ChangeLog

ChangeLog Mon Jun 12 10:25:28 2006 renamed from ChangeLog Mon Jun 12 10:11:10 2006 +9 -0
@@ -1,3 +1,12 @@
+2006-06-10  Harley D. Eades III  <[email protected]>
+
+        * configure.ac: Check for <malloc.h>.  Check for memalign().
+        * include/grub/util/misc.h: Include <unistd.h>.
+        * util/grub-emu.c [HAVE_MALLOC_H]: Include <malloc.h>.
+        * util/misc.c: Likewise.
+        (grub_memalign) [!HAVE_MEMALIGN]: Don't call memalign, but
+        generate an error instead.
+
 2006-06-09  Yoshinori K. Okuji  <[email protected]>
 
        * loader/i386/pc/linux.c (grub_rescue_cmd_initrd): Make sure

that
@@ -335,7 +344,6 @@
for the target-specific tests. Make sure that we also have the up-to-date target variables for those tests.

->>>>>>> 1.283
2006-05-31 Yoshinori K. Okuji <[email protected]>

* genmk.rb (Image::rule): Prefix CFLAGS or ASFLAGS with TARGET_.
diff --exclude=CVS --exclude=configure --exclude=config.log
--exclude=config.h.in -ru grub2/configure.ac grub2Hacked/configure.ac

configure.ac Sun Jun 11 17:55:34 2006 renamed from configure.ac Sun Jun 11 17:49:23 2006 +4 -0
@@ -121,6 +121,15 @@
 AC_CHECK_SIZEOF(void *)
 AC_CHECK_SIZEOF(long)
 
+# BSD checks. 
+AC_CHECK_HEADER([malloc.h],
+               [AC_DEFINE(HAVE_MALLOC_H, [], 
+               [Define to 1 if you have the malloc.h header file.])],

,)
+
+AC_CHECK_FUNC([memalign],
+ [AC_DEFINE(HAVE_MEMALIGN, [],
+ [Define to 1 if you have the memalign function.])], ,)
+
if test "x$host_m32" = x1; then
# Force 32-bit mode.
CFLAGS="$CFLAGS -m32"
diff --exclude=CVS --exclude=configure --exclude=config.log --exclude=config.h.in -ru grub2/include/grub/util/misc.h grub2Hacked/include/grub/util/misc.h
--- grub2/include/grub/util/misc.h Mon Feb 14 18:07:01 2005
+++ grub2Hacked/include/grub/util/misc.h Mon Jun 5 15:25:38
2006
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
+#include <unistd.h>

extern char *progname;
extern int verbosity;
diff --exclude=CVS --exclude=configure --exclude=config.log
--exclude=config.h.in -ru grub2/util/grub-emu.c grub2Hacked/util/grub-emu.c

util/grub-emu.c Mon Jun 5 15:26:30 2006 renamed from util/grub-emu.c Wed Apr 26 16:58:36 2006 +4 -0
@@ -18,7 +18,11 @@
  */
 
 #include <stdlib.h>
+
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
+
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>

diff --exclude=CVS --exclude=configure --exclude=config.log --exclude=config.h.in -ru grub2/util/misc.c grub2Hacked/util/misc.c

util/misc.c Mon Jun 5 15:28:12 2006 renamed from util/misc.c Sun Apr 23 08:37:36 2006 +10 -1
@@ -24,7 +24,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif 
+
 #include <unistd.h>
 
 #include <grub/util/misc.h>
@@ -228,8 +232,13 @@
 grub_memalign (grub_size_t align, grub_size_t size)
 {
   void *p;
-  
+
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  grub_util_error ("memalign not available");
+#endif
+  
   if (! p)
     grub_util_error ("out of memory");
 
#4 lore raw
Quoted 21 lines · [email protected] (Harley D. Eades III) writes:
Quoted 19 lines · [email protected] (Harley D. Eades III) writes:
Quoted 17 lines · Jeroen Dekkers
Quoted 5 lines · Harley D. Eades III

Hello, I managed to work up a small patch for grub2. She makes it possible to build grub2 on FreeBSD Release-6.1. There is one thing I am not sure on. In configure.ac I had to move the lines which restore the compiler flags above the checks for _start etc..see the patch. I would like as much feedback as possible. Thanks. :)

The problem with the compiler flags should have been fixed with this change:

2006-05-31 Jeroen Dekkers <[email protected]>

* configure.ac: Don't set host_m32 for x86_64. Also reset LIBS for the target-specific tests. Make sure that we also have the up-to-date target variables for those tests.

Quoted 5 lines
Quoted 4 lines
Quoted 3 lines

If I read your patch correctly you haven't updated to recent CVS yet. Can you try whether this fix also works for you?

Sure thing. :) Thanks for the reply.

Your patch does fix that issue. Here is my updated patch. :)

Looks fine to me. Hopefully an autoconf expert can check again to be sure. If I don't hear any complaints within the week, I will commit this patch.

--
Marco

#5 lore raw
In reply to Harley D. Eades III

configure.ac Sun Jun 11 17:55:34 2006 line 129

Quoted 12 lines · Harley D. Eades III
configure.ac Sun Jun 11 17:55:34 2006 renamed from configure.ac Sun Jun 11 17:49:23 2006 +5 -0
@@ -121,6 +121,15 @@
 AC_CHECK_SIZEOF(void *)
 AC_CHECK_SIZEOF(long)
 
+# BSD checks.
+AC_CHECK_HEADER([malloc.h],
+               [AC_DEFINE(HAVE_MALLOC_H, [],
+               [Define to 1 if you have the malloc.h header file.])],
 ,)
+

Please use AC_CHECK_HEADERS instead. Usually, you don't have to use AC_CHECK_HEADER. See the autoconf manual for more details.

configure.ac Sun Jun 11 17:55:34 2006 line 133

Quoted 4 lines
configure.ac Sun Jun 11 17:55:34 2006 renamed from configure.ac Sun Jun 11 17:49:23 2006 +4 -0
+AC_CHECK_FUNC([memalign],
+             [AC_DEFINE(HAVE_MEMALIGN, [],
+             [Define to 1 if you have the memalign function.])], ,)
+

Likewise, please use AC_CHECK_FUNCS instead.

include/grub/util/misc.h Mon Jun 5 15:25:38 line 26

Quoted 8 lines
include/grub/util/misc.h Mon Jun 5 15:25:38 renamed from include/grub/util/misc.h Mon Feb 14 18:07:01 2005 +0 -0

2006

include/grub/util/misc.h Mon Jun 5 15:25:38 renamed from include/grub/util/misc.h Mon Feb 14 18:07:01 2005 +1 -0
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <setjmp.h>
+#include <unistd.h>

Can you tell me why it is necessary to include unistd.h here?

util/grub-emu.c Mon Jun 5 15:26:30 2006 line 25

Quoted 11 lines
util/grub-emu.c Mon Jun 5 15:26:30 2006 renamed from util/grub-emu.c Wed Apr 26 16:58:36 2006 +4 -0
@@ -18,7 +18,11 @@
  */
 
 #include <stdlib.h>
+
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
+

I don't know why it is necessary to include malloc.h. IIRC, FreeBSD does not use malloc.h since 4.2 or something. In fact, other projects, such as KDE, stop including malloc.h in all platforms. Can you elaborate on this change?

Thanks,
Okuji

#6 lore raw
Quoted 7 lines · Yoshinori K. Okuji
Quoted 6 lines · Harley D. Eades III
configure.ac Sun Jun 11 17:55:34 2006 renamed from configure.ac Sun Jun 11 17:49:23 2006 +0 -0
@@ -121,6 +121,15 @@
 AC_CHECK_SIZEOF(void *)
 AC_CHECK_SIZEOF(long)
 
Quoted 9 lines

configure.ac Sun Jun 11 17:55:34 2006

Quoted 6 lines
configure.ac Sun Jun 11 17:55:34 2006 renamed from configure.ac Sun Jun 11 17:49:23 2006 +5 -0
+# BSD checks.
+AC_CHECK_HEADER([malloc.h],
+               [AC_DEFINE(HAVE_MALLOC_H, [],
+               [Define to 1 if you have the malloc.h header file.])],
 ,)
+

Please use AC_CHECK_HEADERS instead. Usually, you don't have to use AC_CHECK_HEADER. See the autoconf manual for more details.

ok

Quoted 5 lines

configure.ac Sun Jun 11 17:55:34 2006 line 133

Quoted 5 lines
configure.ac Sun Jun 11 17:55:34 2006 renamed from configure.ac Sun Jun 11 17:49:23 2006 +4 -0
+AC_CHECK_FUNC([memalign],
+             [AC_DEFINE(HAVE_MEMALIGN, [],
+             [Define to 1 if you have the memalign function.])], ,)
+

ok

Quoted 12 lines

Likewise, please use AC_CHECK_FUNCS instead.

include/grub/util/misc.h Mon Jun 5 15:25:38 line 26

Quoted 8 lines
include/grub/util/misc.h Mon Jun 5 15:25:38 renamed from include/grub/util/misc.h Mon Feb 14 18:07:01 2005 +0 -0

2006

include/grub/util/misc.h Mon Jun 5 15:25:38 renamed from include/grub/util/misc.h Mon Feb 14 18:07:01 2005 +1 -0
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <setjmp.h>
+#include <unistd.h>

Can you tell me why it is necessary to include unistd.h here?

off_t is defined here on FreeBSD.

Quoted 5 lines
Quoted 5 lines
util/grub-emu.c Mon Jun 5 15:26:30 2006 renamed from util/grub-emu.c Wed Apr 26 16:58:36 2006 +0 -0
@@ -18,7 +18,11 @@
  */
 
Quoted 10 lines

util/grub-emu.c Mon Jun 5 15:26:30 2006 line 25

Quoted 6 lines
util/grub-emu.c Mon Jun 5 15:26:30 2006 renamed from util/grub-emu.c Wed Apr 26 16:58:36 2006 +4 -0
 #include <stdlib.h>
+
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
+

I don't know why it is necessary to include malloc.h. IIRC, FreeBSD does not use malloc.h since 4.2 or something. In fact, other projects, such as KDE, stop including malloc.h in all platforms. Can you elaborate on this change?

I am not adding the include. All I added was the #if statement so this is not included on FreeBSD. So you are correct about the header file not being used on FreeBSD, because it's not. :) IIRC, GNU/Linux does define memalign in malloc.h though, so this could be the reason it has been included already.

Cheers
Harley

#7 lore raw
Quoted 1 line · Harley D. Eades III

off_t is defined here on FreeBSD.

I understand.

Quoted 5 lines

I am not adding the include. All I added was the #if statement so this is not included on FreeBSD. So you are correct about the header file not being used on FreeBSD, because it's not. :) IIRC, GNU/Linux does define memalign in malloc.h though, so this could be the reason it has been included already.

You are right. I've checked in my own fix for this problem. Since recent FreeBSD supports posix_memalign, I think mine is a bit better. Can you confirm that this works on FreeBSD?

BTW, I am afraid that there are some more dependencies on glibc, such as argp. How do you deal with those?

Thanks,
Okuji

#8 lore raw
Quoted 4 lines · Yoshinori K. Okuji
Quoted 1 line · Harley D. Eades III

off_t is defined here on FreeBSD.

I understand.

:)

Quoted 9 lines
Quoted 5 lines

I am not adding the include. All I added was the #if statement so this is not included on FreeBSD. So you are correct about the header file not being used on FreeBSD, because it's not. :) IIRC, GNU/Linux does define memalign in malloc.h though, so this could be the reason it has been included already.

You are right. I've checked in my own fix for this problem. Since recent FreeBSD supports posix_memalign, I think mine is a bit better. Can you confirm that this works on FreeBSD?

Will do, but, I thought posix_memalign is not going to be active until the next release?

This explains my concern (See Release:) :
http://www.freebsd.org/cgi/query-pr.cgi?pr=85090

Quoted 2 lines

BTW, I am afraid that there are some more dependencies on glibc, such as argp. How do you deal with those?

FreeBSD packages libargp, I add it to LDFLAGS. :)

Cheers
Harley

#9 lore raw
Quoted 4 lines · [email protected] (Harley D. Eades III) writes:
Quoted 4 lines

You are right. I've checked in my own fix for this problem. Since recent FreeBSD supports posix_memalign, I think mine is a bit better. Can you confirm that this works on FreeBSD?

Well your fix is better. It all works.