objtool: Add function to get the name of a CPU feature
PATCH v6 26/30 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.
--- .../x86/tools/gen-cpu-feature-names-x86.awk | 34 +++++++++++++++++++ tools/objtool/.gitignore | 1 + tools/objtool/Makefile | 1 + tools/objtool/arch/loongarch/special.c | 5 +++ tools/objtool/arch/powerpc/special.c | 5 +++ tools/objtool/arch/x86/Build | 10 ++++++ tools/objtool/arch/x86/special.c | 10 ++++++ tools/objtool/include/objtool/special.h | 2 ++ 8 files changed, 68 insertions(+) create mode 100644 tools/arch/x86/tools/gen-cpu-feature-names-x86.awk
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +34 -0
@@ -0,0 +1,34 @@ +#!/bin/awk -f +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2025, Oracle and/or its affiliates. +# +# Usage: awk -f gen-cpu-feature-names-x86.awk cpufeatures.h > cpu-feature-names.c +# + +BEGIN { + print "/* cpu feature name array generated from cpufeatures.h */" + print "/* Do not change this code. */" + print + print "static const char *cpu_feature_names[(NCAPINTS+NBUGINTS)*32] = {" + + value_expr = "\\([0-9*+ ]+\\)" +} + +/^#define X86_FEATURE_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[" value "] = \"" $2 "\"," + } +} + +/^#define X86_BUG_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[NCAPINTS*32+(" value ")] = \"" $2 "\"," + } +} + +END { + print "};" +}
tools/objtool/.gitignore +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +arch/x86/lib/cpu-feature-names.c arch/x86/lib/inat-tables.c /objtool feature
tools/objtool/Makefile +1 -0
@@ -125,6 +125,7 @@ $(LIBSUBCMD)-clean: clean: $(LIBSUBCMD)-clean $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete + $(Q)$(RM) $(OUTPUT)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool $(Q)$(RM) -r -- $(OUTPUT)feature
tools/objtool/arch/loongarch/special.c +5 -0
@@ -194,3 +194,8 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,return rodata_reloc; } + +const char *arch_cpu_feature_name (int feature_number) +{ +return NULL ; +}
tools/objtool/arch/powerpc/special.c +5 -0
@@ -18,3 +18,8 @@ struct reloc *arch_find_switch_table(struct objtool_file *file, {exit (-1 ); } + +const char *arch_cpu_feature_name (int feature_number) +{ +return NULL ; +}
tools/objtool/arch/x86/Build +10 -0
@@ -12,3 +12,13 @@ $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c CFLAGS_decode.o += -I$(OUTPUT)arch/x86/lib + +cpu_features = ../arch/x86/include/asm/cpufeatures.h +cpu_features_script = ../arch/x86/tools/gen-cpu-feature-names-x86.awk + +$(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_features) + $(Q)$(call echo-cmd,gen)$(AWK) -f $(cpu_features_script) $(cpu_features) > $@ + +$(OUTPUT)arch/x86/special.o: $(OUTPUT)arch/x86/lib/cpu-feature-names.c + +CFLAGS_special.o := -I$(OUTPUT)arch/x86/lib
tools/objtool/arch/x86/special.c +10 -0
@@ -4,6 +4,10 @@#include <objtool/special.h> #include <objtool/builtin.h> #include <objtool/warn.h> +#include <asm/cpufeatures.h> + +/* cpu feature name array generated from cpufeatures.h */ +#include "cpu-feature-names.c" void arch_handle_alternative (struct special_alt *alt) {
@@ -134,3 +138,9 @@ struct reloc *arch_find_switch_table(struct objtool_file *file, *table_size =0 ;return rodata_reloc; } + +const char *arch_cpu_feature_name (int feature_number) +{ +return (feature_number <ARRAY_SIZE (cpu_feature_names)) ? + cpu_feature_names[feature_number] :NULL ; +}
tools/objtool/include/objtool/special.h +2 -0
@@ -38,4 +38,6 @@ bool arch_support_alt_relocation(struct special_alt *special_alt,struct reloc *arch_find_switch_table (struct objtool_file *file,struct instruction *insn,unsigned long *table_size); +const char *arch_cpu_feature_name (int feature_number); +#endif /* _SPECIAL_H */
Signature · 1 line
2.43.5
Peter Zijlstra
maintainerQuoted 8 lines · Alexandre Chartre
tools/objtool/arch/x86/Build +0
-0@@ -12,3 +12,13 @@ $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c CFLAGS_decode.o += -I$(OUTPUT)arch/x86/lib
tools/objtool/arch/x86/Build $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) · line 24
Quoted 10 lines
tools/objtool/arch/x86/Build +10
-0+ +cpu_features = ../arch/x86/include/asm/cpufeatures.h +cpu_features_script = ../arch/x86/tools/gen-cpu-feature-names-x86.awk + +$(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_features) + $(Q)$(call echo-cmd,gen)$(AWK) -f $(cpu_features_script) $(cpu_features) > $@ + +$(OUTPUT)arch/x86/special.o: $(OUTPUT)arch/x86/lib/cpu-feature-names.c + +CFLAGS_special.o := -I$(OUTPUT)arch/x86/lib
If you'd been careful, you'd have taken the commit from tip and noticed its Build fragment is slightly different :-)
You're now re-introducing a race in the build where if you build special.o before decode.o the lib directory isn't yet created and it goes sideways.
Anyway, let me fold that awk delta into what I have.
Thanks!
Peter Zijlstra
maintainerQuoted 23 lines · Peter Zijlstra
Quoted 8 lines · Alexandre Chartre
tools/objtool/arch/x86/Build +0
-0@@ -12,3 +12,13 @@ $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c CFLAGS_decode.o += -I$(OUTPUT)arch/x86/libtools/objtool/arch/x86/Build $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) · line 24
Quoted 10 lines
tools/objtool/arch/x86/Build +10
-0+ +cpu_features = ../arch/x86/include/asm/cpufeatures.h +cpu_features_script = ../arch/x86/tools/gen-cpu-feature-names-x86.awk + +$(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_features) + $(Q)$(call echo-cmd,gen)$(AWK) -f $(cpu_features_script) $(cpu_features) > $@ + +$(OUTPUT)arch/x86/special.o: $(OUTPUT)arch/x86/lib/cpu-feature-names.c + +CFLAGS_special.o := -I$(OUTPUT)arch/x86/libIf you'd been careful, you'd have taken the commit from tip and noticed its Build fragment is slightly different :-)
Quoted 5 lines
You're now re-introducing a race in the build where if you build special.o before decode.o the lib directory isn't yet created and it goes sideways.
Anyway, let me fold that awk delta into what I have.
OK, pushed out a new tip/objtool/core, lets hope its all good now :-)
Quoted 23 lines · Peter Zijlstra
Quoted 8 lines · Alexandre Chartre
tools/objtool/arch/x86/Build +0
-0@@ -12,3 +12,13 @@ $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c CFLAGS_decode.o += -I$(OUTPUT)arch/x86/libtools/objtool/arch/x86/Build $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) · line 24
Quoted 10 lines
tools/objtool/arch/x86/Build +10
-0+ +cpu_features = ../arch/x86/include/asm/cpufeatures.h +cpu_features_script = ../arch/x86/tools/gen-cpu-feature-names-x86.awk + +$(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_features) + $(Q)$(call echo-cmd,gen)$(AWK) -f $(cpu_features_script) $(cpu_features) > $@ + +$(OUTPUT)arch/x86/special.o: $(OUTPUT)arch/x86/lib/cpu-feature-names.c + +CFLAGS_special.o := -I$(OUTPUT)arch/x86/libIf you'd been careful, you'd have taken the commit from tip and noticed its Build fragment is slightly different :-)
Quoted 5 lines
You're now re-introducing a race in the build where if you build special.o before decode.o the lib directory isn't yet created and it goes sideways.
Anyway, let me fold that awk delta into what I have.
Oups, sorry. I've checked tip but not closely enough :(
Thanks for handling it; that's a good lesson about the many different impacts and dependencies.
alex.
Quoted 30 lines · On Mon, 24 Nov 2025 17:48:55 +0100 Alexandre Chartre…
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.hinclude file.Signed-off-by Alexandre Chartre <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Josh Poimboeuf <[email protected]>--- .../x86/tools/gen-cpu-feature-names-x86.awk | 34 +++++++++++++++++++ tools/objtool/.gitignore | 1 + tools/objtool/Makefile | 1 + tools/objtool/arch/loongarch/special.c | 5 +++ tools/objtool/arch/powerpc/special.c | 5 +++ tools/objtool/arch/x86/Build | 10 ++++++ tools/objtool/arch/x86/special.c | 10 ++++++ tools/objtool/include/objtool/special.h | 2 ++ 8 files changed, 68 insertions(+) create mode 100644 tools/arch/x86/tools/gen-cpu-feature-names-x86.awktools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +3
-0@@ -0,0 +1,34 @@ +#!/bin/awk -f +# SPDX-License-Identifier: GPL-2.0 +#
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk line 13
Quoted 10 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +10
-0+# Copyright (c) 2025, Oracle and/or its affiliates. +# +# Usage: awk -f gen-cpu-feature-names-x86.awk cpufeatures.h > cpu-feature-names.c +# + +BEGIN { + print "/* cpu feature name array generated from cpufeatures.h */" + print "/* Do not change this code. */" + print + print "static const char *cpu_feature_names[(NCAPINTS+NBUGINTS)*32] = {"
Since this code is #include'd into a .c file the line above (and the final }) can be in that source file.
You only need to generate the initialisers here.
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk line 22
Quoted 9 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +9
-0+ + value_expr = "\\([0-9*+ ]+\\)" +} + +/^#define X86_FEATURE_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[" value "] = \"" $2 "\"," + }
Can't you just do:
print "\t[" $2 "] = \"" $2 "\","
DavidQuoted 114 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +12
-0+} + +/^#define X86_BUG_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[NCAPINTS*32+(" value ")] = \"" $2 "\"," + } +} + +END { + print "};" +}tools/objtool/.gitignore +1
-0@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +arch/x86/lib/cpu-feature-names.c arch/x86/lib/inat-tables.c /objtool featuretools/objtool/Makefile +1
-0@@ -125,6 +125,7 @@ $(LIBSUBCMD)-clean: clean: $(LIBSUBCMD)-clean $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete + $(Q)$(RM) $(OUTPUT)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool $(Q)$(RM) -r -- $(OUTPUT)featuretools/objtool/arch/loongarch/special.c +5
-0@@ -194,3 +194,8 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,return rodata_reloc; } + +const char *arch_cpu_feature_name (int feature_number) +{ +return NULL ; +}tools/objtool/arch/powerpc/special.c +5
-0@@ -18,3 +18,8 @@ struct reloc *arch_find_switch_table(struct objtool_file *file, {exit (-1 ); } + +const char *arch_cpu_feature_name (int feature_number) +{ +return NULL ; +}tools/objtool/arch/x86/Build +10
-0@@ -12,3 +12,13 @@ $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c CFLAGS_decode.o += -I$(OUTPUT)arch/x86/lib + +cpu_features = ../arch/x86/include/asm/cpufeatures.h +cpu_features_script = ../arch/x86/tools/gen-cpu-feature-names-x86.awk + +$(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_features) + $(Q)$(call echo-cmd,gen)$(AWK) -f $(cpu_features_script) $(cpu_features) > $@ + +$(OUTPUT)arch/x86/special.o: $(OUTPUT)arch/x86/lib/cpu-feature-names.c + +CFLAGS_special.o := -I$(OUTPUT)arch/x86/libtools/objtool/arch/x86/special.c +10
-0@@ -4,6 +4,10 @@#include <objtool/special.h> #include <objtool/builtin.h> #include <objtool/warn.h> +#include <asm/cpufeatures.h> + +/* cpu feature name array generated from cpufeatures.h */ +#include "cpu-feature-names.c" void arch_handle_alternative (struct special_alt *alt) {@@ -134,3 +138,9 @@ struct reloc *arch_find_switch_table(struct objtool_file *file, *table_size =0 ;return rodata_reloc; } + +const char *arch_cpu_feature_name (int feature_number) +{ +return (feature_number <ARRAY_SIZE (cpu_feature_names)) ? + cpu_feature_names[feature_number] :NULL ; +}tools/objtool/include/objtool/special.h +2
-0@@ -38,4 +38,6 @@ bool arch_support_alt_relocation(struct special_alt *special_alt,struct reloc *arch_find_switch_table (struct objtool_file *file,struct instruction *insn,unsigned long *table_size); +const char *arch_cpu_feature_name (int feature_number); +#endif /* _SPECIAL_H */
Quoted 39 lines · David Laight
Quoted 36 lines · On Mon, 24 Nov 2025 17:48:55 +0100 Alexandre Chartre…
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.hinclude file.Signed-off-by Alexandre Chartre <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Josh Poimboeuf <[email protected]>--- .../x86/tools/gen-cpu-feature-names-x86.awk | 34 +++++++++++++++++++ tools/objtool/.gitignore | 1 + tools/objtool/Makefile | 1 + tools/objtool/arch/loongarch/special.c | 5 +++ tools/objtool/arch/powerpc/special.c | 5 +++ tools/objtool/arch/x86/Build | 10 ++++++ tools/objtool/arch/x86/special.c | 10 ++++++ tools/objtool/include/objtool/special.h | 2 ++ 8 files changed, 68 insertions(+)create mode 100644
tools/arch/x86/tools/gen-cpu-feature-names-x86.awktools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +9
-0@@ -0,0 +1,34 @@ +#!/bin/awk -f +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2025, Oracle and/or its affiliates. +# +# Usage: awk -f gen-cpu-feature-names-x86.awk cpufeatures.h > cpu-feature-names.c +# + +BEGIN {
Quoted 8 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk line 13
Quoted 4 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +4
-0+ print "/* cpu feature name array generated from cpufeatures.h */" + print "/* Do not change this code. */" + print + print "static const char *cpu_feature_names[(NCAPINTS+NBUGINTS)*32] = {"Since this code is #include'd into a .c file the line above (and the final }) can be in that source file.
You only need to generate the initialisers here.
Sure, I can do that.
Quoted 12 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk line 22
Quoted 10 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +9
-0+ + value_expr = "\\([0-9*+ ]+\\)" +} + +/^#define X86_FEATURE_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[" value "] = \"" $2 "\"," + }Can't you just do:
Quoted 1 line
print "\t[" $2 "] = \"" $2 "\","
I presume you mean: print "\t[" $3 "] = \"" $2 "\","
But this doesn't always work because the value we need can contain spaces and then it will be split into several fields.
For example, this works with:
#define X86_FEATURE_RRSBA_CTRL (11*32+11) /* RET prediction control */
But not with:
#define X86_FEATURE_APIC ( 0*32+ 9) /* "apic" Onboard APIC */
alex.
Quoted 116 lines
Quoted 115 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +12
-0+} + +/^#define X86_BUG_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[NCAPINTS*32+(" value ")] = \"" $2 "\"," + } +} + +END { + print "};" +}tools/objtool/.gitignore +1
-0@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +arch/x86/lib/cpu-feature-names.c arch/x86/lib/inat-tables.c /objtool featuretools/objtool/Makefile +1
-0@@ -125,6 +125,7 @@ $(LIBSUBCMD)-clean: clean: $(LIBSUBCMD)-clean $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete + $(Q)$(RM) $(OUTPUT)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool $(Q)$(RM) -r -- $(OUTPUT)featuretools/objtool/arch/loongarch/special.c +5
-0@@ -194,3 +194,8 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,return rodata_reloc; } + +const char *arch_cpu_feature_name (int feature_number) +{ +return NULL ; +}tools/objtool/arch/powerpc/special.c +5
-0@@ -18,3 +18,8 @@ struct reloc *arch_find_switch_table(struct objtool_file *file, {exit (-1 ); } + +const char *arch_cpu_feature_name (int feature_number) +{ +return NULL ; +}tools/objtool/arch/x86/Build +10
-0@@ -12,3 +12,13 @@ $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c CFLAGS_decode.o += -I$(OUTPUT)arch/x86/lib + +cpu_features = ../arch/x86/include/asm/cpufeatures.h +cpu_features_script = ../arch/x86/tools/gen-cpu-feature-names-x86.awk + +$(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_features) + $(Q)$(call echo-cmd,gen)$(AWK) -f $(cpu_features_script) $(cpu_features) > $@ + +$(OUTPUT)arch/x86/special.o: $(OUTPUT)arch/x86/lib/cpu-feature-names.c + +CFLAGS_special.o := -I$(OUTPUT)arch/x86/libtools/objtool/arch/x86/special.c +10
-0@@ -4,6 +4,10 @@#include <objtool/special.h> #include <objtool/builtin.h> #include <objtool/warn.h> +#include <asm/cpufeatures.h> + +/* cpu feature name array generated from cpufeatures.h */ +#include "cpu-feature-names.c" void arch_handle_alternative (struct special_alt *alt) {@@ -134,3 +138,9 @@ struct reloc *arch_find_switch_table(struct objtool_file *file, *table_size =0 ;return rodata_reloc; } + +const char *arch_cpu_feature_name (int feature_number) +{ +return (feature_number <ARRAY_SIZE (cpu_feature_names)) ? + cpu_feature_names[feature_number] :NULL ; +}tools/objtool/include/objtool/special.h +2
-0@@ -38,4 +38,6 @@ bool arch_support_alt_relocation(struct special_alt *special_alt,struct reloc *arch_find_switch_table (struct objtool_file *file,struct instruction *insn,unsigned long *table_size); +const char *arch_cpu_feature_name (int feature_number); +#endif /* _SPECIAL_H */
Quoted 66 lines · On Tue, 25 Nov 2025 15:43:10 +0100 Alexandre Chartre…
Quoted 39 lines · David Laight
Quoted 36 lines · On Mon, 24 Nov 2025 17:48:55 +0100 Alexandre Chartre…
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.hinclude file.Signed-off-by Alexandre Chartre <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Josh Poimboeuf <[email protected]>--- .../x86/tools/gen-cpu-feature-names-x86.awk | 34 +++++++++++++++++++ tools/objtool/.gitignore | 1 + tools/objtool/Makefile | 1 + tools/objtool/arch/loongarch/special.c | 5 +++ tools/objtool/arch/powerpc/special.c | 5 +++ tools/objtool/arch/x86/Build | 10 ++++++ tools/objtool/arch/x86/special.c | 10 ++++++ tools/objtool/include/objtool/special.h | 2 ++ 8 files changed, 68 insertions(+)create mode 100644
tools/arch/x86/tools/gen-cpu-feature-names-x86.awktools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +9
-0@@ -0,0 +1,34 @@ +#!/bin/awk -f +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2025, Oracle and/or its affiliates. +# +# Usage: awk -f gen-cpu-feature-names-x86.awk cpufeatures.h > cpu-feature-names.c +# + +BEGIN {Quoted 8 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk line 13
Quoted 4 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +4
-0+ print "/* cpu feature name array generated from cpufeatures.h */" + print "/* Do not change this code. */" + print + print "static const char *cpu_feature_names[(NCAPINTS+NBUGINTS)*32] = {"Since this code is #include'd into a .c file the line above (and the final }) can be in that source file.
You only need to generate the initialisers here.Sure, I can do that.
Quoted 12 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk line 22
Quoted 10 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +9
-0+ + value_expr = "\\([0-9*+ ]+\\)" +} + +/^#define X86_FEATURE_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[" value "] = \"" $2 "\"," + }Can't you just do:
Quoted 1 line
print "\t[" $2 "] = \"" $2 "\","
Quoted 1 line
I presume you mean: print "\t[" $3 "] = \"" $2 "\","
No $2 and $2, so it generates:
[X86_FEATURE_RRSBA_CTRL] = "X86_FEATURE_RRSBA_CTRL",
All the #defines are defined - so you might as well use them. I suggested this sed command that has the same effect:
sed -n -E '/^#define (X86_(FEATURE|BUG)_([^ ]*)).*/s// [\1] = "\1",/p'
which can be put directly into the makefile.
It isn't as though the pattern match for lines has to be very selective. It just needs to be 'good enough' for the current file.
David
Quoted 15 lines
But this doesn't always work because the value we need can contain spaces and then it will be split into several fields.
For example, this works with:
#define
X86_FEATURE_RRSBA_CTRL(11*32+11) /* RET prediction control */But not with:
#define
X86_FEATURE_APIC( 0*32+ 9) /* "apic" Onboard APIC */alex.
Quoted 74 lines · David Laight
Quoted 66 lines · On Tue, 25 Nov 2025 15:43:10 +0100 Alexandre Chartre…
Quoted 39 lines · David Laight
Quoted 36 lines · On Mon, 24 Nov 2025 17:48:55 +0100 Alexandre Chartre…
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.hinclude file.Signed-off-by Alexandre Chartre <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Josh Poimboeuf <[email protected]>--- .../x86/tools/gen-cpu-feature-names-x86.awk | 34 +++++++++++++++++++ tools/objtool/.gitignore | 1 + tools/objtool/Makefile | 1 + tools/objtool/arch/loongarch/special.c | 5 +++ tools/objtool/arch/powerpc/special.c | 5 +++ tools/objtool/arch/x86/Build | 10 ++++++ tools/objtool/arch/x86/special.c | 10 ++++++ tools/objtool/include/objtool/special.h | 2 ++ 8 files changed, 68 insertions(+)create mode 100644
tools/arch/x86/tools/gen-cpu-feature-names-x86.awktools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +9
-0@@ -0,0 +1,34 @@ +#!/bin/awk -f +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2025, Oracle and/or its affiliates. +# +# Usage: awk -f gen-cpu-feature-names-x86.awk cpufeatures.h > cpu-feature-names.c +# + +BEGIN {Quoted 8 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk line 13
Quoted 4 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +4
-0+ print "/* cpu feature name array generated from cpufeatures.h */" + print "/* Do not change this code. */" + print + print "static const char *cpu_feature_names[(NCAPINTS+NBUGINTS)*32] = {"Since this code is #include'd into a .c file the line above (and the final }) can be in that source file.
You only need to generate the initialisers here.Sure, I can do that.
Quoted 12 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk line 22
Quoted 10 lines
tools/arch/x86/tools/gen-cpu-feature-names-x86.awk new file +9
-0+ + value_expr = "\\([0-9*+ ]+\\)" +} + +/^#define X86_FEATURE_/ { + if (match($0, value_expr)) { + value = substr($0, RSTART + 1, RLENGTH - 2) + print "\t[" value "] = \"" $2 "\"," + }Can't you just do:
Quoted 1 line
print "\t[" $2 "] = \"" $2 "\","Quoted 1 line
I presume you mean: print "\t[" $3 "] = \"" $2 "\","
No $2 and $2, so it generates:
[X86_FEATURE_RRSBA_CTRL] = "X86_FEATURE_RRSBA_CTRL",
Quoted 8 lines
All the #defines are defined - so you might as well use them. I suggested this sed command that has the same effect:
sed -n -E '/^#define (X86_(FEATURE|BUG)_([^ ]*)).*/s// [\1] = "\1",/p'which can be put directly into the makefile.
It isn't as though the pattern match for lines has to be very selective. It just needs to be 'good enough' for the current file.
Yes, right! I initially wanted to not have to include cpufeatures.h so I used the X86_FEATURE_* values directly. Then I added X86_BUG_* which required NCAPINTS and so cpufeatures.h.
So. of course, sed is good enough. I will simplify this.
Thanks,
alex.