]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/x86: build fsgsbase_restore.c with clang
authorJohn Hubbard <jhubbard@nvidia.com>
Thu, 4 Jul 2024 07:24:27 +0000 (00:24 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 11 Jul 2024 17:23:55 +0000 (11:23 -0600)
When building with clang, via:

    make LLVM=1 -C tools/testing/selftests

Fix this by moving the inline asm to "pure" assembly, in two new files:
clang_helpers_32.S, clang_helpers_64.S.

As a bonus, the pure asm avoids the need for ifdefs, and is now very
simple and easy on the eyes.

Acked-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/x86/Makefile
tools/testing/selftests/x86/clang_helpers_32.S [new file with mode: 0644]
tools/testing/selftests/x86/clang_helpers_64.S [new file with mode: 0644]
tools/testing/selftests/x86/fsgsbase_restore.c

index c1269466e0f8676bc0bcb6d4e51fa9d8d50a6c13..99bc2ef84f5a67e49efa82d515cec91a339786c3 100644 (file)
@@ -113,6 +113,8 @@ endef
 $(eval $(call extra-files,sysret_ss_attrs_64,thunks.S))
 $(eval $(call extra-files,ptrace_syscall_32,raw_syscall_helper_32.S))
 $(eval $(call extra-files,test_syscall_vdso_32,thunks_32.S))
+$(eval $(call extra-files,fsgsbase_restore_64,clang_helpers_64.S))
+$(eval $(call extra-files,fsgsbase_restore_32,clang_helpers_32.S))
 
 # check_initial_reg_state is special: it needs a custom entry, and it
 # needs to be static so that its interpreter doesn't destroy its initial
diff --git a/tools/testing/selftests/x86/clang_helpers_32.S b/tools/testing/selftests/x86/clang_helpers_32.S
new file mode 100644 (file)
index 0000000..dc16271
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * 32-bit assembly helpers for asm operations that lack support in both gcc and
+ * clang. For example, clang asm does not support segment prefixes.
+ */
+.global dereference_seg_base
+dereference_seg_base:
+       mov %fs:(0), %eax
+       ret
+
+.section .note.GNU-stack,"",%progbits
diff --git a/tools/testing/selftests/x86/clang_helpers_64.S b/tools/testing/selftests/x86/clang_helpers_64.S
new file mode 100644 (file)
index 0000000..0d81c71
--- /dev/null
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * 64-bit assembly helpers for asm operations that lack support in both gcc and
+ * clang. For example, clang asm does not support segment prefixes.
+ */
+.global dereference_seg_base
+
+dereference_seg_base:
+       mov %gs:(0), %rax
+       ret
+
+.section .note.GNU-stack,"",%progbits
index 6fffadc5157911b057ccccae1d9310410f666d6d..224058c1e4b2ee44ff25e25fd161483af0e00fcb 100644 (file)
 # define SEG "%fs"
 #endif
 
-static unsigned int dereference_seg_base(void)
-{
-       int ret;
-       asm volatile ("mov %" SEG ":(0), %0" : "=rm" (ret));
-       return ret;
-}
+/*
+ * Defined in clang_helpers_[32|64].S, because unlike gcc, clang inline asm does
+ * not support segmentation prefixes.
+ */
+unsigned int dereference_seg_base(void);
 
 static void init_seg(void)
 {