| Message ID | 20240426215144.1107186-1-fiona.klute@gmx.de |
|---|---|
| State | Accepted |
| Headers | show |
| Series | [1/1] package/kmod: fix build with musl | expand |
Hello Fiona, On Fri, 26 Apr 2024 23:51:44 +0200 Fiona Klute via buildroot <buildroot@buildroot.org> wrote: > From: Fiona Klute <fiona.klute+wiwa@gmx.de> > > Patch from upstream PR still being discussed: > https://github.com/kmod-project/kmod/pull/32 > > Signed-off-by: Fiona Klute <fiona.klute+wiwa@gmx.de> Thanks for the patch. One thing that I find strange is that I cannot reproduce. Yes, I get warnings due to basename(), but not an actual build failure (I'm using a toolchain based on musl 1.2.5). There are also no build failures in our autobuilders. Here is the defconfig that I tested: BR2_arm=y BR2_cortex_a9=y BR2_ARM_ENABLE_VFP=y BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV7_EABIHF_MUSL_STABLE=y BR2_INIT_NONE=y BR2_SYSTEM_BIN_SH_NONE=y # BR2_PACKAGE_BUSYBOX is not set BR2_PACKAGE_KMOD=y BR2_PACKAGE_KMOD_TOOLS=y # BR2_TARGET_ROOTFS_TAR is not set I just get: tools/kmod.c: In function ‘kmod_help’: tools/kmod.c:71:40: warning: implicit declaration of function ‘basename’ [-Wimplicit-function-declaration] 71 | "Commands:\n", basename(argv[0])); | ^~~~~~~~ tools/kmod.c:71:40: warning: nested extern declaration of ‘basename’ [-Wnested-externs] tools/kmod.c:65:16: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=] 65 | printf("kmod - Manage kernel modules: list, load, unload, etc\n" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...... 71 | "Commands:\n", basename(argv[0])); | ~~~~~~~~~~~~~~~~~ | | | int Thoughts? Thomas
Hi Thomas! Am 09.05.24 um 22:51 schrieb Thomas Petazzoni: > Hello Fiona, > > On Fri, 26 Apr 2024 23:51:44 +0200 > Fiona Klute via buildroot <buildroot@buildroot.org> wrote: > >> From: Fiona Klute <fiona.klute+wiwa@gmx.de> >> >> Patch from upstream PR still being discussed: >> https://github.com/kmod-project/kmod/pull/32 >> >> Signed-off-by: Fiona Klute <fiona.klute+wiwa@gmx.de> > > Thanks for the patch. One thing that I find strange is that I cannot > reproduce. Yes, I get warnings due to basename(), but not an actual > build failure (I'm using a toolchain based on musl 1.2.5). There are > also no build failures in our autobuilders. > > Here is the defconfig that I tested: > > BR2_arm=y > BR2_cortex_a9=y > BR2_ARM_ENABLE_VFP=y > BR2_TOOLCHAIN_EXTERNAL=y > BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y > BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV7_EABIHF_MUSL_STABLE=y > BR2_INIT_NONE=y > BR2_SYSTEM_BIN_SH_NONE=y > # BR2_PACKAGE_BUSYBOX is not set > BR2_PACKAGE_KMOD=y > BR2_PACKAGE_KMOD_TOOLS=y > # BR2_TARGET_ROOTFS_TAR is not set > > I just get: > > tools/kmod.c: In function ‘kmod_help’: > tools/kmod.c:71:40: warning: implicit declaration of function ‘basename’ [-Wimplicit-function-declaration] > 71 | "Commands:\n", basename(argv[0])); > | ^~~~~~~~ > tools/kmod.c:71:40: warning: nested extern declaration of ‘basename’ [-Wnested-externs] > tools/kmod.c:65:16: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=] > 65 | printf("kmod - Manage kernel modules: list, load, unload, etc\n" > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > ...... > 71 | "Commands:\n", basename(argv[0])); > | ~~~~~~~~~~~~~~~~~ > | | > | int > > > Thoughts? That's exactly what I'm seeing too. The problem is that when you then try to use the resulting binaries (e.g. modprobe) they segfault, because what's expected to be a pointer is some other value (probably int, with different length) and the result is an invalid pointer. So the build passes, but the resulting kmod tools are unusable. That's how I found the issue, I was wondering why no modules were loaded on my board. I would've just switched to the Busybox equivalents, but they can't handle compressed modules. Sorry I wasn't clearer, I tried to keep the commit message short, evidently too short. Best regards, Fiona
Fiona, All, On 2024-04-26 23:51 +0200, Fiona Klute via buildroot spake thusly: > From: Fiona Klute <fiona.klute+wiwa@gmx.de> > Patch from upstream PR still being discussed: > https://github.com/kmod-project/kmod/pull/32 Thanks for this pointer. It should have been added in the bundled patch itself (see below). I was holding off on that patch of yours, because there has been no resolution on that upstream PR (adding Khem in Cc so he can maybe have a look back at it ;-) ). But following your comment on bug #16093, I decided to look again. I just looked at the discussion in more details, and all the discussion is basically just about how to name the symbol. So let's cary this patch for now... > Signed-off-by: Fiona Klute <fiona.klute+wiwa@gmx.de> > --- > ...able-implementation-for-basename-API.patch | 131 ++++++++++++++++++ # ./utils/docker-run make check-package package/kmod/0002-Use-portable-implementation-for-basename-API.patch:0: missing Upstream in the header (https://nightly.buildroot.org/#_additional_patch_documentation) This is where you should add the upstream PR URL: Upstream: https://github.com/kmod-project/kmod/pull/32 You must also sign-off the bundled patch. No need to respin, I can just add it if you just reply with your SoB line. Thanks! Regards, Yann E. MORIN. > 1 file changed, 131 insertions(+) > create mode 100644 package/kmod/0002-Use-portable-implementation-for-basename-API.patch > > diff --git a/package/kmod/0002-Use-portable-implementation-for-basename-API.patch b/package/kmod/0002-Use-portable-implementation-for-basename-API.patch > new file mode 100644 > index 0000000000..46d23f4fa9 > --- /dev/null > +++ b/package/kmod/0002-Use-portable-implementation-for-basename-API.patch > @@ -0,0 +1,131 @@ > +From 721ed6040c7aa47070faf6378c433089e178bd43 Mon Sep 17 00:00:00 2001 > +From: Khem Raj <raj.khem@gmail.com> > +Date: Sat, 9 Dec 2023 17:35:59 -0800 > +Subject: [PATCH] Use portable implementation for basename API > + > +musl has removed the non-prototype declaration of basename from > +string.h [1] which now results in build errors with clang-17+ compiler > + > +Implement GNU basename behavior using strchr which is portable across libcs > + > +Fixes > +../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] > +71 | "Commands:\n", basename(argv[0])); > +| ^ > + > +[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 > + > +Suggested-by: Rich Felker > + > +Signed-off-by: Khem Raj <raj.khem@gmail.com> > +--- > + libkmod/libkmod-config.c | 2 +- > + shared/util.c | 4 ++-- > + shared/util.h | 7 +++++++ > + testsuite/testsuite.c | 2 +- > + tools/depmod.c | 2 +- > + tools/kmod.c | 4 ++-- > + 6 files changed, 14 insertions(+), 7 deletions(-) > + > +diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c > +index e83621b3..8aa555a4 100644 > +--- a/libkmod/libkmod-config.c > ++++ b/libkmod/libkmod-config.c > +@@ -794,7 +794,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx, > + bool is_single = false; > + > + if (name == NULL) { > +- name = basename(path); > ++ name = gnu_basename(path); > + is_single = true; > + } > + > +diff --git a/shared/util.c b/shared/util.c > +index e2bab83a..0e16670e 100644 > +--- a/shared/util.c > ++++ b/shared/util.c > +@@ -172,9 +172,9 @@ char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t * > + > + char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len) > + { > +- char *modname; > ++ const char *modname; > + > +- modname = basename(path); > ++ modname = gnu_basename(path); > + if (modname == NULL || modname[0] == '\0') > + return NULL; > + > +diff --git a/shared/util.h b/shared/util.h > +index c4a3916b..073dc5a7 100644 > +--- a/shared/util.h > ++++ b/shared/util.h > +@@ -5,6 +5,7 @@ > + #include <stdbool.h> > + #include <stdlib.h> > + #include <stdio.h> > ++#include <string.h> > + #include <sys/types.h> > + #include <sys/stat.h> > + #include <time.h> > +@@ -76,6 +77,12 @@ do { \ > + __p->__v = (val); \ > + } while(0) > + > ++static _always_inline_ const char *gnu_basename(const char *s) > ++{ > ++ const char *p = strrchr(s, '/'); > ++ return p ? p+1 : s; > ++} > ++ > + static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u) > + { > + return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1)); > +diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c > +index 318343ac..aafc9873 100644 > +--- a/testsuite/testsuite.c > ++++ b/testsuite/testsuite.c > +@@ -70,7 +70,7 @@ static void help(void) > + > + printf("Usage:\n" > + "\t%s [options] <test>\n" > +- "Options:\n", basename(progname)); > ++ "Options:\n", gnu_basename(progname)); > + > + for (itr = options, itr_short = options_short; > + itr->name != NULL; itr++, itr_short++) > +diff --git a/tools/depmod.c b/tools/depmod.c > +index 43fc354a..cfb15b11 100644 > +--- a/tools/depmod.c > ++++ b/tools/depmod.c > +@@ -762,7 +762,7 @@ static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files > + if (name != NULL) > + namelen = strlen(name); > + else { > +- name = basename(dir); > ++ name = gnu_basename(dir); > + namelen = strlen(name); > + dirlen -= namelen + 1; > + } > +diff --git a/tools/kmod.c b/tools/kmod.c > +index 55689c07..df91e5c6 100644 > +--- a/tools/kmod.c > ++++ b/tools/kmod.c > +@@ -68,7 +68,7 @@ static int kmod_help(int argc, char *argv[]) > + "Options:\n" > + "\t-V, --version show version\n" > + "\t-h, --help show this help\n\n" > +- "Commands:\n", basename(argv[0])); > ++ "Commands:\n", gnu_basename(argv[0])); > + > + for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) { > + if (kmod_cmds[i]->help != NULL) { > +@@ -156,7 +156,7 @@ static int handle_kmod_compat_commands(int argc, char *argv[]) > + const char *cmd; > + size_t i; > + > +- cmd = basename(argv[0]); > ++ cmd = gnu_basename(argv[0]); > + > + for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) { > + if (streq(kmod_compat_cmds[i]->name, cmd)) > -- > 2.43.0 > > _______________________________________________ > buildroot mailing list > buildroot@buildroot.org > https://lists.buildroot.org/mailman/listinfo/buildroot
Am 04.06.24 um 19:55 schrieb Yann E. MORIN: > Fiona, All, > > On 2024-04-26 23:51 +0200, Fiona Klute via buildroot spake thusly: >> From: Fiona Klute <fiona.klute+wiwa@gmx.de> >> Patch from upstream PR still being discussed: >> https://github.com/kmod-project/kmod/pull/32 > > Thanks for this pointer. It should have been added in the bundled patch > itself (see below). > > I was holding off on that patch of yours, because there has been no > resolution on that upstream PR (adding Khem in Cc so he can maybe have > a look back at it ;-) ). > > But following your comment on bug #16093, I decided to look again. I > just looked at the discussion in more details, and all the discussion > is basically just about how to name the symbol. So let's cary this patch > for now... > >> Signed-off-by: Fiona Klute <fiona.klute+wiwa@gmx.de> >> --- >> ...able-implementation-for-basename-API.patch | 131 ++++++++++++++++++ > > # ./utils/docker-run make check-package > package/kmod/0002-Use-portable-implementation-for-basename-API.patch:0: missing Upstream in the header (https://nightly.buildroot.org/#_additional_patch_documentation) > > This is where you should add the upstream PR URL: > > Upstream: https://github.com/kmod-project/kmod/pull/32 > > You must also sign-off the bundled patch. No need to respin, I can just > add it if you just reply with your SoB line. Signed-off-by: Fiona Klute <fiona.klute+wiwa@gmx.de> Thanks for taking care of this! If possible, please remove the subaddressing from the "From", somehow my mail provider seems to not deliver with it. I'll keep the "Upstream" tag in mind for the future. :-) Best regards, Fiona > Thanks! > > Regards, > Yann E. MORIN. > >> 1 file changed, 131 insertions(+) >> create mode 100644 package/kmod/0002-Use-portable-implementation-for-basename-API.patch >> >> diff --git a/package/kmod/0002-Use-portable-implementation-for-basename-API.patch b/package/kmod/0002-Use-portable-implementation-for-basename-API.patch >> new file mode 100644 >> index 0000000000..46d23f4fa9 >> --- /dev/null >> +++ b/package/kmod/0002-Use-portable-implementation-for-basename-API.patch >> @@ -0,0 +1,131 @@ >> +From 721ed6040c7aa47070faf6378c433089e178bd43 Mon Sep 17 00:00:00 2001 >> +From: Khem Raj <raj.khem@gmail.com> >> +Date: Sat, 9 Dec 2023 17:35:59 -0800 >> +Subject: [PATCH] Use portable implementation for basename API >> + >> +musl has removed the non-prototype declaration of basename from >> +string.h [1] which now results in build errors with clang-17+ compiler >> + >> +Implement GNU basename behavior using strchr which is portable across libcs >> + >> +Fixes >> +../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] >> +71 | "Commands:\n", basename(argv[0])); >> +| ^ >> + >> +[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 >> + >> +Suggested-by: Rich Felker >> + >> +Signed-off-by: Khem Raj <raj.khem@gmail.com> >> +--- >> + libkmod/libkmod-config.c | 2 +- >> + shared/util.c | 4 ++-- >> + shared/util.h | 7 +++++++ >> + testsuite/testsuite.c | 2 +- >> + tools/depmod.c | 2 +- >> + tools/kmod.c | 4 ++-- >> + 6 files changed, 14 insertions(+), 7 deletions(-) >> + >> +diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c >> +index e83621b3..8aa555a4 100644 >> +--- a/libkmod/libkmod-config.c >> ++++ b/libkmod/libkmod-config.c >> +@@ -794,7 +794,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx, >> + bool is_single = false; >> + >> + if (name == NULL) { >> +- name = basename(path); >> ++ name = gnu_basename(path); >> + is_single = true; >> + } >> + >> +diff --git a/shared/util.c b/shared/util.c >> +index e2bab83a..0e16670e 100644 >> +--- a/shared/util.c >> ++++ b/shared/util.c >> +@@ -172,9 +172,9 @@ char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t * >> + >> + char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len) >> + { >> +- char *modname; >> ++ const char *modname; >> + >> +- modname = basename(path); >> ++ modname = gnu_basename(path); >> + if (modname == NULL || modname[0] == '\0') >> + return NULL; >> + >> +diff --git a/shared/util.h b/shared/util.h >> +index c4a3916b..073dc5a7 100644 >> +--- a/shared/util.h >> ++++ b/shared/util.h >> +@@ -5,6 +5,7 @@ >> + #include <stdbool.h> >> + #include <stdlib.h> >> + #include <stdio.h> >> ++#include <string.h> >> + #include <sys/types.h> >> + #include <sys/stat.h> >> + #include <time.h> >> +@@ -76,6 +77,12 @@ do { \ >> + __p->__v = (val); \ >> + } while(0) >> + >> ++static _always_inline_ const char *gnu_basename(const char *s) >> ++{ >> ++ const char *p = strrchr(s, '/'); >> ++ return p ? p+1 : s; >> ++} >> ++ >> + static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u) >> + { >> + return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1)); >> +diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c >> +index 318343ac..aafc9873 100644 >> +--- a/testsuite/testsuite.c >> ++++ b/testsuite/testsuite.c >> +@@ -70,7 +70,7 @@ static void help(void) >> + >> + printf("Usage:\n" >> + "\t%s [options] <test>\n" >> +- "Options:\n", basename(progname)); >> ++ "Options:\n", gnu_basename(progname)); >> + >> + for (itr = options, itr_short = options_short; >> + itr->name != NULL; itr++, itr_short++) >> +diff --git a/tools/depmod.c b/tools/depmod.c >> +index 43fc354a..cfb15b11 100644 >> +--- a/tools/depmod.c >> ++++ b/tools/depmod.c >> +@@ -762,7 +762,7 @@ static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files >> + if (name != NULL) >> + namelen = strlen(name); >> + else { >> +- name = basename(dir); >> ++ name = gnu_basename(dir); >> + namelen = strlen(name); >> + dirlen -= namelen + 1; >> + } >> +diff --git a/tools/kmod.c b/tools/kmod.c >> +index 55689c07..df91e5c6 100644 >> +--- a/tools/kmod.c >> ++++ b/tools/kmod.c >> +@@ -68,7 +68,7 @@ static int kmod_help(int argc, char *argv[]) >> + "Options:\n" >> + "\t-V, --version show version\n" >> + "\t-h, --help show this help\n\n" >> +- "Commands:\n", basename(argv[0])); >> ++ "Commands:\n", gnu_basename(argv[0])); >> + >> + for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) { >> + if (kmod_cmds[i]->help != NULL) { >> +@@ -156,7 +156,7 @@ static int handle_kmod_compat_commands(int argc, char *argv[]) >> + const char *cmd; >> + size_t i; >> + >> +- cmd = basename(argv[0]); >> ++ cmd = gnu_basename(argv[0]); >> + >> + for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) { >> + if (streq(kmod_compat_cmds[i]->name, cmd)) >> -- >> 2.43.0 >> >> _______________________________________________ >> buildroot mailing list >> buildroot@buildroot.org >> https://lists.buildroot.org/mailman/listinfo/buildroot > -- Dipl.-Ing. Fiona Klute Mollwitzer Str. 2 44141 Dortmund Germany USt.-ID/VAT number: DE363488944
Fiona, All, On 2024-04-26 23:51 +0200, Fiona Klute via buildroot spake thusly: > From: Fiona Klute <fiona.klute+wiwa@gmx.de> > > Patch from upstream PR still being discussed: > https://github.com/kmod-project/kmod/pull/32 > > Signed-off-by: Fiona Klute <fiona.klute+wiwa@gmx.de> Applied to master, after adding your SoB line, and a reference to bug #16093, thanks. Regards, Yann E. MORIN. > --- > ...able-implementation-for-basename-API.patch | 131 ++++++++++++++++++ > 1 file changed, 131 insertions(+) > create mode 100644 package/kmod/0002-Use-portable-implementation-for-basename-API.patch > > diff --git a/package/kmod/0002-Use-portable-implementation-for-basename-API.patch b/package/kmod/0002-Use-portable-implementation-for-basename-API.patch > new file mode 100644 > index 0000000000..46d23f4fa9 > --- /dev/null > +++ b/package/kmod/0002-Use-portable-implementation-for-basename-API.patch > @@ -0,0 +1,131 @@ > +From 721ed6040c7aa47070faf6378c433089e178bd43 Mon Sep 17 00:00:00 2001 > +From: Khem Raj <raj.khem@gmail.com> > +Date: Sat, 9 Dec 2023 17:35:59 -0800 > +Subject: [PATCH] Use portable implementation for basename API > + > +musl has removed the non-prototype declaration of basename from > +string.h [1] which now results in build errors with clang-17+ compiler > + > +Implement GNU basename behavior using strchr which is portable across libcs > + > +Fixes > +../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] > +71 | "Commands:\n", basename(argv[0])); > +| ^ > + > +[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 > + > +Suggested-by: Rich Felker > + > +Signed-off-by: Khem Raj <raj.khem@gmail.com> > +--- > + libkmod/libkmod-config.c | 2 +- > + shared/util.c | 4 ++-- > + shared/util.h | 7 +++++++ > + testsuite/testsuite.c | 2 +- > + tools/depmod.c | 2 +- > + tools/kmod.c | 4 ++-- > + 6 files changed, 14 insertions(+), 7 deletions(-) > + > +diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c > +index e83621b3..8aa555a4 100644 > +--- a/libkmod/libkmod-config.c > ++++ b/libkmod/libkmod-config.c > +@@ -794,7 +794,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx, > + bool is_single = false; > + > + if (name == NULL) { > +- name = basename(path); > ++ name = gnu_basename(path); > + is_single = true; > + } > + > +diff --git a/shared/util.c b/shared/util.c > +index e2bab83a..0e16670e 100644 > +--- a/shared/util.c > ++++ b/shared/util.c > +@@ -172,9 +172,9 @@ char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t * > + > + char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len) > + { > +- char *modname; > ++ const char *modname; > + > +- modname = basename(path); > ++ modname = gnu_basename(path); > + if (modname == NULL || modname[0] == '\0') > + return NULL; > + > +diff --git a/shared/util.h b/shared/util.h > +index c4a3916b..073dc5a7 100644 > +--- a/shared/util.h > ++++ b/shared/util.h > +@@ -5,6 +5,7 @@ > + #include <stdbool.h> > + #include <stdlib.h> > + #include <stdio.h> > ++#include <string.h> > + #include <sys/types.h> > + #include <sys/stat.h> > + #include <time.h> > +@@ -76,6 +77,12 @@ do { \ > + __p->__v = (val); \ > + } while(0) > + > ++static _always_inline_ const char *gnu_basename(const char *s) > ++{ > ++ const char *p = strrchr(s, '/'); > ++ return p ? p+1 : s; > ++} > ++ > + static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u) > + { > + return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1)); > +diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c > +index 318343ac..aafc9873 100644 > +--- a/testsuite/testsuite.c > ++++ b/testsuite/testsuite.c > +@@ -70,7 +70,7 @@ static void help(void) > + > + printf("Usage:\n" > + "\t%s [options] <test>\n" > +- "Options:\n", basename(progname)); > ++ "Options:\n", gnu_basename(progname)); > + > + for (itr = options, itr_short = options_short; > + itr->name != NULL; itr++, itr_short++) > +diff --git a/tools/depmod.c b/tools/depmod.c > +index 43fc354a..cfb15b11 100644 > +--- a/tools/depmod.c > ++++ b/tools/depmod.c > +@@ -762,7 +762,7 @@ static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files > + if (name != NULL) > + namelen = strlen(name); > + else { > +- name = basename(dir); > ++ name = gnu_basename(dir); > + namelen = strlen(name); > + dirlen -= namelen + 1; > + } > +diff --git a/tools/kmod.c b/tools/kmod.c > +index 55689c07..df91e5c6 100644 > +--- a/tools/kmod.c > ++++ b/tools/kmod.c > +@@ -68,7 +68,7 @@ static int kmod_help(int argc, char *argv[]) > + "Options:\n" > + "\t-V, --version show version\n" > + "\t-h, --help show this help\n\n" > +- "Commands:\n", basename(argv[0])); > ++ "Commands:\n", gnu_basename(argv[0])); > + > + for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) { > + if (kmod_cmds[i]->help != NULL) { > +@@ -156,7 +156,7 @@ static int handle_kmod_compat_commands(int argc, char *argv[]) > + const char *cmd; > + size_t i; > + > +- cmd = basename(argv[0]); > ++ cmd = gnu_basename(argv[0]); > + > + for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) { > + if (streq(kmod_compat_cmds[i]->name, cmd)) > -- > 2.43.0 > > _______________________________________________ > buildroot mailing list > buildroot@buildroot.org > https://lists.buildroot.org/mailman/listinfo/buildroot
>>>>> "Yann" == Yann E MORIN <yann.morin.1998@free.fr> writes: > Fiona, All, > On 2024-04-26 23:51 +0200, Fiona Klute via buildroot spake thusly: >> From: Fiona Klute <fiona.klute+wiwa@gmx.de> >> >> Patch from upstream PR still being discussed: >> https://github.com/kmod-project/kmod/pull/32 >> >> Signed-off-by: Fiona Klute <fiona.klute+wiwa@gmx.de> > Applied to master, after adding your SoB line, and a reference to bug > #16093, thanks. Committed to 2024.02.x, thanks.
diff --git a/package/kmod/0002-Use-portable-implementation-for-basename-API.patch b/package/kmod/0002-Use-portable-implementation-for-basename-API.patch new file mode 100644 index 0000000000..46d23f4fa9 --- /dev/null +++ b/package/kmod/0002-Use-portable-implementation-for-basename-API.patch @@ -0,0 +1,131 @@ +From 721ed6040c7aa47070faf6378c433089e178bd43 Mon Sep 17 00:00:00 2001 +From: Khem Raj <raj.khem@gmail.com> +Date: Sat, 9 Dec 2023 17:35:59 -0800 +Subject: [PATCH] Use portable implementation for basename API + +musl has removed the non-prototype declaration of basename from +string.h [1] which now results in build errors with clang-17+ compiler + +Implement GNU basename behavior using strchr which is portable across libcs + +Fixes +../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] +71 | "Commands:\n", basename(argv[0])); +| ^ + +[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 + +Suggested-by: Rich Felker + +Signed-off-by: Khem Raj <raj.khem@gmail.com> +--- + libkmod/libkmod-config.c | 2 +- + shared/util.c | 4 ++-- + shared/util.h | 7 +++++++ + testsuite/testsuite.c | 2 +- + tools/depmod.c | 2 +- + tools/kmod.c | 4 ++-- + 6 files changed, 14 insertions(+), 7 deletions(-) + +diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c +index e83621b3..8aa555a4 100644 +--- a/libkmod/libkmod-config.c ++++ b/libkmod/libkmod-config.c +@@ -794,7 +794,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx, + bool is_single = false; + + if (name == NULL) { +- name = basename(path); ++ name = gnu_basename(path); + is_single = true; + } + +diff --git a/shared/util.c b/shared/util.c +index e2bab83a..0e16670e 100644 +--- a/shared/util.c ++++ b/shared/util.c +@@ -172,9 +172,9 @@ char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t * + + char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len) + { +- char *modname; ++ const char *modname; + +- modname = basename(path); ++ modname = gnu_basename(path); + if (modname == NULL || modname[0] == '\0') + return NULL; + +diff --git a/shared/util.h b/shared/util.h +index c4a3916b..073dc5a7 100644 +--- a/shared/util.h ++++ b/shared/util.h +@@ -5,6 +5,7 @@ + #include <stdbool.h> + #include <stdlib.h> + #include <stdio.h> ++#include <string.h> + #include <sys/types.h> + #include <sys/stat.h> + #include <time.h> +@@ -76,6 +77,12 @@ do { \ + __p->__v = (val); \ + } while(0) + ++static _always_inline_ const char *gnu_basename(const char *s) ++{ ++ const char *p = strrchr(s, '/'); ++ return p ? p+1 : s; ++} ++ + static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u) + { + return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1)); +diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c +index 318343ac..aafc9873 100644 +--- a/testsuite/testsuite.c ++++ b/testsuite/testsuite.c +@@ -70,7 +70,7 @@ static void help(void) + + printf("Usage:\n" + "\t%s [options] <test>\n" +- "Options:\n", basename(progname)); ++ "Options:\n", gnu_basename(progname)); + + for (itr = options, itr_short = options_short; + itr->name != NULL; itr++, itr_short++) +diff --git a/tools/depmod.c b/tools/depmod.c +index 43fc354a..cfb15b11 100644 +--- a/tools/depmod.c ++++ b/tools/depmod.c +@@ -762,7 +762,7 @@ static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files + if (name != NULL) + namelen = strlen(name); + else { +- name = basename(dir); ++ name = gnu_basename(dir); + namelen = strlen(name); + dirlen -= namelen + 1; + } +diff --git a/tools/kmod.c b/tools/kmod.c +index 55689c07..df91e5c6 100644 +--- a/tools/kmod.c ++++ b/tools/kmod.c +@@ -68,7 +68,7 @@ static int kmod_help(int argc, char *argv[]) + "Options:\n" + "\t-V, --version show version\n" + "\t-h, --help show this help\n\n" +- "Commands:\n", basename(argv[0])); ++ "Commands:\n", gnu_basename(argv[0])); + + for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) { + if (kmod_cmds[i]->help != NULL) { +@@ -156,7 +156,7 @@ static int handle_kmod_compat_commands(int argc, char *argv[]) + const char *cmd; + size_t i; + +- cmd = basename(argv[0]); ++ cmd = gnu_basename(argv[0]); + + for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) { + if (streq(kmod_compat_cmds[i]->name, cmd))