Skip to content

Commit 1158655

Browse files
johnhubbardshuahkh
authored andcommitted
selftests/x86: build fsgsbase_restore.c with clang
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 <[email protected]> Signed-off-by: John Hubbard <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent bf967fb commit 1158655

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

tools/testing/selftests/x86/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ endef
113113
$(eval $(call extra-files,sysret_ss_attrs_64,thunks.S))
114114
$(eval $(call extra-files,ptrace_syscall_32,raw_syscall_helper_32.S))
115115
$(eval $(call extra-files,test_syscall_vdso_32,thunks_32.S))
116+
$(eval $(call extra-files,fsgsbase_restore_64,clang_helpers_64.S))
117+
$(eval $(call extra-files,fsgsbase_restore_32,clang_helpers_32.S))
116118

117119
# check_initial_reg_state is special: it needs a custom entry, and it
118120
# needs to be static so that its interpreter doesn't destroy its initial
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* 32-bit assembly helpers for asm operations that lack support in both gcc and
4+
* clang. For example, clang asm does not support segment prefixes.
5+
*/
6+
.global dereference_seg_base
7+
dereference_seg_base:
8+
mov %fs:(0), %eax
9+
ret
10+
11+
.section .note.GNU-stack,"",%progbits
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* 64-bit assembly helpers for asm operations that lack support in both gcc and
4+
* clang. For example, clang asm does not support segment prefixes.
5+
*/
6+
.global dereference_seg_base
7+
8+
dereference_seg_base:
9+
mov %gs:(0), %rax
10+
ret
11+
12+
.section .note.GNU-stack,"",%progbits

tools/testing/selftests/x86/fsgsbase_restore.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@
3939
# define SEG "%fs"
4040
#endif
4141

42-
static unsigned int dereference_seg_base(void)
43-
{
44-
int ret;
45-
asm volatile ("mov %" SEG ":(0), %0" : "=rm" (ret));
46-
return ret;
47-
}
42+
/*
43+
* Defined in clang_helpers_[32|64].S, because unlike gcc, clang inline asm does
44+
* not support segmentation prefixes.
45+
*/
46+
unsigned int dereference_seg_base(void);
4847

4948
static void init_seg(void)
5049
{

0 commit comments

Comments
 (0)