Skip to contentSkip to conversation

RFC: allow compilation without target libc

PATCH In review Pavel Roskin 2 participants 3 messages May 22, 2009 – Jun 5, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RFC: allow compilation without target libc

ChangeLog:

* configure.ac: Define GRUB_SOURCE to identify GRUB sources in include/multiboot2.h. Use "-nostdlib" when testing target compiler.
* include/multiboot2.h: Use GRUB types and definitions. Provide compatibility layer when GRUB_SOURCE is not defined.
* loader/i386/pc/multiboot2.c: Include multiboot2.h last to make sure that config.h was included first.
* loader/multiboot2.c: Likewise.
* loader/multiboot_loader.c: Likewise.
---

 configure.ac                |    3 ++-
 include/multiboot2.h        |   24 +++++++++++++++---------
 loader/i386/pc/multiboot2.c |    2 +-
 loader/multiboot2.c         |    2 +-
 loader/multiboot_loader.c   |    2 +-
 5 files changed, 20 insertions(+), 13 deletions(-)
configure.ac +2 -1
index 98cd841..af60603 100644
@@ -161,6 +161,7 @@ test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
 
 AC_GNU_SOURCE
 AC_SYS_LARGEFILE
+AC_DEFINE([GRUB_SOURCE], [1], [Define when compiling GRUB sources.])
 
 # Identify characteristics of the host architecture.
 AC_C_BIGENDIAN
@@ -366,7 +367,7 @@ AC_SUBST(TARGET_LDFLAGS)
 
 # Set them to their new values for the tests below.
 CC="$TARGET_CC"
-CFLAGS="$TARGET_CFLAGS"
+CFLAGS="$TARGET_CFLAGS -nostdlib"
 CPPFLAGS="$TARGET_CPPFLAGS"
 LDFLAGS="$TARGET_LDFLAGS"
 
include/multiboot2.h +15 -9
index 0f2b0cf..e8fe425 100644
@@ -34,25 +34,31 @@
 
 #ifndef ASM_FILE
 
-#include "stdint.h"
+#ifdef GRUB_SOURCE
+#include <grub/types.h>
+#else
+#include <stdint.h>
+typedef uint32_t grub_uint32_t;
+typedef uint64_t grub_uint64_t;
+#define GRUB_TARGET_SIZEOF_VOID_P (__WORDSIZE / 8)
+#endif
 
-/* XXX not portable? */
-#if __WORDSIZE == 64
-typedef uint64_t multiboot_word;
+#if GRUB_TARGET_SIZEOF_VOID_P == 8
+typedef grub_uint64_t multiboot_word;
 #else
-typedef uint32_t multiboot_word;
+typedef grub_uint32_t multiboot_word;
 #endif
 
 struct multiboot_header
 {
-  uint32_t magic;
-  uint32_t flags;
+  grub_uint32_t magic;
+  grub_uint32_t flags;
 };
 
 struct multiboot_tag_header
 {
-  uint32_t key;
-  uint32_t len;
+  grub_uint32_t key;
+  grub_uint32_t len;
 };
 
 #define MULTIBOOT2_TAG_RESERVED1 0
loader/i386/pc/multiboot2.c +1 -1
index 2c14ee2..25ef150 100644
@@ -17,7 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <multiboot2.h>
 #include <grub/multiboot2.h>
 #include <grub/elf.h>
 #include <grub/err.h>
@@ -25,6 +24,7 @@
 #include <grub/mm.h>
 #include <grub/multiboot.h>
 #include <grub/cpu/multiboot.h>
+#include <multiboot2.h>
 
 grub_err_t
 grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr)
loader/multiboot2.c +1 -1
index fd82828..34e42c1 100644
@@ -17,7 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <multiboot2.h>
 #include <grub/loader.h>
 #include <grub/machine/loader.h>
 #include <grub/multiboot2.h>
@@ -28,6 +27,7 @@
 #include <grub/mm.h>
 #include <grub/misc.h>
 #include <grub/gzio.h>
+#include <multiboot2.h>
 
 static grub_addr_t entry;
 extern grub_dl_t my_mod;
loader/multiboot_loader.c +1 -1
index 11ba666..654508e 100644
@@ -17,7 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <multiboot2.h>
 #include <grub/machine/machine.h>
 #include <grub/multiboot.h>
 #include <grub/multiboot2.h>
@@ -29,6 +28,7 @@
 #include <grub/misc.h>
 #include <grub/gzio.h>
 #include <grub/command.h>
+#include <multiboot2.h>
 
 grub_dl_t my_mod;
 
#1 lore raw

Hello. I like this patch

Quoted 7 lines · Pavel Roskin

ChangeLog:

       * configure.ac: Define GRUB_SOURCE to identify GRUB sources in include/multiboot2.h.  Use "-nostdlib" when testing target compiler.
       * include/multiboot2.h: Use GRUB types and definitions.  Provide compatibility layer when GRUB_SOURCE is not defined.

I'm not sure about this part since multiboot isn't necessarily tied to grub. Perhaps
#ifdef GRUB_SOURCE
typedef grub_uint32_t multiboot_uint32_t;
#else
typedef uint32_t multiboot_uint32_t;
#endif
would make more sense?

Quoted 146 lines

       * loader/i386/pc/multiboot2.c: Include multiboot2.h last to make sure that config.h was included first.
       * loader/multiboot2.c: Likewise.
       * loader/multiboot_loader.c: Likewise.
---

 configure.ac                |    3 ++- include/multiboot2.h        |   24 +++++++++++++++--------- loader/i386/pc/multiboot2.c |    2 +- loader/multiboot2.c         |    2 +- loader/multiboot_loader.c   |    2 +-

 5 files changed, 20 insertions(+), 13 deletions(-)
configure.ac +0 -0
index 98cd841..af60603 100644
@@ -161,6 +161,7 @@ test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
 

 AC_GNU_SOURCE
 AC_SYS_LARGEFILE
+AC_DEFINE([GRUB_SOURCE], [1], [Define when compiling GRUB sources.])

 # Identify characteristics of the host architecture. AC_C_BIGENDIAN

configure.ac +0 -0
@@ -366,7 +367,7 @@ AC_SUBST(TARGET_LDFLAGS)
 
  # Set them to their new values for the tests below.

 CC="$TARGET_CC"

configure.ac +1 -1
-CFLAGS="$TARGET_CFLAGS"
+CFLAGS="$TARGET_CFLAGS -nostdlib"

 CPPFLAGS="$TARGET_CPPFLAGS"
 LDFLAGS="$TARGET_LDFLAGS"

include/multiboot2.h +11 -5
index 0f2b0cf..e8fe425 100644
@@ -34,25 +34,31 @@
 
  #ifndef ASM_FILE
 
-#include "stdint.h"
+#ifdef GRUB_SOURCE
+#include <grub/types.h>
+#else
+#include <stdint.h>
+typedef uint32_t grub_uint32_t;
+typedef uint64_t grub_uint64_t;
+#define GRUB_TARGET_SIZEOF_VOID_P (__WORDSIZE / 8)
+#endif
 
-/* XXX not portable? */
-#if __WORDSIZE == 64
-typedef uint64_t multiboot_word;
+#if GRUB_TARGET_SIZEOF_VOID_P == 8
+typedef grub_uint64_t multiboot_word;
  #else
-typedef uint32_t multiboot_word;
+typedef grub_uint32_t multiboot_word;
  #endif
 

 struct multiboot_header
 {
-  uint32_t magic;
-  uint32_t flags;
+  grub_uint32_t magic;
+  grub_uint32_t flags;
 };

 struct multiboot_tag_header
 {
-  uint32_t key;
-  uint32_t len;
+  grub_uint32_t key;
+  grub_uint32_t len;
 };

 #define MULTIBOOT2_TAG_RESERVED1 0

loader/i386/pc/multiboot2.c +1 -1
index 2c14ee2..25ef150 100644
@@ -17,7 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <multiboot2.h>
  #include <grub/multiboot2.h>
  #include <grub/elf.h>
  #include <grub/err.h>
@@ -25,6 +24,7 @@
  #include <grub/mm.h>
  #include <grub/multiboot.h>
  #include <grub/cpu/multiboot.h>
+#include <multiboot2.h>
 

 grub_err_t
 grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr)

loader/multiboot2.c +1 -1
index fd82828..34e42c1 100644
@@ -17,7 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <multiboot2.h>
  #include <grub/loader.h>
  #include <grub/machine/loader.h>
  #include <grub/multiboot2.h>
@@ -28,6 +27,7 @@
  #include <grub/mm.h>
  #include <grub/misc.h>
  #include <grub/gzio.h>
+#include <multiboot2.h>
 
  static grub_addr_t entry;
  extern grub_dl_t my_mod;
loader/multiboot_loader.c +1 -1
index 11ba666..654508e 100644
@@ -17,7 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <multiboot2.h>
  #include <grub/machine/machine.h>
  #include <grub/multiboot.h>
  #include <grub/multiboot2.h>
@@ -29,6 +28,7 @@
  #include <grub/misc.h>
  #include <grub/gzio.h>
  #include <grub/command.h>
+#include <multiboot2.h>
 
  grub_dl_t my_mod;
 

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#2 lore raw
In reply to Pavel Roskin

This patch greatly simplifies compiling on freebsd-amd64 and possibly other systems. Would be nice to get in into mainstream fastly. Concern about multiboot2.h however remains

Quoted 153 lines · Pavel Roskin

ChangeLog:

       * configure.ac: Define GRUB_SOURCE to identify GRUB sources in include/multiboot2.h.  Use "-nostdlib" when testing target compiler.
       * include/multiboot2.h: Use GRUB types and definitions.  Provide compatibility layer when GRUB_SOURCE is not defined.
       * loader/i386/pc/multiboot2.c: Include multiboot2.h last to make sure that config.h was included first.
       * loader/multiboot2.c: Likewise.
       * loader/multiboot_loader.c: Likewise.
---

 configure.ac                |    3 ++- include/multiboot2.h        |   24 +++++++++++++++--------- loader/i386/pc/multiboot2.c |    2 +- loader/multiboot2.c         |    2 +- loader/multiboot_loader.c   |    2 +-

 5 files changed, 20 insertions(+), 13 deletions(-)
configure.ac +0 -0
index 98cd841..af60603 100644
@@ -161,6 +161,7 @@ test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
 

 AC_GNU_SOURCE
 AC_SYS_LARGEFILE
+AC_DEFINE([GRUB_SOURCE], [1], [Define when compiling GRUB sources.])

 # Identify characteristics of the host architecture. AC_C_BIGENDIAN

configure.ac +0 -0
@@ -366,7 +367,7 @@ AC_SUBST(TARGET_LDFLAGS)
 
  # Set them to their new values for the tests below.

 CC="$TARGET_CC"

configure.ac +1 -1
-CFLAGS="$TARGET_CFLAGS"
+CFLAGS="$TARGET_CFLAGS -nostdlib"

 CPPFLAGS="$TARGET_CPPFLAGS"
 LDFLAGS="$TARGET_LDFLAGS"

include/multiboot2.h +11 -5
index 0f2b0cf..e8fe425 100644
@@ -34,25 +34,31 @@
 
  #ifndef ASM_FILE
 
-#include "stdint.h"
+#ifdef GRUB_SOURCE
+#include <grub/types.h>
+#else
+#include <stdint.h>
+typedef uint32_t grub_uint32_t;
+typedef uint64_t grub_uint64_t;
+#define GRUB_TARGET_SIZEOF_VOID_P (__WORDSIZE / 8)
+#endif
 
-/* XXX not portable? */
-#if __WORDSIZE == 64
-typedef uint64_t multiboot_word;
+#if GRUB_TARGET_SIZEOF_VOID_P == 8
+typedef grub_uint64_t multiboot_word;
  #else
-typedef uint32_t multiboot_word;
+typedef grub_uint32_t multiboot_word;
  #endif
 

 struct multiboot_header
 {
-  uint32_t magic;
-  uint32_t flags;
+  grub_uint32_t magic;
+  grub_uint32_t flags;
 };

 struct multiboot_tag_header
 {
-  uint32_t key;
-  uint32_t len;
+  grub_uint32_t key;
+  grub_uint32_t len;
 };

 #define MULTIBOOT2_TAG_RESERVED1 0

loader/i386/pc/multiboot2.c +1 -1
index 2c14ee2..25ef150 100644
@@ -17,7 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <multiboot2.h>
  #include <grub/multiboot2.h>
  #include <grub/elf.h>
  #include <grub/err.h>
@@ -25,6 +24,7 @@
  #include <grub/mm.h>
  #include <grub/multiboot.h>
  #include <grub/cpu/multiboot.h>
+#include <multiboot2.h>
 

 grub_err_t
 grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr)

loader/multiboot2.c +1 -1
index fd82828..34e42c1 100644
@@ -17,7 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <multiboot2.h>
  #include <grub/loader.h>
  #include <grub/machine/loader.h>
  #include <grub/multiboot2.h>
@@ -28,6 +27,7 @@
  #include <grub/mm.h>
  #include <grub/misc.h>
  #include <grub/gzio.h>
+#include <multiboot2.h>
 
  static grub_addr_t entry;
  extern grub_dl_t my_mod;
loader/multiboot_loader.c +1 -1
index 11ba666..654508e 100644
@@ -17,7 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <multiboot2.h>
  #include <grub/machine/machine.h>
  #include <grub/multiboot.h>
  #include <grub/multiboot2.h>
@@ -29,6 +28,7 @@
  #include <grub/misc.h>
  #include <grub/gzio.h>
  #include <grub/command.h>
+#include <multiboot2.h>
 
  grub_dl_t my_mod;
 

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko