Skip to content

Commit 825658b

Browse files
johnhubbardshuahkh
authored andcommitted
selftests/x86: fix Makefile dependencies to work with clang
When building with clang, via: make LLVM=1 -C tools/testing/selftests ...the following build failure occurs in selftests/x86: clang: error: cannot specify -o when generating multiple output files This happens because, although gcc doesn't complain if you invoke it like this: gcc file1.c header2.h ...clang won't accept that form--it rejects the .h file(s). Also, the above approach is inaccurate anyway, because file.c includes header2.h in this case, and the inclusion of header2.h on the invocation is an artifact of the Makefile's desire to maintain dependencies. In Makefiles of this type, a better way to do it is to use Makefile dependencies to trigger the appropriate incremental rebuilds, and separately use file lists (see EXTRA_FILES in this commit) to track what to pass to the compiler. This commit splits those concepts up, by setting up both EXTRA_FILES and the Makefile dependencies with a single call to the new Makefile function extra-files. That fixes the build failure, while still providing the correct dependencies in all cases. Acked-by: Muhammad Usama Anjum <[email protected]> Signed-off-by: John Hubbard <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 4eddfaf commit 825658b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tools/testing/selftests/x86/Makefile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ all_64: $(BINARIES_64)
7373
EXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64)
7474

7575
$(BINARIES_32): $(OUTPUT)/%_32: %.c helpers.h
76-
$(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
76+
$(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $< $(EXTRA_FILES) -lrt -ldl -lm
7777

7878
$(BINARIES_64): $(OUTPUT)/%_64: %.c helpers.h
79-
$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
79+
$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $< $(EXTRA_FILES) -lrt -ldl
8080

8181
# x86_64 users should be encouraged to install 32-bit libraries
8282
ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
@@ -100,10 +100,19 @@ warn_32bit_failure:
100100
exit 0;
101101
endif
102102

103-
# Some tests have additional dependencies.
104-
$(OUTPUT)/sysret_ss_attrs_64: thunks.S
105-
$(OUTPUT)/ptrace_syscall_32: raw_syscall_helper_32.S
106-
$(OUTPUT)/test_syscall_vdso_32: thunks_32.S
103+
# Add an additional file to the source file list for a given target, and also
104+
# add a Makefile dependency on that same file. However, do these separately, so
105+
# that the compiler invocation ("$(CC) file1.c file2.S") is not combined with
106+
# the dependencies ("header3.h"), because clang, unlike gcc, will not accept
107+
# header files as an input to the compiler invocation.
108+
define extra-files
109+
$(OUTPUT)/$(1): EXTRA_FILES := $(2)
110+
$(OUTPUT)/$(1): $(2)
111+
endef
112+
113+
$(eval $(call extra-files,sysret_ss_attrs_64,thunks.S))
114+
$(eval $(call extra-files,ptrace_syscall_32,raw_syscall_helper_32.S))
115+
$(eval $(call extra-files,test_syscall_vdso_32,thunks_32.S))
107116

108117
# check_initial_reg_state is special: it needs a custom entry, and it
109118
# needs to be static so that its interpreter doesn't destroy its initial

0 commit comments

Comments
 (0)