Skip to content

Commit cb8b69b

Browse files
author
Fox Snowpatch
committed
1 parent 5c2c0ba commit cb8b69b

4 files changed

Lines changed: 61 additions & 37 deletions

File tree

arch/powerpc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ config PPC
286286
select HAVE_REGS_AND_STACK_ACCESS_API
287287
select HAVE_RELIABLE_STACKTRACE
288288
select HAVE_RSEQ
289+
select HAVE_RUST if PPC32
290+
select HAVE_RUST if PPC64 && CPU_LITTLE_ENDIAN
289291
select HAVE_SAMPLE_FTRACE_DIRECT if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
290292
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
291293
select HAVE_SETUP_PER_CPU_AREA if PPC64

arch/powerpc/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ else
6161
KBUILD_LDFLAGS_MODULE += $(objtree)/arch/powerpc/lib/crtsavres.o
6262
endif
6363

64+
ifdef CONFIG_PPC64
65+
KBUILD_RUSTFLAGS += --target=powerpc64le-unknown-linux-gnu
66+
KBUILD_RUSTFLAGS += -Ctarget-feature=-mma,-vsx,-hard-float,-altivec
67+
else
68+
KBUILD_RUSTFLAGS += --target=powerpc-unknown-linux-gnu
69+
endif
70+
6471
ifdef CONFIG_CPU_LITTLE_ENDIAN
6572
KBUILD_CPPFLAGS += -mlittle-endian
6673
KBUILD_LDFLAGS += -EL

arch/powerpc/include/asm/jump_label.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@
1515
#define JUMP_ENTRY_TYPE stringify_in_c(FTR_ENTRY_LONG)
1616
#define JUMP_LABEL_NOP_SIZE 4
1717

18+
#define JUMP_TABLE_ENTRY(key, label) \
19+
".pushsection __jump_table, \"aw\" \n\t" \
20+
".long 1b - ., " label " - . \n\t" \
21+
JUMP_ENTRY_TYPE key " - . \n\t" \
22+
".popsection \n\t"
23+
24+
#define ARCH_STATIC_BRANCH_ASM(key, label) \
25+
"1: nop \n\t" \
26+
JUMP_TABLE_ENTRY(key, label)
27+
1828
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
1929
{
20-
asm goto("1:\n\t"
21-
"nop # arch_static_branch\n\t"
22-
".pushsection __jump_table, \"aw\"\n\t"
23-
".long 1b - ., %l[l_yes] - .\n\t"
24-
JUMP_ENTRY_TYPE "%c0 - .\n\t"
25-
".popsection \n\t"
30+
asm goto(
31+
ARCH_STATIC_BRANCH_ASM("%c0", "%l[l_yes]")
2632
: : "i" (&((char *)key)[branch]) : : l_yes);
2733

2834
return false;
@@ -34,10 +40,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool
3440
{
3541
asm goto("1:\n\t"
3642
"b %l[l_yes] # arch_static_branch_jump\n\t"
37-
".pushsection __jump_table, \"aw\"\n\t"
38-
".long 1b - ., %l[l_yes] - .\n\t"
39-
JUMP_ENTRY_TYPE "%c0 - .\n\t"
40-
".popsection \n\t"
43+
JUMP_TABLE_ENTRY("%c0", "%l[l_yes]")
4144
: : "i" (&((char *)key)[branch]) : : l_yes);
4245

4346
return false;

rust/Makefile

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Where to place rustdoc generated documentation
44
rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
55

6+
# Clean generated host directory
7+
clean-files := host/
8+
69
obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o
710
always-$(CONFIG_RUST) += exports_core_generated.h
811

@@ -27,7 +30,7 @@ endif
2730

2831
obj-$(CONFIG_RUST) += exports.o
2932

30-
always-$(CONFIG_RUST) += libproc_macro2.rlib libquote.rlib libsyn.rlib
33+
always-$(CONFIG_RUST) += host/libproc_macro2.rlib host/libquote.rlib host/libsyn.rlib
3134

3235
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
3336
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
@@ -49,7 +52,7 @@ libmacros_extension := $(patsubst libmacros.%,%,$(libmacros_name))
4952
libpin_init_internal_name := $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name pin_init_internal --crate-type proc-macro - </dev/null)
5053
libpin_init_internal_extension := $(patsubst libpin_init_internal.%,%,$(libpin_init_internal_name))
5154

52-
always-$(CONFIG_RUST) += $(libmacros_name) $(libpin_init_internal_name)
55+
always-$(CONFIG_RUST) += host/$(libmacros_name) host/$(libpin_init_internal_name)
5356

5457
# `$(rust_flags)` is passed in case the user added `--sysroot`.
5558
rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot)
@@ -150,7 +153,7 @@ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
150153
OBJTREE=$(abspath $(objtree)) \
151154
$(RUSTDOC) $(filter-out $(skip_flags) --remap-path-prefix=% --remap-path-scope=%, \
152155
$(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \
153-
$(rustc_target_flags) -L$(objtree)/$(obj) \
156+
$(rustc_target_flags) -L$(objtree)/$(obj)$(if $(rustdoc_host),/host) \
154157
-Zunstable-options --generate-link-to-definition \
155158
--output $(rustdoc_output) \
156159
--crate-name $(subst rustdoc-,,$@) \
@@ -247,7 +250,7 @@ rustdoc-kernel: private rustc_target_flags = --extern ffi --extern pin_init \
247250
--extern build_error --extern macros \
248251
--extern bindings --extern uapi
249252
rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-ffi rustdoc-macros \
250-
rustdoc-pin_init rustdoc-compiler_builtins $(obj)/$(libmacros_name) \
253+
rustdoc-pin_init rustdoc-compiler_builtins $(obj)/host/$(libmacros_name) \
251254
$(obj)/bindings.o FORCE
252255
+$(call if_changed,rustdoc)
253256

@@ -299,14 +302,14 @@ rusttestlib-pin_init_internal: $(src)/pin-init/internal/src/lib.rs \
299302

300303
rusttestlib-pin_init: private rustc_target_flags = $(pin_init-flags)
301304
rusttestlib-pin_init: $(src)/pin-init/src/lib.rs rusttestlib-macros \
302-
rusttestlib-pin_init_internal $(obj)/$(libpin_init_internal_name) FORCE
305+
rusttestlib-pin_init_internal $(obj)/host/$(libpin_init_internal_name) FORCE
303306
+$(call if_changed,rustc_test_library)
304307

305308
rusttestlib-kernel: private rustc_target_flags = --extern ffi \
306309
--extern build_error --extern macros --extern pin_init \
307310
--extern bindings --extern uapi
308311
rusttestlib-kernel: $(src)/kernel/lib.rs rusttestlib-bindings rusttestlib-uapi \
309-
rusttestlib-build_error rusttestlib-pin_init $(obj)/$(libmacros_name) \
312+
rusttestlib-build_error rusttestlib-pin_init $(obj)/host/$(libmacros_name) \
310313
$(obj)/bindings.o FORCE
311314
+$(call if_changed,rustc_test_library)
312315

@@ -402,13 +405,21 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
402405
-fstrict-flex-arrays=% -fmin-function-alignment=% \
403406
-fzero-init-padding-bits=% -mno-fdpic \
404407
-fdiagnostics-show-context -fdiagnostics-show-context=% \
405-
--param=% --param asan-% -fno-isolate-erroneous-paths-dereference
408+
--param=% --param asan-% -fno-isolate-erroneous-paths-dereference \
409+
-ffixed-r2 -mmultiple -mno-readonly-in-sdata
406410

407411
# Derived from `scripts/Makefile.clang`.
408412
BINDGEN_TARGET_x86 := x86_64-linux-gnu
409413
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
410414
BINDGEN_TARGET_arm := arm-linux-gnueabi
411415
BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf
416+
417+
ifdef CONFIG_PPC64
418+
BINDGEN_TARGET_powerpc := powerpc64le-linux-gnu
419+
else
420+
BINDGEN_TARGET_powerpc := powerpc-linux-gnu
421+
endif
422+
412423
BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
413424
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
414425

@@ -525,26 +536,27 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
525536

526537
quiet_cmd_rustc_procmacrolibrary = $(RUSTC_OR_CLIPPY_QUIET) PL $@
527538
cmd_rustc_procmacrolibrary = \
539+
mkdir -p $(dir $@); \
528540
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
529541
$(filter-out $(skip_flags),$(rust_common_flags) $(rustc_target_flags)) \
530542
--emit=dep-info=$(depfile) --emit=link=$@ --crate-type rlib -O \
531-
--out-dir $(objtree)/$(obj) -L$(objtree)/$(obj) \
543+
-L$(objtree)/$(obj)/host \
532544
--crate-name $(patsubst lib%.rlib,%,$(notdir $@)) $<
533545

534-
$(obj)/libproc_macro2.rlib: private skip_clippy = 1
535-
$(obj)/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
536-
$(obj)/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
546+
$(obj)/host/libproc_macro2.rlib: private skip_clippy = 1
547+
$(obj)/host/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
548+
$(obj)/host/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
537549
+$(call if_changed_dep,rustc_procmacrolibrary)
538550

539-
$(obj)/libquote.rlib: private skip_clippy = 1
540-
$(obj)/libquote.rlib: private skip_flags = $(quote-skip_flags)
541-
$(obj)/libquote.rlib: private rustc_target_flags = $(quote-flags)
542-
$(obj)/libquote.rlib: $(src)/quote/lib.rs $(obj)/libproc_macro2.rlib FORCE
551+
$(obj)/host/libquote.rlib: private skip_clippy = 1
552+
$(obj)/host/libquote.rlib: private skip_flags = $(quote-skip_flags)
553+
$(obj)/host/libquote.rlib: private rustc_target_flags = $(quote-flags)
554+
$(obj)/host/libquote.rlib: $(src)/quote/lib.rs $(obj)/host/libproc_macro2.rlib FORCE
543555
+$(call if_changed_dep,rustc_procmacrolibrary)
544556

545-
$(obj)/libsyn.rlib: private skip_clippy = 1
546-
$(obj)/libsyn.rlib: private rustc_target_flags = $(syn-flags)
547-
$(obj)/libsyn.rlib: $(src)/syn/lib.rs $(obj)/libquote.rlib FORCE
557+
$(obj)/host/libsyn.rlib: private skip_clippy = 1
558+
$(obj)/host/libsyn.rlib: private rustc_target_flags = $(syn-flags)
559+
$(obj)/host/libsyn.rlib: $(src)/syn/lib.rs $(obj)/host/libquote.rlib FORCE
548560
+$(call if_changed_dep,rustc_procmacrolibrary)
549561

550562
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
@@ -553,20 +565,20 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
553565
-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
554566
-Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
555567
--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
556-
--crate-type proc-macro -L$(objtree)/$(obj) \
568+
--crate-type proc-macro -L$(objtree)/$(obj)/host \
557569
--crate-name $(patsubst lib%.$(libmacros_extension),%,$(notdir $@)) \
558570
@$(objtree)/include/generated/rustc_cfg $<
559571

560572
# Procedural macros can only be used with the `rustc` that compiled it.
561-
$(obj)/$(libmacros_name): private rustc_target_flags = \
573+
$(obj)/host/$(libmacros_name): private rustc_target_flags = \
562574
--extern proc_macro2 --extern quote --extern syn
563-
$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib \
564-
$(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
575+
$(obj)/host/$(libmacros_name): $(src)/macros/lib.rs $(obj)/host/libproc_macro2.rlib \
576+
$(obj)/host/libquote.rlib $(obj)/host/libsyn.rlib FORCE
565577
+$(call if_changed_dep,rustc_procmacro)
566578

567-
$(obj)/$(libpin_init_internal_name): private rustc_target_flags = $(pin_init_internal-flags)
568-
$(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs \
569-
$(obj)/libproc_macro2.rlib $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
579+
$(obj)/host/$(libpin_init_internal_name): private rustc_target_flags = $(pin_init_internal-flags)
580+
$(obj)/host/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs \
581+
$(obj)/host/libproc_macro2.rlib $(obj)/host/libquote.rlib $(obj)/host/libsyn.rlib FORCE
570582
+$(call if_changed_dep,rustc_procmacro)
571583

572584
# `rustc` requires `-Zunstable-options` to use custom target specifications
@@ -665,7 +677,7 @@ $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
665677
$(obj)/pin_init.o: private skip_gendwarfksyms = 1
666678
$(obj)/pin_init.o: private rustc_target_flags = $(pin_init-flags)
667679
$(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \
668-
$(obj)/$(libpin_init_internal_name) $(obj)/$(libmacros_name) FORCE
680+
$(obj)/host/$(libpin_init_internal_name) $(obj)/host/$(libmacros_name) FORCE
669681
+$(call if_changed_rule,rustc_library)
670682

671683
# Even if normally `build_error` is not a kernel object, it should still be
@@ -699,7 +711,7 @@ $(obj)/uapi.o: $(src)/uapi/lib.rs \
699711
$(obj)/kernel.o: private rustc_target_flags = --extern ffi --extern pin_init \
700712
--extern build_error --extern macros --extern bindings --extern uapi
701713
$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/build_error.o $(obj)/pin_init.o \
702-
$(obj)/$(libmacros_name) $(obj)/bindings.o $(obj)/uapi.o FORCE
714+
$(obj)/host/$(libmacros_name) $(obj)/bindings.o $(obj)/uapi.o FORCE
703715
+$(call if_changed_rule,rustc_library)
704716

705717
ifdef CONFIG_JUMP_LABEL

0 commit comments

Comments
 (0)