public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v4 mtd-utils 1/4] ubifs-utils: ubifs.h: Include <fcntl.h>
@ 2025-02-19 13:02 Fabio Estevam
  2025-02-19 13:02 ` [PATCH v4 mtd-utils 2/4] ubifs-utils: journal: Include <sys/stat.h> Fabio Estevam
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Fabio Estevam @ 2025-02-19 13:02 UTC (permalink / raw)
  To: david.oberhollenzer; +Cc: chengzhihao1, raj.khem, linux-mtd, Fabio Estevam

Include the <fcntl.h> header file to fix the following error
when building with musl:

| In file included from ../git/ubifs-utils/common/compr.c:42:
| ../git/ubifs-utils/libubifs/ubifs.h:313:9: error: unknown type name 'loff_t'; did you mean 'off_t'?
|   313 |         loff_t ui_size;
|       |         ^~~~~~
|       |         off_t
| ../git/ubifs-utils/libubifs/ubifs.h:1341:9: error: unknown type name 'loff_t'; did you mean 'off_t'?
|  1341 |         loff_t i_size;
|       |         ^~~~~~
|       |         off_t
| ../git/ubifs-utils/libubifs/ubifs.h:1342:9: error: unknown type name 'loff_t'; did you mean 'off_t'?
|  1342 |         loff_t d_size;
|       |         ^~~~~~
|       |         off_t
| ../git/ubifs-utils/libubifs/ubifs.h:1899:44: error: unknown type name 'loff_t'; did you mean 'off_t'?
|  1899 |                              int deletion, loff_t new_size);
|       |                                            ^~~~~~
|       |                                            off_t
| make: *** [Makefile:4878: ubifs-utils/common/mkfs_ubifs-compr.o] Error 1

Signed-off-by: Fabio Estevam <festevam@gmail.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Reviewed-by: Khem Raj <raj.khem@gmail.com>
---
Changes since v3:
- Removed Upstream-Status tag.

 ubifs-utils/libubifs/ubifs.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ubifs-utils/libubifs/ubifs.h b/ubifs-utils/libubifs/ubifs.h
index 0908a2289208..1c7bc7bd0c80 100644
--- a/ubifs-utils/libubifs/ubifs.h
+++ b/ubifs-utils/libubifs/ubifs.h
@@ -11,6 +11,7 @@
 #ifndef __UBIFS_H__
 #define __UBIFS_H__
 
+#include <fcntl.h>
 #include <string.h>
 
 #include "linux_types.h"
-- 
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v4 mtd-utils 2/4] ubifs-utils: journal: Include <sys/stat.h>
  2025-02-19 13:02 [PATCH v4 mtd-utils 1/4] ubifs-utils: ubifs.h: Include <fcntl.h> Fabio Estevam
@ 2025-02-19 13:02 ` Fabio Estevam
  2025-02-19 13:02 ` [PATCH v4 mtd-utils 3/4] configure.ac: Add a check for execinfo and backtrace Fabio Estevam
  2025-02-19 13:02 ` [PATCH v4 mtd-utils 4/4] ubifs-utils: extract_files: Include <linux/limits.h> Fabio Estevam
  2 siblings, 0 replies; 8+ messages in thread
From: Fabio Estevam @ 2025-02-19 13:02 UTC (permalink / raw)
  To: david.oberhollenzer; +Cc: chengzhihao1, raj.khem, linux-mtd, Fabio Estevam

Include the <sys/stat.h> header file to fix the following error
when building with musl:

| ../git/ubifs-utils/libubifs/journal.c: In function 'ubifs_get_dent_type':
| ../git/ubifs-utils/libubifs/journal.c:414:24: error: 'S_IFMT' undeclared (first use in this function)
|   414 |         switch (mode & S_IFMT) {
|       |                        ^~~~~~
| ../git/ubifs-utils/libubifs/journal.c:414:24: note: each undeclared identifier is reported only once for each function it appears in
| ../git/ubifs-utils/libubifs/journal.c:415:14: error: 'S_IFREG' undeclared (first use in this function)
|   415 |         case S_IFREG:

Signed-off-by: Fabio Estevam <festevam@gmail.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
Changes since v3:
- Removed Upstream-Status tag.

 ubifs-utils/libubifs/journal.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ubifs-utils/libubifs/journal.c b/ubifs-utils/libubifs/journal.c
index e78ea14f3e69..45d82fd54bdb 100644
--- a/ubifs-utils/libubifs/journal.c
+++ b/ubifs-utils/libubifs/journal.c
@@ -46,6 +46,7 @@
  * all the nodes.
  */
 
+#include <sys/stat.h>
 #include "bitops.h"
 #include "kmem.h"
 #include "ubifs.h"
-- 
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v4 mtd-utils 3/4] configure.ac: Add a check for execinfo and backtrace
  2025-02-19 13:02 [PATCH v4 mtd-utils 1/4] ubifs-utils: ubifs.h: Include <fcntl.h> Fabio Estevam
  2025-02-19 13:02 ` [PATCH v4 mtd-utils 2/4] ubifs-utils: journal: Include <sys/stat.h> Fabio Estevam
@ 2025-02-19 13:02 ` Fabio Estevam
  2025-02-26 18:23   ` Ross Burton
  2025-02-19 13:02 ` [PATCH v4 mtd-utils 4/4] ubifs-utils: extract_files: Include <linux/limits.h> Fabio Estevam
  2 siblings, 1 reply; 8+ messages in thread
From: Fabio Estevam @ 2025-02-19 13:02 UTC (permalink / raw)
  To: david.oberhollenzer; +Cc: chengzhihao1, raj.khem, linux-mtd, Fabio Estevam

musl relies on an external execinfo library to provide backtrace
functionality. If musl cannot link to libexecinfo, the following link
error happens:

| /work/festevam/oe/poky/build/tmp/work/core2-64-poky-linux-musl/mtd-utils/2.3.0/recipe-sysroot-native/usr/bin/x86_64-poky-linux-musl/../../libexec/x86_64-poky-linux-musl/gcc/x86_64-poky-linux-musl/14.2.0/ld: ubifs-utils/libubifs/mkfs_ubifs-io.o: in function `dump_stack':
| /usr/src/debug/mtd-utils/2.3.0/ubifs-utils/common/defs.h:71:(.text+0x25): undefined reference to `backtrace'
....
| collect2: error: ld returned 1 exit status
| make: *** [Makefile:2959: mkfs.ubifs] Error 1

Fix the problem by checking for backtrace support in libc first and if not
found, then check for backtrace support in the external libexecinfo.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
Suggested-by: Khem Raj <raj.khem@gmail.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
Change since v3:
- None.

 configure.ac | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/configure.ac b/configure.ac
index 2a79ba820fc0..296901e61760 100644
--- a/configure.ac
+++ b/configure.ac
@@ -238,6 +238,17 @@ if test "x$need_cmocka" = "xyes"; then
 	PKG_CHECK_MODULES(CMOCKA, [cmocka], [], [cmocka_missing="yes"])
 fi
 
+AC_CHECK_FUNC([backtrace], [have_backtrace=yes], [have_backtrace=no])
+
+if test "x$have_backtrace" = "xno"; then
+    AC_CHECK_LIB([execinfo], [backtrace],
+        [LIBS="$LIBS -lexecinfo"
+         AC_DEFINE([HAVE_BACKTRACE], [1], [backtrace is available via libexecinfo])],
+        [AC_MSG_WARN([backtrace support not found])])
+else
+    AC_DEFINE([HAVE_BACKTRACE], [1], [backtrace is available via libc])
+fi
+
 AC_CHECK_HEADERS([execinfo.h])
 
 ##### produce summary on dependencies #####
-- 
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v4 mtd-utils 4/4] ubifs-utils: extract_files: Include <linux/limits.h>
  2025-02-19 13:02 [PATCH v4 mtd-utils 1/4] ubifs-utils: ubifs.h: Include <fcntl.h> Fabio Estevam
  2025-02-19 13:02 ` [PATCH v4 mtd-utils 2/4] ubifs-utils: journal: Include <sys/stat.h> Fabio Estevam
  2025-02-19 13:02 ` [PATCH v4 mtd-utils 3/4] configure.ac: Add a check for execinfo and backtrace Fabio Estevam
@ 2025-02-19 13:02 ` Fabio Estevam
  2025-06-02  5:39   ` David Oberhollenzer
  2 siblings, 1 reply; 8+ messages in thread
From: Fabio Estevam @ 2025-02-19 13:02 UTC (permalink / raw)
  To: david.oberhollenzer; +Cc: chengzhihao1, raj.khem, linux-mtd, Fabio Estevam

Include <linux/limits.h> to fix the following build error when building
with musl:

| ../git/ubifs-utils/fsck.ubifs/extract_files.c: In function 'parse_ino_node':
| ../git/ubifs-utils/fsck.ubifs/extract_files.c:144:47: error: 'XATTR_LIST_MAX' undeclared (first use in this function)
|   144 |         if (ino_node->xnms + ino_node->xcnt > XATTR_LIST_MAX) {
|       |                                               ^~~~~~~~~~~~~~
| ../git/ubifs-utils/fsck.ubifs/extract_files.c:144:47: note: each undeclared identifier is reported only once for each function it appears in
| make: *** [Makefile:4374: ubifs-utils/fsck.ubifs/fsck_ubifs-extract_files.o] Error 1

Signed-off-by: Fabio Estevam <festevam@gmail.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
Changes since v3:
- None.

 ubifs-utils/fsck.ubifs/extract_files.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ubifs-utils/fsck.ubifs/extract_files.c b/ubifs-utils/fsck.ubifs/extract_files.c
index c83d37749bc0..000ef5d10565 100644
--- a/ubifs-utils/fsck.ubifs/extract_files.c
+++ b/ubifs-utils/fsck.ubifs/extract_files.c
@@ -10,6 +10,8 @@
 #include <getopt.h>
 #include <sys/stat.h>
 
+#include <linux/limits.h>
+
 #include "linux_err.h"
 #include "bitops.h"
 #include "kmem.h"
-- 
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 mtd-utils 3/4] configure.ac: Add a check for execinfo and backtrace
  2025-02-19 13:02 ` [PATCH v4 mtd-utils 3/4] configure.ac: Add a check for execinfo and backtrace Fabio Estevam
@ 2025-02-26 18:23   ` Ross Burton
  2025-02-26 20:13     ` Khem Raj
  0 siblings, 1 reply; 8+ messages in thread
From: Ross Burton @ 2025-02-26 18:23 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: david.oberhollenzer@sigma-star.at, chengzhihao1@huawei.com,
	raj.khem@gmail.com, linux-mtd@lists.infradead.org

On 19 Feb 2025, at 13:02, Fabio Estevam <festevam@gmail.com> wrote:
>
> musl relies on an external execinfo library to provide backtrace
> functionality. If musl cannot link to libexecinfo, the following link
> error happens:
>
> Fix the problem by checking for backtrace support in libc first and if not
> found, then check for backtrace support in the external libexecinfo.

If this is the right solution, it’s not complete.

mtd-utils already checks for the presence of execinfo.h and uses that when creating lib/libmissing.a, which if execinfo.h isn’t present will contain a stub backtrace() implementation that simply returns 0.  The test suite already uses this so it can build on systems without musl, but presumably nobody tested mtd-utils on musl after "ubifs-utils: Add implementations for linux kernel printing functions” landed, which added more users of backtrace().

I think either mtd-utils should hard-depend on _something_ providing backtrace(), be it the libc or a drop-in library, or it should use backtrace() if present and gracefully fallback otherwise (as it’s a convenience feature).  Not both, which is what this patch achieves.

I’ll send an alternative patch in a moment which uses libmissing.a instead of relying on an external libexecinfo.

Note that the rest of the series is good, this is the only change I have comments on.

Ross
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 mtd-utils 3/4] configure.ac: Add a check for execinfo and backtrace
  2025-02-26 18:23   ` Ross Burton
@ 2025-02-26 20:13     ` Khem Raj
  2025-02-27  6:58       ` Zhihao Cheng
  0 siblings, 1 reply; 8+ messages in thread
From: Khem Raj @ 2025-02-26 20:13 UTC (permalink / raw)
  To: Ross Burton
  Cc: Fabio Estevam, david.oberhollenzer@sigma-star.at,
	chengzhihao1@huawei.com, linux-mtd@lists.infradead.org

On Wed, Feb 26, 2025 at 10:23 AM Ross Burton <Ross.Burton@arm.com> wrote:
>
> On 19 Feb 2025, at 13:02, Fabio Estevam <festevam@gmail.com> wrote:
> >
> > musl relies on an external execinfo library to provide backtrace
> > functionality. If musl cannot link to libexecinfo, the following link
> > error happens:
> >
> > Fix the problem by checking for backtrace support in libc first and if not
> > found, then check for backtrace support in the external libexecinfo.
>
> If this is the right solution, it’s not complete.
>
> mtd-utils already checks for the presence of execinfo.h and uses that when creating lib/libmissing.a, which if execinfo.h isn’t present will contain a stub backtrace() implementation that simply returns 0.  The test suite already uses this so it can build on systems without musl, but presumably nobody tested mtd-utils on musl after "ubifs-utils: Add implementations for linux kernel printing functions” landed, which added more users of backtrace().
>
> I think either mtd-utils should hard-depend on _something_ providing backtrace(), be it the libc or a drop-in library, or it should use backtrace() if present and gracefully fallback otherwise (as it’s a convenience feature).  Not both, which is what this patch achieves.
>
> I’ll send an alternative patch in a moment which uses libmissing.a instead of relying on an external libexecinfo.
>

I think looking for libexecinfo is perhaps fine, its that when
backtrace is not found in libc and in libexecinfo, it should still
work by falling back to stub.

> Note that the rest of the series is good, this is the only change I have comments on.
>
> Ross
> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 mtd-utils 3/4] configure.ac: Add a check for execinfo and backtrace
  2025-02-26 20:13     ` Khem Raj
@ 2025-02-27  6:58       ` Zhihao Cheng
  0 siblings, 0 replies; 8+ messages in thread
From: Zhihao Cheng @ 2025-02-27  6:58 UTC (permalink / raw)
  To: Khem Raj, Ross Burton
  Cc: Fabio Estevam, david.oberhollenzer@sigma-star.at,
	linux-mtd@lists.infradead.org

在 2025/2/27 4:13, Khem Raj 写道:
> On Wed, Feb 26, 2025 at 10:23 AM Ross Burton <Ross.Burton@arm.com> wrote:
>>
>> On 19 Feb 2025, at 13:02, Fabio Estevam <festevam@gmail.com> wrote:
>>>
>>> musl relies on an external execinfo library to provide backtrace
>>> functionality. If musl cannot link to libexecinfo, the following link
>>> error happens:
>>>
>>> Fix the problem by checking for backtrace support in libc first and if not
>>> found, then check for backtrace support in the external libexecinfo.
>>
>> If this is the right solution, it’s not complete.
>>
>> mtd-utils already checks for the presence of execinfo.h and uses that when creating lib/libmissing.a, which if execinfo.h isn’t present will contain a stub backtrace() implementation that simply returns 0.  The test suite already uses this so it can build on systems without musl, but presumably nobody tested mtd-utils on musl after "ubifs-utils: Add implementations for linux kernel printing functions” landed, which added more users of backtrace().
>>
>> I think either mtd-utils should hard-depend on _something_ providing backtrace(), be it the libc or a drop-in library, or it should use backtrace() if present and gracefully fallback otherwise (as it’s a convenience feature).  Not both, which is what this patch achieves.
>>

That sounds plausible, that's possibly what commit 
3516b8b7558a69dfd("Add libmissing") wanted to do.
>> I’ll send an alternative patch in a moment which uses libmissing.a instead of relying on an external libexecinfo.
>>
> 
> I think looking for libexecinfo is perhaps fine, its that when
> backtrace is not found in libc and in libexecinfo, it should still
> work by falling back to stub.
> 

Hi, Khem. IMHO,maybe copying 'execinfo.h' into musl is a hack way, then 
users could modify mtd-utils(eg. link external libexecinfo) according to 
the specific compiler, but that's not a common way for all compilers. 
What if the library contains 'backtrace' function is not named as 
'libexecinfo'?
>> Note that the rest of the series is good, this is the only change I have comments on.
>>
>> Ross
>> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
> .
> 


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 mtd-utils 4/4] ubifs-utils: extract_files: Include <linux/limits.h>
  2025-02-19 13:02 ` [PATCH v4 mtd-utils 4/4] ubifs-utils: extract_files: Include <linux/limits.h> Fabio Estevam
@ 2025-06-02  5:39   ` David Oberhollenzer
  0 siblings, 0 replies; 8+ messages in thread
From: David Oberhollenzer @ 2025-06-02  5:39 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: chengzhihao1, raj.khem, linux-mtd

I cherry-picked the changes, save for the libexecinfo patch
and applied them to mtd-utils.git master.

The execinfo related issue should be resolved by [1] which
adds a check to mkfs.ubifs and properly links the libmissing
stub.

Thanks,

David

[1] https://patchwork.ozlabs.org/project/linux-mtd/patch/20250226182400.1723418-1-ross.burton@arm.com/


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-06-02  5:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-19 13:02 [PATCH v4 mtd-utils 1/4] ubifs-utils: ubifs.h: Include <fcntl.h> Fabio Estevam
2025-02-19 13:02 ` [PATCH v4 mtd-utils 2/4] ubifs-utils: journal: Include <sys/stat.h> Fabio Estevam
2025-02-19 13:02 ` [PATCH v4 mtd-utils 3/4] configure.ac: Add a check for execinfo and backtrace Fabio Estevam
2025-02-26 18:23   ` Ross Burton
2025-02-26 20:13     ` Khem Raj
2025-02-27  6:58       ` Zhihao Cheng
2025-02-19 13:02 ` [PATCH v4 mtd-utils 4/4] ubifs-utils: extract_files: Include <linux/limits.h> Fabio Estevam
2025-06-02  5:39   ` David Oberhollenzer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox