From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 674543233E5 for ; Tue, 25 Nov 2025 13:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764077351; cv=none; b=Khp14ymUT9SE4bbI3FmZ5UZ23eWI1T37v+eChYS61M4dywhMaVUQz9p4Q5QK0mjMwngQ4TxTV+dBVa/ihi9ZRWi4hFEcU1867syTluJ5w0MGD209Cc4QGyjhUbBB63NiiIIftZRX20v2yMASFAlzAxbTXybeTZ34yG4i7pHx1ZY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764077351; c=relaxed/simple; bh=RrpnJoAWwj1guuK20VOGzFP2lekMc4QPEeFV6SDLpOE=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BNRI/2/+JNLaHPFzJk7pnc0LQLZASOkPCHgG46Or3GdrlWXH8ThHDL9AirMtF6FWNf755VdwZYeJcD4LzOMF4E5Ytju2rO+Z9ewe0zOB0wfikExn5u65SaEpeHsYTp1meEzjhIFL4wQphXe25ttC5jmKQX6zkmEDG3BNxDQ+ddo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GL2QwDOG; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GL2QwDOG" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4779d47be12so42441235e9.2 for ; Tue, 25 Nov 2025 05:29:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764077348; x=1764682148; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=8DSSTjHtNH+PgGTpGYxYzoER1wy3t1uDvM93KUXazXI=; b=GL2QwDOG8t6IAunnzogvv67mMzoCqkCLpQ7mPidiVA7JvnREbIpYBOvvkPhe0qPd2i AN2QA38T7yvihRzTqMb00Fhq0V3MESVuzV+cwDLs20p8nhDpTvmqimlsUAluBKPLgFxJ fIYV3sQaV+sbvFr44Gt+MeQiqzQJmzKW2zwi2i8ZEtsM2joG7Pj1fdp93NFqLs6Orp3V lUWQFapOwtaYGl7PCV/tWPnaOIZoFhZLisExf9IR5FA8LMmm3aJQo4OPRxE+BIYkTLHa LnOntgrTk32kY/g3wlRVck0Ltn4rpMN/gxFip65S0r1LuF082sMfbQz48yoT0XlZ+blp Edmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764077348; x=1764682148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8DSSTjHtNH+PgGTpGYxYzoER1wy3t1uDvM93KUXazXI=; b=I8RsFW/EflNLld0UsziTYojaWKQjQDTnowNvOdNIt6KS4W/dBMfol5kkySHohvRDgh UKPy9LebL0kC/j9nSc4dSw0Lr0GRXAiAlU+Ck++h4JAfavrK9/Gf2ZhQUGFAnOK0o4Mi QC34vt7pif8fPcoXeEXBTUzGaX5vdkLYB1uK7gsl8rgY2ztEHTE+aOP4gdjvpOykOVPD JMlHiz2niG0+IBrhXwMquElHMxhd1UhiFAxG+IPHmT2wA894cwdgQM4HBFW/YJcB5REp h3LoSROd7jpy9TvCdz1NSiSWY4Iv8e86lkAOl0MvCvUPandvmLi1zyt/Rjjwd3v6qHKH K9Iw== X-Gm-Message-State: AOJu0YwjHatgF0J0LE9Q75UTY/0ylQRGFnLCfu/wAqItJbxUJ13TGtnr sQUDTRJELvXbq6JdvlzURkL87F3diDowB6bApNQYXIeNIw36i3bvK7N8 X-Gm-Gg: ASbGncsq5OmnXkr01KilUx/0osVy4zkenK2aEYGsjlxU5HCvM74aR2LLhVCMi8tn3dM j2CxjSrSbOoCQT9q6sRVlylEkFO9oTtiet/YV5wi7RZH2eQpRlIwJaZ9+oWKZTJTM89eUpoHxOW 4ynXhMXNW5BS4HiVDPPC7SUIUbHUEPNtGLwQqiElToK4VnSMslM6OPMJ0TmYE9aJBxXQoiFonfA hztGzRcFBCy7j3WxoZcksbpaXlIi0f5nEy0xEMyOzN8NrMoXM99AT/BXWlFZbSPbAtCWaBjRsIE 4lT1DSXXG0pgwzzOC6bGPnP/BkRUfuHKn926m5U6LsjgTK4Uu8KUc6CtOXualdsy4GErhuRVuJd lZ4S0GJwrLAdDMhumkmG98XuoQGGrc5pBd3m5FX+Dj3STdyh6HDvCDxVBYdJQY7LahcXxRAdyS4 AlLZCSahyW1dcZ+uDISaEJq3kjJDaEAsjfUNnUhgXOfyBnZ6EZL8q+ X-Google-Smtp-Source: AGHT+IEPjleynrVXuCyBYfyLGdOG1WzVTBvJaNJp3nl651aYHOAmEV7NIIUDJ3Nf/qdXsAjsPTlzsg== X-Received: by 2002:a05:600c:524d:b0:477:c71:1fc1 with SMTP id 5b1f17b1804b1-477c01d44b4mr142244515e9.19.1764077347386; Tue, 25 Nov 2025 05:29:07 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47903e65d51sm19449755e9.0.2025.11.25.05.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 05:29:06 -0800 (PST) Date: Tue, 25 Nov 2025 13:29:02 +0000 From: David Laight To: Alexandre Chartre Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Subject: Re: [PATCH v6 26/30 (mawk fix)] objtool: Add function to get the name of a CPU feature Message-ID: <20251125132902.0cace2c8@pumpkin> In-Reply-To: <20251124164855.1036513-1-alexandre.chartre@oracle.com> References: <20251124164855.1036513-1-alexandre.chartre@oracle.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 24 Nov 2025 17:48:55 +0100 Alexandre Chartre wrote: > 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 > Signed-off-by: Peter Zijlstra (Intel) > Acked-by: Josh Poimboeuf > Link: https://patch.msgid.link/20251121095340.464045-27-alexandre.chartre@oracle.com > --- > .../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 > > diff --git a/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk b/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk > new file mode 100644 > index 0000000000000..cc4c7a3e6c2e2 > --- /dev/null > +++ b/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk > @@ -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] = {" 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. > + > + 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 "\"," David > +} > + > +/^#define X86_BUG_/ { > + if (match($0, value_expr)) { > + value = substr($0, RSTART + 1, RLENGTH - 2) > + print "\t[NCAPINTS*32+(" value ")] = \"" $2 "\"," > + } > +} > + > +END { > + print "};" > +} > diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore > index 759303657bd7c..73d883128511f 100644 > --- a/tools/objtool/.gitignore > +++ b/tools/objtool/.gitignore > @@ -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 > diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile > index df793ca6fc1a1..66397d755fe4b 100644 > --- a/tools/objtool/Makefile > +++ b/tools/objtool/Makefile > @@ -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 > diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/loongarch/special.c > index a80b75f7b061f..aba774109437f 100644 > --- a/tools/objtool/arch/loongarch/special.c > +++ b/tools/objtool/arch/loongarch/special.c > @@ -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; > +} > diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powerpc/special.c > index 51610689abf72..8f9bf61ca0899 100644 > --- a/tools/objtool/arch/powerpc/special.c > +++ b/tools/objtool/arch/powerpc/special.c > @@ -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; > +} > diff --git a/tools/objtool/arch/x86/Build b/tools/objtool/arch/x86/Build > index 3dedb2fd8f3a0..b95448ee01ee4 100644 > --- a/tools/objtool/arch/x86/Build > +++ b/tools/objtool/arch/x86/Build > @@ -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 > diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/special.c > index 09300761f1085..e817a3fff4491 100644 > --- a/tools/objtool/arch/x86/special.c > +++ b/tools/objtool/arch/x86/special.c > @@ -4,6 +4,10 @@ > #include > #include > #include > +#include > + > +/* 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; > +} > diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/include/objtool/special.h > index b22410745e4a1..121c3761899c1 100644 > --- a/tools/objtool/include/objtool/special.h > +++ b/tools/objtool/include/objtool/special.h > @@ -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 */