Skip to contentSkip to conversation

package/e2tools: fix build with uClibc on mips64

PATCH In review Yegor Yefremov via buildroot 2 participants 4 messages Sep 8 – Sep 19

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/e2tools: fix build with uClibc on mips64

From: Yegor Yefremov <[email protected]>

put_file() passes &statbuf.st_size to store_data(), which takes an 'off_t *'. On mips64 those types do not match: uClibc-ng declares 'struct stat::st_size' as '__off_t' (long int) for the N32/N64 ABI, while '_FILE_OFFSET_BITS=64' makes 'off_t' an alias of '__off64_t' (long long int). Both are 64 bit wide, but they are distinct types, so gcc 14 and later reject the call:

src/write.c: In function 'put_file':
src/write.c:237:45: error: passing argument 4 of 'store_data' from incompatible pointer type [-Wincompatible-pointer-types]

  237 |       (retval = store_data(fs, fd, newfile, &statbuf.st_size)))
      |                                             ^~~~~~~~~~~~~~~~
      |                                             |
      |                                             __off_t * {aka long int *}

Add a patch using a local 'off_t' variable instead, copying the size reported by store_data() back into statbuf.

Fixes:
https://autobuild.buildroot.org/results/49754464e5daf87f69de8a79d7e6d607c00c78e2/

Assisted-by Claude:claude-opus-5
---
 ...ss-struct-stat-st_size-to-store_data.patch | 74 +++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch
package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch new file +74 -0
new file mode 100644
index 0000000000..86dd01192c
@@ -0,0 +1,74 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Yegor Yefremov <[email protected]>
+Date: Tue, 8 Sep 2026 12:00:00 +0200
+Subject: [PATCH] write: do not pass &statbuf.st_size to store_data()
+
+store_data() takes an 'off_t *', but put_file() hands it the address of
+'statbuf.st_size', whose type is whatever the C library declares in
+'struct stat'. Those two types are not required to match: on mips64
+uClibc-ng declares 'struct stat::st_size' as '__off_t' (long int), while
+'_FILE_OFFSET_BITS=64' makes 'off_t' an alias of '__off64_t' (long long
+int). Both are 64 bit wide, but they are distinct types, so gcc 14 and
+later reject the call:
+
+src/write.c: In function 'put_file':
+src/write.c:237:45: error: passing argument 4 of 'store_data' from incompatible pointer type [-Wincompatible-pointer-types]
+  237 |       (retval = store_data(fs, fd, newfile, &statbuf.st_size)))
+      |                                             ^~~~~~~~~~~~~~~~
+      |                                             |
+      |                                             __off_t * {aka long int *}
+src/write.c:49:63: note: expected 'off_t *' {aka 'long long int *'} but argument is of type '__off_t *' {aka 'long int *'}
+   49 | store_data(ext2_filsys fs, int fd, ext2_ino_t newfile, off_t *file_size);
+      |                                                        ~~~~~~~^~~~~~~~~
+
+Use a local 'off_t' variable instead and copy the size store_data()
+reports back into statbuf, which is what the code below (the stdin case,
+where the size is only known after the copy) relies on.
+
+Upstream: https://github.com/e2tools/e2tools/pull/40
+Signed-off-by: Yegor Yefremov <[email protected]>
+Assisted-by: Claude:claude-opus-5
+---
+ src/write.c | 19 ++++++++++++++-----
+ 1 file changed, 14 insertions(+), 5 deletions(-)
+
+diff --git a/src/write.c b/src/write.c
+index 1111111..2222222 100644
+--- a/src/write.c
++++ b/src/write.c
+@@ -114,6 +114,7 @@ put_file(ext2_filsys fs, ext2_ino_t cwd, char *infile, char *outfile,
+   long  retval;
+   struct ext2_inode inode;
+   mode_t cur_umask;
++  off_t file_size;
+ 
+   if (fs == NULL || outfile == NULL)
+     {
+@@ -233,15 +234,19 @@ put_file(ext2_filsys fs, ext2_ino_t cwd, char *infile, char *outfile,
+       return (retval);
+     }
+ 
+-  if (LINUX_S_ISREG(inode.i_mode) &&
+-      (retval = store_data(fs, fd, newfile, &statbuf.st_size)))
++  if (LINUX_S_ISREG(inode.i_mode))
+     {
+-      close(fd);
++      file_size = statbuf.st_size;
++      if ((retval = store_data(fs, fd, newfile, &file_size)))
++        {
++          close(fd);
+ #ifndef DEBUG
+-      rm_file(fs, cwd, outfile, newfile);
++          rm_file(fs, cwd, outfile, newfile);
+ 
+ #endif
+-      return(retval);
++          return(retval);
++        }
++      statbuf.st_size = file_size;
+     }
+ 
+   close(fd);
+-- 
+2.51.0
+
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Hello Yegor,

(+Waldemar in Cc)

Quoted 8 lines · Yegor Yefremov via buildroot
package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch new file +2 -0
new file mode 100644
index 0000000000..86dd01192c
@@ -0,0 +1,74 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Yegor Yefremov <[email protected]>

package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch line 12

Quoted 10 lines
package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch new file +10 -0
+Date: Tue, 8 Sep 2026 12:00:00 +0200
+Subject: [PATCH] write: do not pass &statbuf.st_size to store_data()
+
+store_data() takes an 'off_t *', but put_file() hands it the address of
+'statbuf.st_size', whose type is whatever the C library declares in
+'struct stat'. Those two types are not required to match: on mips64
+uClibc-ng declares 'struct stat::st_size' as '__off_t' (long int), while
+'_FILE_OFFSET_BITS=64' makes 'off_t' an alias of '__off64_t' (long long
+int). Both are 64 bit wide, but they are distinct types, so gcc 14 and
+later reject the call:

Are you sure this is the correct fix?

When I look at stat(3type) it says:

struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* Inode number */
mode_t st_mode; /* File type and mode */
nlink_t st_nlink; /* Number of hard links */
uid_t st_uid; /* User ID of owner */
gid_t st_gid; /* Group ID of owner */
dev_t st_rdev; /* Device ID (if special file) */
off_t st_size; /* Total size, in bytes */

So st_size is an off_t, so passing &blabla.st_size to a function expecting an off_t* should always work.

And the fact that this (apparently) only occurs on uClibc makes me think that this is more likely a uClibc bug.

Waldemar, do you have any thoughts?

Thomas

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Hi Thomas, Yegor, all,
Thomas Petazzoni wrote,

Quoted 39 lines

Hello Yegor,

(+Waldemar in Cc)

Quoted 8 lines · Yegor Yefremov via buildroot
package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch new file +2 -0
new file mode 100644
index 0000000000..86dd01192c
@@ -0,0 +1,74 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Yegor Yefremov <[email protected]>

package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch line 12

Quoted 10 lines
package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch new file +10 -0
+Date: Tue, 8 Sep 2026 12:00:00 +0200
+Subject: [PATCH] write: do not pass &statbuf.st_size to store_data()
+
+store_data() takes an 'off_t *', but put_file() hands it the address of
+'statbuf.st_size', whose type is whatever the C library declares in
+'struct stat'. Those two types are not required to match: on mips64
+uClibc-ng declares 'struct stat::st_size' as '__off_t' (long int), while
+'_FILE_OFFSET_BITS=64' makes 'off_t' an alias of '__off64_t' (long long
+int). Both are 64 bit wide, but they are distinct types, so gcc 14 and
+later reject the call:

Are you sure this is the correct fix?

When I look at stat(3type) it says:

struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* Inode number */
mode_t st_mode; /* File type and mode */
nlink_t st_nlink; /* Number of hard links */
uid_t st_uid; /* User ID of owner */
gid_t st_gid; /* Group ID of owner */
dev_t st_rdev; /* Device ID (if special file) */
off_t st_size; /* Total size, in bytes */

Quoted 7 lines

So st_size is an off_t, so passing &blabla.st_size to a function expecting an off_t* should always work.

And the fact that this (apparently) only occurs on uClibc makes me think that this is more likely a uClibc bug.

Waldemar, do you have any thoughts?

I believe you are right, it is a uClibc-ng Bug. I could reproduce the issue with MIPS64 (LE) N32. A fix is committed to uClibc-ng git repository.

https://github.com/wbx-github/uclibc-ng/commit/4d307481e2c73e4ec6ae3e37c881d29c182bed58

best regards
Waldemar

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw

Hi Waldemar, Thomas, all,

Quoted 49 lines · Waldemar Brodkorb

Hi Thomas, Yegor, all,
Thomas Petazzoni wrote,

Quoted 45 lines

Hello Yegor,

(+Waldemar in Cc)

Quoted 8 lines · Yegor Yefremov via buildroot
package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch new file +2 -0
new file mode 100644
index 0000000000..86dd01192c
@@ -0,0 +1,74 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Yegor Yefremov <[email protected]>

package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch line 12

Quoted 10 lines
package/e2tools/0001-write-do-not-pass-struct-stat-st_size-to-store_data.patch new file +10 -0
+Date: Tue, 8 Sep 2026 12:00:00 +0200
+Subject: [PATCH] write: do not pass &statbuf.st_size to store_data()
+
+store_data() takes an 'off_t *', but put_file() hands it the address of
+'statbuf.st_size', whose type is whatever the C library declares in
+'struct stat'. Those two types are not required to match: on mips64
+uClibc-ng declares 'struct stat::st_size' as '__off_t' (long int), while
+'_FILE_OFFSET_BITS=64' makes 'off_t' an alias of '__off64_t' (long long
+int). Both are 64 bit wide, but they are distinct types, so gcc 14 and
+later reject the call:

Are you sure this is the correct fix?

When I look at stat(3type) it says:

struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* Inode number */
mode_t st_mode; /* File type and mode */
nlink_t st_nlink; /* Number of hard links */
uid_t st_uid; /* User ID of owner */
gid_t st_gid; /* Group ID of owner */
dev_t st_rdev; /* Device ID (if special file) */
off_t st_size; /* Total size, in bytes */

So st_size is an off_t, so passing &blabla.st_size to a function expecting an off_t* should always work.

And the fact that this (apparently) only occurs on uClibc makes me think that this is more likely a uClibc bug.

Quoted 7 lines
Quoted 1 line

Waldemar, do you have any thoughts?

I believe you are right, it is a uClibc-ng Bug. I could reproduce the issue with MIPS64 (LE) N32. A fix is committed to uClibc-ng git repository.

https://github.com/wbx-github/uclibc-ng/commit/4d307481e2c73e4ec6ae3e37c881d29c182bed58

Then my solution was wrong and can be dismissed. I turned the upstream PR to a draft.

Yegor
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot