Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

objtool: Add Function to get the name of a CPU feature

Add a function to get the name of a CPU feature. The function is
architecture dependent and currently only implemented for x86. The
feature names are automatically generated from the cpufeatures.h
include file.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://patch.msgid.link/20251121095340.464045-27-alexandre.chartre@oracle.com

authored by

Alexandre Chartre and committed by
Peter Zijlstra
8308fd00 be5ee60a

+70 -1
+34
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk
··· 1 + #!/bin/awk -f 2 + # SPDX-License-Identifier: GPL-2.0 3 + # 4 + # Copyright (c) 2025, Oracle and/or its affiliates. 5 + # 6 + # Usage: awk -f gen-cpu-feature-names-x86.awk cpufeatures.h > cpu-feature-names.c 7 + # 8 + 9 + BEGIN { 10 + print "/* cpu feature name array generated from cpufeatures.h */" 11 + print "/* Do not change this code. */" 12 + print 13 + print "static const char *cpu_feature_names[(NCAPINTS+NBUGINTS)*32] = {" 14 + 15 + value_expr = "\\([0-9*+ ]+\\)" 16 + } 17 + 18 + /^#define X86_FEATURE_/ { 19 + if (match($0, value_expr)) { 20 + value = substr($0, RSTART + 1, RLENGTH - 2) 21 + print "\t[" value "] = \"" $2 "\"," 22 + } 23 + } 24 + 25 + /^#define X86_BUG_/ { 26 + if (match($0, value_expr)) { 27 + value = substr($0, RSTART + 1, RLENGTH - 2) 28 + print "\t[NCAPINTS*32+(" value ")] = \"" $2 "\"," 29 + } 30 + } 31 + 32 + END { 33 + print "};" 34 + }
+1
tools/objtool/.gitignore
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 + arch/x86/lib/cpu-feature-names.c 2 3 arch/x86/lib/inat-tables.c 3 4 /objtool 4 5 feature
+1
tools/objtool/Makefile
··· 125 125 clean: $(LIBSUBCMD)-clean 126 126 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) 127 127 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 128 + $(Q)$(RM) $(OUTPUT)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep 128 129 $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep 129 130 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool 130 131 $(Q)$(RM) -r -- $(OUTPUT)feature
+5
tools/objtool/arch/loongarch/special.c
··· 194 194 195 195 return rodata_reloc; 196 196 } 197 + 198 + const char *arch_cpu_feature_name(int feature_number) 199 + { 200 + return NULL; 201 + }
+5
tools/objtool/arch/powerpc/special.c
··· 18 18 { 19 19 exit(-1); 20 20 } 21 + 22 + const char *arch_cpu_feature_name(int feature_number) 23 + { 24 + return NULL; 25 + }
+12 -1
tools/objtool/arch/x86/Build
··· 1 - objtool-y += special.o 2 1 objtool-y += decode.o 2 + objtool-y += special.o 3 3 objtool-y += orc.o 4 4 5 5 inat_tables_script = ../arch/x86/tools/gen-insn-attr-x86.awk ··· 12 12 $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c 13 13 14 14 CFLAGS_decode.o += -I$(OUTPUT)arch/x86/lib 15 + 16 + cpu_features = ../arch/x86/include/asm/cpufeatures.h 17 + cpu_features_script = ../arch/x86/tools/gen-cpu-feature-names-x86.awk 18 + 19 + $(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_features) 20 + $(call rule_mkdir) 21 + $(Q)$(call echo-cmd,gen)$(AWK) -f $(cpu_features_script) $(cpu_features) > $@ 22 + 23 + $(OUTPUT)arch/x86/special.o: $(OUTPUT)arch/x86/lib/cpu-feature-names.c 24 + 25 + CFLAGS_special.o += -I$(OUTPUT)arch/x86/lib
+10
tools/objtool/arch/x86/special.c
··· 4 4 #include <objtool/special.h> 5 5 #include <objtool/builtin.h> 6 6 #include <objtool/warn.h> 7 + #include <asm/cpufeatures.h> 8 + 9 + /* cpu feature name array generated from cpufeatures.h */ 10 + #include "cpu-feature-names.c" 7 11 8 12 void arch_handle_alternative(struct special_alt *alt) 9 13 { ··· 137 133 138 134 *table_size = 0; 139 135 return rodata_reloc; 136 + } 137 + 138 + const char *arch_cpu_feature_name(int feature_number) 139 + { 140 + return (feature_number < ARRAY_SIZE(cpu_feature_names)) ? 141 + cpu_feature_names[feature_number] : NULL; 140 142 }
+2
tools/objtool/include/objtool/special.h
··· 38 38 struct reloc *arch_find_switch_table(struct objtool_file *file, 39 39 struct instruction *insn, 40 40 unsigned long *table_size); 41 + const char *arch_cpu_feature_name(int feature_number); 42 + 41 43 #endif /* _SPECIAL_H */