Skip to contentSkip to conversation

grub-core/osdep/unix/hostdisk.c: remove support for ancient glibc

PATCH Felix Janda 3 participants 9 messages Nov 21, 2014 – Dec 7, 2014

lore
Share & tools
lore
#0 lore raw

Hello,

the file grub-core/osdep/unix/hostdisk.c has special code for glibc<2.1, which gets also pulled in for other libcs (such as musl libc) and makes compilation fail for them because the code uses glibc internals. The easiest way to fix is just to remove the code as the below patch does.

--Felix

grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c +0 -24
diff -ur a/grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c b/grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c
@@ -48,11 +48,6 @@
 #ifdef __linux__
 # include <sys/ioctl.h>         /* ioctl */
 # include <sys/mount.h>
-# if !defined(__GLIBC__) || \
-        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))
-/* Maybe libc doesn't have large file support.  */
-#  include <linux/unistd.h>     /* _llseek */
-# endif /* (GLIBC < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR < 1)) */
 #endif /* __linux__ */
 
 grub_uint64_t
@@ -79,24 +74,6 @@
   return st.st_size;
 }
 
-#if defined(__linux__) && (!defined(__GLIBC__) || \
-        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))))
-  /* Maybe libc doesn't have large file support.  */
-int
-grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
-{
-  loff_t offset, result;
-  static int _llseek (uint filedes, ulong hi, ulong lo,
-		      loff_t *res, uint wh);
-  _syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo,
-	     loff_t *, res, uint, wh);
-
-  offset = (loff_t) off;
-  if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
-    return -1;
-  return GRUB_ERR_NONE;
-}
-#else
 int
 grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
 {
@@ -107,7 +84,6 @@
 
   return 0;
 }
-#endif
 
 
 /* Read LEN bytes from FD in BUF. Return less than or equal to zero if an
#1 lore raw

This was badly coordinated. Please use the recent patch from daggs instead.

Felix

#2 lore raw
In reply to Felix Janda

В Fri, 21 Nov 2014 21:00:41 +0100
Felix Janda <[email protected]> пишет:

Quoted 7 lines

Hello,

the file grub-core/osdep/unix/hostdisk.c has special code for glibc<2.1, which gets also pulled in for other libcs (such as musl libc) and makes compilation fail for them because the code uses glibc internals. The easiest way to fix is just to remove the code as the below patch does.

Could you replace glibc version check with configure test for llseek? This should cover your case as well.

Quoted 55 lines

--Felix

diff -ur a/grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c b/grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c

grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c +0 -24
@@ -48,11 +48,6 @@
 #ifdef __linux__
 # include <sys/ioctl.h>         /* ioctl */
 # include <sys/mount.h>
-# if !defined(__GLIBC__) || \
-        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))
-/* Maybe libc doesn't have large file support.  */
-#  include <linux/unistd.h>     /* _llseek */
-# endif /* (GLIBC < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR < 1)) */
 #endif /* __linux__ */
 
 grub_uint64_t
@@ -79,24 +74,6 @@
   return st.st_size;
 }
 
-#if defined(__linux__) && (!defined(__GLIBC__) || \
-        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))))
-  /* Maybe libc doesn't have large file support.  */
-int
-grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
-{
-  loff_t offset, result;
-  static int _llseek (uint filedes, ulong hi, ulong lo,
-		      loff_t *res, uint wh);
-  _syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo,
-	     loff_t *, res, uint, wh);
-
-  offset = (loff_t) off;
-  if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
-    return -1;
-  return GRUB_ERR_NONE;
-}
-#else
 int
 grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
 {
@@ -107,7 +84,6 @@
 
   return 0;
 }
-#endif
 
 
 /* Read LEN bytes from FD in BUF. Return less than or equal to zero if an

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

#3 lore raw
Quoted 5 lines · Andrei Borzenkov

В Fri, 21 Nov 2014 21:00:41 +0100
Felix Janda <[email protected]> пишет:

Quoted 2 lines

Hello,

Quoted 8 lines
Quoted 5 lines

the file grub-core/osdep/unix/hostdisk.c has special code for glibc<2.1, which gets also pulled in for other libcs (such as musl libc) and makes compilation fail for them because the code uses glibc internals. The easiest way to fix is just to remove the code as the below patch does.

Could you replace glibc version check with configure test for llseek? This should cover your case as well.

There is no llseek.

Testing for lseek will likely also succeed for old glibc. I think that one rather needs to check whether its prototype is correct.

I don't think that the code behind !defined(__GLIBC__) ... is useful for anything other than glibc<2.1. It seems to use old glibc internals. (Notice that glibc-2.1 is from 1999.) If the code should be kept in, it should IMO be conditional on

((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))

Felix

#4 lore raw
In reply to Felix Janda
Quoted 7 lines · Felix Janda

Hello,

the file grub-core/osdep/unix/hostdisk.c has special code for glibc<2.1, which gets also pulled in for other libcs (such as musl libc) and makes compilation fail for them because the code uses glibc internals. The easiest way to fix is just to remove the code as the below patch does.

Don't assume that nobody will try to compile with ancient glibc. If you want to raise the supported version for glibc you need to add a configure check for presence of long offsets to configure and fail it if it's not available. It should also be documented in INSTALL.

Quoted 56 lines

--Felix

diff -ur a/grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c b/grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c

grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c +0 -24
@@ -48,11 +48,6 @@
 #ifdef __linux__
 # include <sys/ioctl.h>         /* ioctl */
 # include <sys/mount.h>
-# if !defined(__GLIBC__) || \
-        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))
-/* Maybe libc doesn't have large file support.  */
-#  include <linux/unistd.h>     /* _llseek */
-# endif /* (GLIBC < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR < 1)) */
 #endif /* __linux__ */
 
 grub_uint64_t
@@ -79,24 +74,6 @@
   return st.st_size;
 }
 
-#if defined(__linux__) && (!defined(__GLIBC__) || \
-        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))))
-  /* Maybe libc doesn't have large file support.  */
-int
-grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
-{
-  loff_t offset, result;
-  static int _llseek (uint filedes, ulong hi, ulong lo,
-		      loff_t *res, uint wh);
-  _syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo,
-	     loff_t *, res, uint, wh);
-
-  offset = (loff_t) off;
-  if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
-    return -1;
-  return GRUB_ERR_NONE;
-}
-#else
 int
 grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
 {
@@ -107,7 +84,6 @@
 
   return 0;
 }
-#endif
 
 
 /* Read LEN bytes from FD in BUF. Return less than or equal to zero if an

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

#5 lore raw
Quoted 8 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 7 lines · Felix Janda

Hello,

the file grub-core/osdep/unix/hostdisk.c has special code for glibc<2.1, which gets also pulled in for other libcs (such as musl libc) and makes compilation fail for them because the code uses glibc internals. The easiest way to fix is just to remove the code as the below patch does.

Quoted 4 lines

Don't assume that nobody will try to compile with ancient glibc. If you want to raise the supported version for glibc you need to add a configure check for presence of long offsets to configure and fail it if it's not available. It should also be documented in INSTALL.

Before messing around with configure.ac, I'd like know whether a patch (correctly) implementing what you suggest would be accepted.

Another solution I would be happy with, is to change the conditions

# if !defined(__GLIBC__) || \
        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))

to

# ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))

Felix

#6 lore raw

В Thu, 4 Dec 2014 23:21:09 +0100
Felix Janda <[email protected]> пишет:

Quoted 17 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 8 lines · Felix Janda
Quoted 7 lines

Hello,

the file grub-core/osdep/unix/hostdisk.c has special code for glibc<2.1, which gets also pulled in for other libcs (such as musl libc) and makes compilation fail for them because the code uses glibc internals. The easiest way to fix is just to remove the code as the below patch does.

Quoted 4 lines

Don't assume that nobody will try to compile with ancient glibc. If you want to raise the supported version for glibc you need to add a configure check for presence of long offsets to configure and fail it if it's not available. It should also be documented in INSTALL.

Before messing around with configure.ac, I'd like know whether a patch (correctly) implementing what you suggest would be accepted.

Quoted 9 lines

Another solution I would be happy with, is to change the conditions

# if !defined(__GLIBC__) || \
        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))

to

# ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))

This will likely result in build error if __GLIBC__ is undefined.

Quoted 6 lines

Felix

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

#7 lore raw
Quoted 2 lines · Andrei Borzenkov

В Thu, 4 Dec 2014 23:21:09 +0100
Felix Janda <[email protected]> пишет:

[..]

Quoted 11 lines
Quoted 9 lines

Another solution I would be happy with, is to change the conditions

# if !defined(__GLIBC__) || \
        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))

to

# ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))

This will likely result in build error if __GLIBC__ is undefined.

Right, the condition is wrong if __GLIBC__ is undefined. How about the below patch?

Felix

grub-2.02~beta2/grub-core/osdep/unix/hostdisk.c +3 -3
@@ -48,7 +48,7 @@
 #ifdef __linux__
 # include <sys/ioctl.h>         /* ioctl */
 # include <sys/mount.h>
-# if !defined(__GLIBC__) || \
+# if defined(__GLIBC__) && \
         ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))
 /* Maybe libc doesn't have large file support.  */
 #  include <linux/unistd.h>     /* _llseek */
@@ -79,8 +79,8 @@
   return st.st_size;
 }
 
-#if defined(__linux__) && (!defined(__GLIBC__) || \
-        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))))
+#if defined(__linux__) && defined(__GLIBC__) && \
+        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))
   /* Maybe libc doesn't have large file support.  */
 int
 grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
#8 lore raw
In reply to Felix Janda
Quoted 9 lines · Felix Janda
Quoted 8 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 7 lines · Felix Janda

Hello,

the file grub-core/osdep/unix/hostdisk.c has special code for glibc<2.1, which gets also pulled in for other libcs (such as musl libc) and makes compilation fail for them because the code uses glibc internals. The easiest way to fix is just to remove the code as the below patch does.

Quoted 8 lines
Quoted 4 lines

Don't assume that nobody will try to compile with ancient glibc. If you want to raise the supported version for glibc you need to add a configure check for presence of long offsets to configure and fail it if it's not available. It should also be documented in INSTALL.

Before messing around with configure.ac, I'd like know whether a patch (correctly) implementing what you suggest would be accepted.

Yes, I'll accept removing this clause as long as failure on ./configure time is clear in case of no long-files available.

Quoted 16 lines

Another solution I would be happy with, is to change the conditions

# if !defined(__GLIBC__) || \
        ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))

to

# ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))

Felix

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