Skip to content

Commit fca5e94

Browse files
committed
samples: binderfs: really compile this sample and fix build issues
Even after commit c624adc ("samples: fix binderfs sample"), this sample is never compiled. 'hostprogs' teaches Kbuild that this is a host program, but not enough to order to compile it. You must add it to 'always-y' to really compile it. Since this sample has never been compiled in upstream, various issues are left unnoticed. [1] compilers without <linux/android/binderfs.h> are still widely used <linux/android/binderfs.h> is only available since commit c13295a ("binderfs: rename header to binderfs.h"), i.e., Linux 5.0 If your compiler is based on UAPI headers older than Linux 5.0, you will see the following error: samples/binderfs/binderfs_example.c:16:10: fatal error: linux/android/binderfs.h: No such file or directory #include <linux/android/binderfs.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. You cannot rely on compilers having such a new header. The common approach is to install UAPI headers of this kernel into usr/include, and then add it to the header search path. I added 'depends on HEADERS_INSTALL' in Kconfig, and '-I usr/include' compiler flag in Makefile. [2] compile the sample for target architecture Because headers_install works for the target architecture, only the native compiler was able to build sample code that requires '-I usr/include'. Commit 7f3a59d ("kbuild: add infrastructure to build userspace programs") added the new syntax 'userprogs' to compile user-space programs for the target architecture. Use it, and then 'ifndef CROSS_COMPILE' will go away. I added 'depends on CC_CAN_LINK' because $(CC) is not necessarily capable of linking user-space programs. [3] use subdir-y to descend into samples/binderfs Since this directory does not contain any kernel-space code, it has no point in generating built-in.a or modules.order. Replace obj-$(CONFIG_...) with subdir-$(CONFIG_...). [4] -Wunused-variable warning If I compile this, I see the following warning. samples/binderfs/binderfs_example.c: In function 'main': samples/binderfs/binderfs_example.c:21:9: warning: unused variable 'len' [-Wunused-variable] 21 | size_t len; | ^~~ I removed the unused 'len'. [5] CONFIG_ANDROID_BINDERFS is not required Since this is a user-space standalone program, it is independent of the kernel configuration. Remove 'depends on ANDROID_BINDERFS'. Fixes: 9762dc1 ("samples: add binderfs sample program") Fixes: c624adc ("samples: fix binderfs sample") Signed-off-by: Masahiro Yamada <[email protected]> Acked-by: Christian Brauner <[email protected]>
1 parent b29482f commit fca5e94

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

samples/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ config SAMPLE_VFIO_MDEV_MBOCHS
185185

186186
config SAMPLE_ANDROID_BINDERFS
187187
bool "Build Android binderfs example"
188-
depends on ANDROID_BINDERFS
188+
depends on CC_CAN_LINK && HEADERS_INSTALL
189189
help
190190
Builds a sample program to illustrate the use of the Android binderfs
191191
filesystem.

samples/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Makefile for Linux samples code
33

44
subdir-$(CONFIG_SAMPLE_AUXDISPLAY) += auxdisplay
5-
obj-$(CONFIG_SAMPLE_ANDROID_BINDERFS) += binderfs/
5+
subdir-$(CONFIG_SAMPLE_ANDROID_BINDERFS) += binderfs
66
obj-$(CONFIG_SAMPLE_CONFIGFS) += configfs/
77
obj-$(CONFIG_SAMPLE_CONNECTOR) += connector/
88
subdir-$(CONFIG_SAMPLE_HIDRAW) += hidraw

samples/binderfs/Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
ifndef CROSS_COMPILE
3-
ifdef CONFIG_SAMPLE_ANDROID_BINDERFS
4-
hostprogs := binderfs_example
5-
endif
6-
endif
2+
userprogs := binderfs_example
3+
always-y := $(userprogs)
4+
5+
userccflags += -I usr/include

samples/binderfs/binderfs_example.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
int main(int argc, char *argv[])
1919
{
2020
int fd, ret, saved_errno;
21-
size_t len;
2221
struct binderfs_device device = { 0 };
2322

2423
ret = unshare(CLONE_NEWNS);

0 commit comments

Comments
 (0)