Skip to contentSkip to conversation

utest: fix build with musl + clang >=15

PATCH In review Miko Larsson 2 participants 7 messages Feb 22, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover utest: fix build with musl + clang >=15

Clang 15 onwards defaults to -Werror=implicit-function-declaration which, combined with musl not declaring all the stuff we need without the missing includes and defines, breaks the utest build. This series fixes thus by simply adding the missing stuff.

---
Changes in v2:
- Better commit descriptions, messages
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Miko Larsson (3):
utest/tracefs-utest: include linux/limits.h utest/tracefs-utest: define _LARGEFILE64_SOURCE utest/trace-utest: include libgen.h

 utest/trace-utest.c   | 1 +
 utest/tracefs-utest.c | 4 ++++
 2 files changed, 5 insertions(+)

---
base-commit: 5f27b7f3fb7d88b29522baf3883cc0e2e28b1af0
change-id: 20240215-utest-fixes-893315be225b

Best regards,

Signature · 1 line
Miko Larsson <[email protected]>
#1 lore raw

PATCH v2 1/3 utest/tracefs-utest: include linux/limits.h

This fixes the build with musl + clang >=15; musl doesn't define PATH_MAX anywhere else, and clang >=15 doesn't allow implicit declarations with >=c99. Without this, the build fails due to PATH_MAX not being defined.

We could include limits.h from the libc, but AFAIK the libc doesn't necessarily have to define PATH_MAX, so it's safer to just include linux/limits.h

Fixes 845f16976929 ("libtracefs: Add unit tests")
---
 utest/tracefs-utest.c | 2 ++
 1 file changed, 2 insertions(+)
utest/tracefs-utest.c +2 -0
index 963fac7..70bcf3e 100644
@@ -16,6 +16,8 @@
 #include <kbuffer.h>
 #include <pthread.h>
 
+#include <linux/limits.h>
+
 #include <sys/mount.h>
 #include <sys/syscall.h>
 
Signature · 1 line
2.43.0
#5 lore raw

PATCH v2 2/3 utest/tracefs-utest: define _LARGEFILE64_SOURCE

In reply to Miko Larsson

This fixes the build with musl + clang >=15; musl doesn't declare lseek64() otherwise, and clang >=15 doesn't allow implicit declarations.

Fixes 0f45e68cb04a ("libtracefs: Add unit tests for tracefs_cpu functions")
---
 utest/tracefs-utest.c | 2 ++
 1 file changed, 2 insertions(+)
utest/tracefs-utest.c +2 -0
index 70bcf3e..224903b 100644
@@ -3,6 +3,8 @@
  * Copyright (C) 2020, VMware, Tzvetomir Stoyanov <[email protected]>
  *
  */
+#define _LARGEFILE64_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
Signature · 1 line
2.43.0
#6 lore raw

PATCH v2 3/3 utest/trace-utest: include libgen.h

In reply to Miko Larsson

This fixes the build with musl + clang >=15; musl doesn't declare basename() anywhere else, and clang >=15 doesn't allow implicit declarations.

Fixes 845f16976929 ("libtracefs: Add unit tests")
---
 utest/trace-utest.c | 1 +
 1 file changed, 1 insertion(+)
utest/trace-utest.c +1 -0
index 58d4d4e..39485a1 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2020, VMware, Tzvetomir Stoyanov <[email protected]>
  *
  */
+#include <libgen.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <getopt.h>
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 1/3] utest/tracefs-utest: include linux/limits.h

In reply to Miko Larsson
Quoted 10 lines · On Thu, 22 Feb 2024 11:12:44 +0100 Miko Larsson via B4 Relay…

From: Miko Larsson <[email protected]>

This fixes the build with musl + clang >=15; musl doesn't define PATH_MAX anywhere else, and clang >=15 doesn't allow implicit declarations with >=c99. Without this, the build fails due to PATH_MAX not being defined.

We could include limits.h from the libc, but AFAIK the libc doesn't necessarily have to define PATH_MAX, so it's safer to just include linux/limits.h

Actually, the way I handle PATH_MAX is to add:

#ifndef PATH_MAX
#define PATH_MAX 1024
#endif

As it's not really used, but just a default value to be able to add any paths used in the tracefs directory, where 1024 is more than enough.

-- Steve

#3 lore raw

Re: [PATCH v2 1/3] utest/tracefs-utest: include linux/limits.h

Quoted 14 lines · On Thu, 22 Feb 2024 09:53:45 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 10 lines · On Thu, 22 Feb 2024 11:12:44 +0100 Miko Larsson via B4 Relay…

From: Miko Larsson <[email protected]>

This fixes the build with musl + clang >=15; musl doesn't define PATH_MAX anywhere else, and clang >=15 doesn't allow implicit declarations with >=c99. Without this, the build fails due to PATH_MAX not being defined.

We could include limits.h from the libc, but AFAIK the libc doesn't necessarily have to define PATH_MAX, so it's safer to just include linux/limits.h

Quoted 8 lines

Actually, the way I handle PATH_MAX is to add:

#ifndef PATH_MAX
#define PATH_MAX 1024
#endif

As it's not really used, but just a default value to be able to add any paths used in the tracefs directory, where 1024 is more than enough.

I'm going to apply your other two patches, but I created a patch with the added code above, and will be posting that shortly.

-- Steve

#4 lore raw

Re: [PATCH v2 1/3] utest/tracefs-utest: include linux/limits.h

Quoted 2 lines · Steven Rostedt

I'm going to apply your other two patches, but I created a patch with the added code above, and will be posting that shortly.

Thanks!