lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Tue,  5 Oct 2021 22:27:39 +0000
From:   Andrew Delgadilo <>
To:     Shuah Khan <>,,
Cc:     Nathan Chancellor <>,
        Nick Desaulniers <>,,
        Andrew Delgadillo <>
Subject: [PATCH v2] selftests: Include directories of header files

From: Andrew Delgadillo <>

clang complains about using -o when one specifies header files on the
commandline. An example can be seen when building the futex selftests:

$ make -C tools/testing/selftests TARGETS=futex
clang -Wall   -g -O2 -Wall -D_GNU_SOURCE -pthread -I../include \
-I../../ -I../../../../../usr/include/ -I/kselftest/usr/include \
futex_wait_timeout.c ../include/futextest.h ../include/atomic.h \
../include/logging.h -lpthread -lrt -o \
clang: error: cannot specify -o when generating multiple output files

To fix this, instead of specifying the headers explicitliy, we include
(with -I) their directories. Note that -I does not work with files, only
directories [1,2]

There are still errors when building with clang, but this patch does a
way with one class of those errors.

Tested: No new errors when building with LLVM=0/1. In fact, clang no
longer errors out with "cannot specify -o ..." anymore.


Signed-off-by: Andrew Delgadillo <>
Changes since v1:
- Instead of removing the headers from the cmdline altogether, include
  their directories.
- Add more detail to the tested tag.
- Add missing Suggested-By tag from original patch.

 tools/testing/selftests/filesystems/binderfs/Makefile | 4 ++--
 tools/testing/selftests/                        | 5 ++++-
 tools/testing/selftests/x86/Makefile                  | 4 ++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/filesystems/binderfs/Makefile b/tools/testing/selftests/filesystems/binderfs/Makefile
index 8af25ae96049..e2f09acb15b4 100644
--- a/tools/testing/selftests/filesystems/binderfs/Makefile
+++ b/tools/testing/selftests/filesystems/binderfs/Makefile
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
-CFLAGS += -I../../../../../usr/include/ -pthread
+CFLAGS += -I../../../../../usr/include/ -I$(selfdir) -pthread
 TEST_GEN_PROGS := binderfs_test
-binderfs_test: binderfs_test.c ../../kselftest.h ../../kselftest_harness.h
+binderfs_test: binderfs_test.c
 include ../../
diff --git a/tools/testing/selftests/ b/tools/testing/selftests/
index fa2ac0e56b43..0edf2a421771 100644
--- a/tools/testing/selftests/
+++ b/tools/testing/selftests/
@@ -137,12 +137,15 @@ COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
 # Selftest makefiles can override those targets by setting
 LOCAL_HDRS := $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
 $(OUTPUT)/%:%.c $(LOCAL_HDRS)
-	$(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@
+	$(LINK.c) $(filter-out %.h,$^) \
+		$(addprefix -I,$(dir $(filter %.h,$^))) \
+			$(LDLIBS) -o $@
 	$(COMPILE.S) $^ -o $@
diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests/x86/Makefile
index b4142cd1c5c2..f794d431f289 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -72,10 +72,10 @@ all_64: $(BINARIES_64)
 $(BINARIES_32): $(OUTPUT)/%_32: %.c helpers.h
-	$(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
+	$(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $(filter-out %.h,$^) $(addprefix -I,$(dir $(filter %.h,$^))) -lrt -ldl -lm
 $(BINARIES_64): $(OUTPUT)/%_64: %.c helpers.h
-	$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
+	$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $(filter-out %.h,$^) $(addprefix -I,$(dir $(filter %.h,$^))) -lrt -ldl
 # x86_64 users should be encouraged to install 32-bit libraries
 ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)

Powered by blists - more mailing lists