Procházet zdrojové kódy

package/libapparmor: fix build w/ musl

When building the libapparmor package with musl the following error
would appear:

```
test_multi.c: In function 'main':
test_multi.c:27:30: error: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
   27 |         printf("File: %s\n", basename(argv[1]));
      |                              ^~~~~~~~
test_multi.c:27:24: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
   27 |         printf("File: %s\n", basename(argv[1]));
      |                       ~^     ~~~~~~~~~~~~~~~~~
      |                        |     |
      |                        |     int
      |                        char *
      |                       %d
make[3]: *** [Makefile:466: test_multi_multi-test_multi.o] Error 1
```

This error can be reproduced with the following:

```
cat >.config <<EOF
BR2_aarch64=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_AARCH64_MUSL_BLEEDING_EDGE=y
BR2_PACKAGE_LIBAPPARMOR=y
EOF
make olddefconfig
make libapparmor
```

On musl libc the function `basename` is provided by included libgen.h.
This error has been addressed upstream in [1] by re-defining the
function `basename`.

[1] https://gitlab.com/apparmor/apparmor/-/commit/7fb040bde69ebdfce48cf1a01c1a62fd4f8eef0a

Signed-off-by: Thomas Perale <thomas.perale@mind.be>
[Peter: drop unrelated AUTORECONF change]
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Thomas Perale před 5 dny
rodič
revize
2640f5dcd0

+ 44 - 0
package/libapparmor/0001-libapparamor-define-a-portable-version-of-gnu-basename.patch

@@ -0,0 +1,44 @@
+From 7fb040bde69ebdfce48cf1a01c1a62fd4f8eef0a Mon Sep 17 00:00:00 2001
+From: Jules Maselbas <jmaselbas@zdiv.net>
+Date: Thu, 16 May 2024 12:01:00 +0200
+Subject: [PATCH] libapparamor: Define a portable version of gnu basename
+
+Since musl 1.2.5, basename(3) prototype is only provided in libgen.h
+(as mandated by POSIX) and not in strings.h. Also there is a major
+difference between the gnu basename and the one defined in libgen.h,
+the latter modify the argument string making them incompatible.
+
+Fix this by defining a portable version of basename using strchr.
+
+Upstream: https://gitlab.com/apparmor/apparmor/-/commit/7fb040bde69ebdfce48cf1a01c1a62fd4f8eef0a
+Signed-off-by: Thomas Perale <thomas.perale@mind.be>
+---
+ libraries/libapparmor/testsuite/test_multi.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/libraries/libapparmor/testsuite/test_multi.c b/libraries/libapparmor/testsuite/test_multi.c
+index 578629500..7f37966ec 100644
+--- a/libraries/libapparmor/testsuite/test_multi.c
++++ b/libraries/libapparmor/testsuite/test_multi.c
+@@ -1,5 +1,3 @@
+-#define _GNU_SOURCE /* for glibc's basename version */
+-
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -7,6 +5,12 @@
+ 
+ #include <aalogparse.h>
+ 
++static const char *basename(const char *path)
++{
++	const char *p = strrchr(path, '/');
++	return p ? p + 1 : path;
++}
++
+ int print_results(aa_log_record *record);
+ 
+ int main(int argc, char **argv)
+-- 
+GitLab
+