Skip to contentSkip to conversation

Warning free build achieved, coreboot documentation updated

DISCUSSION Pavel Roskin 3 participants 4 messages Jun 17, 2009 – Jun 22, 2009

lore
Share & tools
lore
#0 lore raw

Hello!

I have fixed the remaining warnings in the coreboot build, so now GRUB builds without warnings for all 7 supported platforms in the default configuration. Let's keep it this way.

I was unable to compile coreboot-v3, but I succeeded at compiling coreboot-v2 for qemu. It's not trivial, so I had to make a script. The script has been posted on http://grub.enbug.org/CoreBoot

Signature · 2 lines
Regards,
Pavel Roskin
#1 lore raw
Quoted 6 lines · Pavel Roskin

Hello!

I have fixed the remaining warnings in the coreboot build, so now GRUB builds without warnings for all 7 supported platforms in the default configuration. Let's keep it this way.

There are still warnings if you compile under FreeBSD. Attached patch fixes all of them except one
The remaining is
util/hostdisk.c:1061: comparison between signed and unsigned The problem comes from the following declaration

# define GRUB_LONG_MIN -2147483648UL
As you see we declare a negative number with UL. This works correctly on
i386 but what about other architectures? Can this warning be just silenced
with a cast or do we have a real problem here?
Index: util/hostdisk.c
===================================================================
--- util/hostdisk.c    (revision 2340)
+++ util/hostdisk.c    (working copy)
@@ -344,7 +344,7 @@
 #else /* ! __linux__ */
 #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
   int sysctl_flags, sysctl_oldflags;
-  const size_t sysctl_size = sizeof (sysctl_flags);
+  size_t sysctl_size = sizeof (sysctl_flags);

if (sysctlbyname ("kern.geom.debugflags", &sysctl_oldflags, &sysctl_size,
NULL, 0))

     {

@@ -833,6 +833,7 @@
#endif
}

+#if defined(__linux__) || defined(__CYGWIN__)
static int
device_is_wholedisk (const char *os_dev)
{
@@ -842,6 +843,7 @@

     return 1;

return 0;
}
+#endif

static int
find_system_device (const char *os_dev)
@@ -1045,7 +1047,7 @@

     if (strncmp ("/dev/", os_dev, 5) == 0)
       {
-        char *p, *q;
+        const char *p, *q;
         long int n;

         for (p = os_dev + 5; *p; ++p)
@@ -1055,7 +1057,7 @@
               if (p)
                 {
                   p++;
-                  n = strtol (p, &q, 10);
+                  n = strtol (p, (char **) &q, 10);
                   if (p != q && n != GRUB_LONG_MIN && n != GRUB_LONG_MAX)
                     {
                       dos_part = (int) n - 1;
Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#2 lore raw
Quoted 7 lines · Vladimir 'phcoder' Serbinenko

The remaining is
util/hostdisk.c:1061: comparison between signed and unsigned The problem comes from the following declaration

# define GRUB_LONG_MIN -2147483648UL
As you see we declare a negative number with UL. This works correctly on
i386 but what about other architectures? Can this warning be just silenced
with a cast or do we have a real problem here?

it is portable since C standard defines unsigned numbers to have modular arithmetic. However it therefore can't be silenced with a cast to a signed number (which doesn't have that guarantee!) Note that casts between signed/unsigned of the same size are guaranteed to work as expected.

this should work without warnings I guess?:

# define GRUB_LONG_MIN (0UL - 2147483648UL)
do you want it to be of a signed type, though? then cast that to (long) afterwards.
(-1L - 2147483647L) would work too.

it's annoying isn't it that C doesn't actually have negative numeric literals :-)

-Isaac

#3 lore raw
In reply to Vladimir 'phcoder' Serbinenko

hostdisk.c (working copy) line 350

Quoted 13 lines · Vladimir 'phcoder' Serbinenko

Index: util/hostdisk.c
===================================================================

hostdisk.c (working copy) renamed from hostdisk.c (revision 2340) +1 -1
@@ -344,7 +344,7 @@
 #else /* ! __linux__ */
 #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
   int sysctl_flags, sysctl_oldflags;
-  const size_t sysctl_size = sizeof (sysctl_flags);
+  size_t sysctl_size = sizeof (sysctl_flags);
 
   if (sysctlbyname ("kern.geom.debugflags", &sysctl_oldflags,
 &sysctl_size, NULL, 0))

We use sysctl_size twice after that call. If it's not constant, chances are that it has changed. Shouldn't we revert to the original value, or should we use the returned value in the subsequent calls?

I've seen that warning and I considered that patch, but I didn't have a chance to check the correctness of the change. Just silencing the warning is not good. We should actually make sure that the problem is fixed.

Quoted 10 lines
     {
hostdisk.c (working copy) renamed from hostdisk.c (revision 2340) +1 -0
@@ -833,6 +833,7 @@
 #endif
 }
 
+#if defined(__linux__) || defined(__CYGWIN__)
 static int
 device_is_wholedisk (const char *os_dev)
 {

hostdisk.c (working copy) line 846

Quoted 4 lines
hostdisk.c (working copy) renamed from hostdisk.c (revision 2340) +1 -0
@@ -842,6 +843,7 @@
     return 1;
   return 0;
 }
+#endif

That's good.

Quoted 12 lines
hostdisk.c (working copy) renamed from hostdisk.c (revision 2340) +1 -1
 static int
 find_system_device (const char *os_dev)
@@ -1045,7 +1047,7 @@
 
     if (strncmp ("/dev/", os_dev, 5) == 0)
       {
-        char *p, *q;
+        const char *p, *q;
         long int n;
 
         for (p = os_dev + 5; *p; ++p)

hostdisk.c (working copy) line 1060

Quoted 5 lines
hostdisk.c (working copy) renamed from hostdisk.c (revision 2340) +1 -1
@@ -1055,7 +1057,7 @@
               if (p)
                 {
                   p++;
-                  n = strtol (p, &q, 10);
+                  n = strtol (p, (char **) &q, 10);

Casts to remove "const" look like hacks to me. Again, it's better to keep a warning that to have such code.

Signature · 2 lines
Regards,
Pavel Roskin