Skip to content

lxcfs fails to build with Clang on glibc 2.43 #707

@listout

Description

@listout

Building on Glibc 2.43 with Clang fails with the following error message. I'm using Gentoo's LLVM profile.

Gentoo bug: https://bugs.gentoo.org/970543

NFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C /tmp/lxcfs/build
ninja: Entering directory `/tmp/lxcfs/build'
[1/21] Compiling C object liblxcfs.so.p/src_cpuset_parse.c.o
FAILED: [code=1] liblxcfs.so.p/src_cpuset_parse.c.o
clang -Iliblxcfs.so.p -I. -I.. -I/usr/include/fuse3 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wvla -Wcast-align -Wstrict-prototypes -fno-strict-aliasing -fstack-clash-protection -fstack-protector-strong --param=ssp-buffer-size=4 -Werror=implicit-function-declaration -Wmissing-include-dirs -Wold-style-definition -Winit-self -Wunused-but-set-variable -Wno-unused-parameter -Wfloat-equal -Werror=return-type -Werror=incompatible-pointer-types -Wformat=2 -Wshadow -Wendif-labels -Werror=overflow -fdiagnostics-show-option -Werror=shift-count-overflow -Wdate-time -Wnested-externs -fasynchronous-unwind-tables -fexceptions -Warray-bounds -Wreturn-local-addr -include config.h -fPIC -pthread -MD -MQ liblxcfs.so.p/src_cpuset_parse.c.o -MF liblxcfs.so.p/src_cpuset_parse.c.o.d -o liblxcfs.so.p/src_cpuset_parse.c.o -c ../src/cpuset_parse.c
../src/cpuset_parse.c:24:4: error: assigning to 'char *' from 'const char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
   24 |         r = strchr(c + 1, ',');
      |           ^ ~~~~~~~~~~~~~~~~~~
1 error generated.
[6/21] Compiling C object liblxcfs.so.p/src_cgroup_fuse.c.o
FAILED: [code=1] liblxcfs.so.p/src_cgroup_fuse.c.o
clang -Iliblxcfs.so.p -I. -I.. -I/usr/include/fuse3 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wvla -Wcast-align -Wstrict-prototypes -fno-strict-aliasing -fstack-clash-protection -fstack-protector-strong --param=ssp-buffer-size=4 -Werror=implicit-function-declaration -Wmissing-include-dirs -Wold-style-definition -Winit-self -Wunused-but-set-variable -Wno-unused-parameter -Wfloat-equal -Werror=return-type -Werror=incompatible-pointer-types -Wformat=2 -Wshadow -Wendif-labels -Werror=overflow -fdiagnostics-show-option -Werror=shift-count-overflow -Wdate-time -Wnested-externs -fasynchronous-unwind-tables -fexceptions -Warray-bounds -Wreturn-local-addr -include config.h -fPIC -pthread -MD -MQ liblxcfs.so.p/src_cgroup_fuse.c.o -MF liblxcfs.so.p/src_cgroup_fuse.c.o.d -o liblxcfs.so.p/src_cgroup_fuse.c.o -c ../src/cgroup_fuse.c
../src/cgroup_fuse.c:148:8: error: assigning to 'char *' from 'const char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
  148 |         *last = strrchr(cg, '/');
      |               ^ ~~~~~~~~~~~~~~~~
1 error generated.
[18/21] Compiling C object liblxcfs.so.p/src_proc_fuse.c.o
ninja: build stopped: subcommand failed.

Steps to reproduce:

  1. git clone https://github.com/lxc/lxcfs.git
  2. CC=clang meson setup -Dinit-script="" -Dwith-init-script="" --prefix=/usr build/
  3. CC=clang meson compile -C build/

Looking through the source code, can we do something like

--- a/src/cgroup_fuse.c
+++ b/src/cgroup_fuse.c
@@ -145,7 +145,7 @@ static void get_cgdir_and_path(const char *cg, char **dir, char **last)
 	do {
 		*dir = strdup(cg);
 	} while (!*dir);
-	*last = strrchr(cg, '/');
+	*last = (char *) strrchr(cg, '/');
 	if (!*last) {
 		*last = NULL;
 		return;
diff --git a/src/cpuset_parse.c b/src/cpuset_parse.c
index 053aff1e5eec..d3dcb23da18a 100644
--- a/src/cpuset_parse.c
+++ b/src/cpuset_parse.c
@@ -21,7 +21,7 @@ static char *cpuset_nexttok(const char *c)
 	if (!strlen(c))
 		return NULL;
 
-	r = strchr(c + 1, ',');
+	r = (char *) strchr(c + 1, ',');
 	return r ? (r + 1) : NULL;
 }

or (taking idea from rockowitz/ddcutil@23d9938)

--- a/src/cgroup_fuse.c
+++ b/src/cgroup_fuse.c
@@ -145,7 +145,14 @@ static void get_cgdir_and_path(const char *cg, char **dir, char **last)
 	do {
 		*dir = strdup(cg);
 	} while (!*dir);
-	*last = strrchr(cg, '/');
+
+	char *tmp = strdup(cg);
+	if (!tmp) {
+		*last = NULL;
+		return;
+	}
+
+	*last = strrchr(tmp, '/');
 	if (!*last) {
 		*last = NULL;
 		return;
--- a/src/cpuset_parse.c
+++ b/src/cpuset_parse.c
@@ -21,7 +21,11 @@ static char *cpuset_nexttok(const char *c)
 	if (!strlen(c))
 		return NULL;
 
-	r = strchr(c + 1, ',');
+	char *tmp = strdup(c);
+	if (!tmp)
+		return NULL;
+
+	r = strchr(tmp + 1, ',');
 	return r ? (r + 1) : NULL;
 }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions