From patchwork Mon Jan 13 15:00:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937587 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89EA2233526; Mon, 13 Jan 2025 15:03:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780583; cv=none; b=LDa7dXw4UUvoVb+Iw9Can4W7J1g+OgHsanScYaJEtFCLgCx04enR2+yh9B8+PtsSIIvtV43Q2oP5+fE7pOTPR+LcDap7Q79p05tKWdbhwOmrd4PqP34SCpQRcmTh+pIpq8r08WnLvXRmHYGszG1IAENCpTTzb9ChtmEcEntSx9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780583; c=relaxed/simple; bh=ZWUl1EW6V5uS0plPjwVRpm99BGxULSuZis64ZLyce9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UcIjazTSzhhlCSjmitn2NyLiBWnDNPHVri1jtfLO2suvlFuzWR+vkW7/e0yXUArhokdNJNkl75kxDdoI6YOJP4q7hf/hNujJbiNVUiB+mW8Cym9GspdxWCK6QafvmiFGgvVukeprxw/fljTUZRQhoGQpS6AWP3KgT0f1BWEyZIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rdh+OAZj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rdh+OAZj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C72DC4CEE2; Mon, 13 Jan 2025 15:03:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780583; bh=ZWUl1EW6V5uS0plPjwVRpm99BGxULSuZis64ZLyce9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rdh+OAZjqDj/AHyZQJq6T3zB/NWIEBg17+3IQD4x7BNmrA2zx1v49a0Jza4Mdnna8 h8vKgMn941PUNUWzAsI8pbFszD3ArqkQplYOqfSXJznkGb9UeeLlHAuI+gPvm3y698 upgqd9F7bGYQyNAuUXItzSugOZoE3OzyJFMaumMEfRPNxZWZmB8eBE0T16dG0gttJz DjwZ4XX0EpS+tC+/pqGjMgWctGiy7ZFsiAnzF1AiMXeu9j/MlkLISFXmwz3oXsKwVD /B9V6uxfXs2LwirD8aMHaIdCnFAwm48AIjWY25JXQAXBT1yDl1dWGAyu29pSsWJl13 uTFJU8+aEXLmA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 01/17] genksyms: rename m_abstract_declarator to abstract_declarator Date: Tue, 14 Jan 2025 00:00:39 +0900 Message-ID: <20250113150253.3097820-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is called "abstract-declarator" in K&R. [1] I am not sure what "m_" stands for, but the name is clear enough without it. No functional changes are intended. [1] https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 689cb6bb40b6..02f2f713ec5a 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -367,17 +367,17 @@ parameter_declaration_list: ; parameter_declaration: - decl_specifier_seq m_abstract_declarator + decl_specifier_seq abstract_declarator { $$ = $2 ? $2 : $1; } ; -m_abstract_declarator: - ptr_operator m_abstract_declarator +abstract_declarator: + ptr_operator abstract_declarator { $$ = $2 ? $2 : $1; } - | direct_m_abstract_declarator + | direct_abstract_declarator ; -direct_m_abstract_declarator: +direct_abstract_declarator: /* empty */ { $$ = NULL; } | IDENT { /* For version 2 checksums, we don't want to remember @@ -391,13 +391,13 @@ direct_m_abstract_declarator: { remove_node($1); $$ = $1; } - | direct_m_abstract_declarator '(' parameter_declaration_clause ')' + | direct_abstract_declarator '(' parameter_declaration_clause ')' { $$ = $4; } - | direct_m_abstract_declarator '(' error ')' + | direct_abstract_declarator '(' error ')' { $$ = $4; } - | direct_m_abstract_declarator BRACKET_PHRASE + | direct_abstract_declarator BRACKET_PHRASE { $$ = $2; } - | '(' m_abstract_declarator ')' + | '(' abstract_declarator ')' { $$ = $3; } | '(' error ')' { $$ = $3; } From patchwork Mon Jan 13 15:00:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937588 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C94D2233546; Mon, 13 Jan 2025 15:03:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780584; cv=none; b=GdC7uLPgkVWgsZOOAZwchMGjq84iOMPkbkU50+6stOBFE/NL3C7Aiv+AeULK0yCmC/s9MKN/rFp0yEHOVXFvwM9UaeLwb5eb6zyQ8MRWJCdsgw24y3yVbA7717SPV7xv/9iwDnhXxf01eImVh8fSMbUFiAfvIzCIqyeeE3oaJpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780584; c=relaxed/simple; bh=uKOdfFpo12TyfwrgTckET9VqKFMxhOzj2aqUL9MOTu4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=auGwWVlEL9MX8XC5pOq9bDQMVXMgu1SI1v5CyxyzNqUbLuYRzpdjfbtclAkf8oAC4EDkMzT6OGZLrpOL/dTIK6I3hU3XWlfMu98DQcuPctlGdbWrhiyMrcTmMIRxKG+UpCro105Cwa6tNwGw7sb8QTX2cxFfBDwBYfH/PNks3qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qIXutRbi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qIXutRbi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D3BBC4CEE4; Mon, 13 Jan 2025 15:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780584; bh=uKOdfFpo12TyfwrgTckET9VqKFMxhOzj2aqUL9MOTu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qIXutRbiy7bE9KufK7rgNWSgT0eG5R8gkenifcu2A7eCoV8J+KB5XTyfGeavFTaqs lT+9a7rxKfn/6LnktMCfGcTi8qio+8pfxp/k6sH/CJkNWjKlr5CMszRDRMygb/Q2vH QOX8+bUW0zTwoOJSKqMYDiLFewHPXXRjVgxnGVqEaOliezMva0hErmRI4mnXR8OYK0 y2yACmcLnILWMeSWuQF1wT+Wh/r8lRxWr+zGRpKVW6jlv9t4NO+HWMTQR5IGwJGYPA MnDxVRXrD9zzFeVX7QSlkR5PQfG4Qpd4hslY40cAPd0dEIFS5IGRIG2uKG236sj2D0 rbAqlhJwi5BFg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 02/17] genksyms: rename cvar_qualifier to type_qualifier Date: Tue, 14 Jan 2025 00:00:40 +0900 Message-ID: <20250113150253.3097820-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 I believe "cvar" stands for "Const, Volatile, Attribute, or Restrict". This is called "type-qualifier" in K&R. [1] Adopt this more generic naming. No functional changes are intended. [1] https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 02f2f713ec5a..8f62b9f0d99c 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -223,7 +223,7 @@ storage_class_specifier: type_specifier: simple_type_specifier - | cvar_qualifier + | type_qualifier | TYPEOF_KEYW '(' parameter_declaration ')' | TYPEOF_PHRASE @@ -270,21 +270,21 @@ simple_type_specifier: ; ptr_operator: - '*' cvar_qualifier_seq_opt + '*' type_qualifier_seq_opt { $$ = $2 ? $2 : $1; } ; -cvar_qualifier_seq_opt: +type_qualifier_seq_opt: /* empty */ { $$ = NULL; } - | cvar_qualifier_seq + | type_qualifier_seq ; -cvar_qualifier_seq: - cvar_qualifier - | cvar_qualifier_seq cvar_qualifier { $$ = $2; } +type_qualifier_seq: + type_qualifier + | type_qualifier_seq type_qualifier { $$ = $2; } ; -cvar_qualifier: +type_qualifier: CONST_KEYW | VOLATILE_KEYW | ATTRIBUTE_PHRASE | RESTRICT_KEYW { /* restrict has no effect in prototypes so ignore it */ From patchwork Mon Jan 13 15:00:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937589 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CC78235BFC; Mon, 13 Jan 2025 15:03:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780586; cv=none; b=LYmJdcuQSchpu97zFsPhX+rKNJMucdtBhjYPcSpAAIZ4I055ohht2/4F4GxtMU+5S3qdgLfZJDQRsgUgCBAGsyc5uldRyklulyoxkd6hbZBP8qtxZ8xvwS9a8MymOZI0bV6r1POC5fy/MiB2pIqnh/86b/lT/DO00q4/A4TQgTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780586; c=relaxed/simple; bh=KbCf9wRYe6d1/pmWcTMzq+haySq2hrnChmFMYX55DDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=np1LNMec3/jVAy1HJDyb1EHyzrb5K8vHZ+hhrlttH/si7fgveGXCKLo/+s7AhYTGFf61Rvg58KOiWgRScKp9dd6lfrtg9qe9XwWFF8Kq98UNywbJGOHZTS9zJ0+BWeL2zVgdAlVxqo/TX0VuhFW8QyqPwHIuwQ8gmpCVCmivXJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NxKrZBxM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NxKrZBxM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE2FEC4CED6; Mon, 13 Jan 2025 15:03:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780585; bh=KbCf9wRYe6d1/pmWcTMzq+haySq2hrnChmFMYX55DDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NxKrZBxMd4bOQV7G8yzKhxTRx7/Po3cVNaE5l3OAmRbqK1eg1hElVKsfKhE7stO22 GFbXvjkxvoE4rDPGuktEptDJ/4jBY/zbAdgr0xjlIJGv7rlr4dmBWrW0x9jlvIAfO5 zsLvHl1KhIvRm6ST3ZRbNtjdX4gE19rJgZ1PQ5x0//JAMWarxbwLa41jFkWC9vLTN7 6a9tP1Uuldt7LZpQkZzklorQAbrAQNZJjCzTh7NUEOoTTklSPEDWvWHZi+zlNjRMKp U5bJVi4aB9KbUyfqgkMtOd4Wy0ORfAssmZnScu9Ku9JwEsHsff8VmkBllI7QXwgi9J 9h4dBbRzIbFbw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 03/17] genksyms: reduce type_qualifier directly to decl_specifier Date: Tue, 14 Jan 2025 00:00:41 +0900 Message-ID: <20250113150253.3097820-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A type_qualifier (const, volatile, etc.) is not a type_specifier. According to K&R [1], a type-qualifier should be directly reduced to a declaration-specifier. ::= | | [1]: https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 8f62b9f0d99c..20cb3db7f149 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -211,6 +211,7 @@ decl_specifier: $$ = $1; } | type_specifier + | type_qualifier ; storage_class_specifier: @@ -223,7 +224,6 @@ storage_class_specifier: type_specifier: simple_type_specifier - | type_qualifier | TYPEOF_KEYW '(' parameter_declaration ')' | TYPEOF_PHRASE From patchwork Mon Jan 13 15:00:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937590 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0285F23A574; Mon, 13 Jan 2025 15:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780587; cv=none; b=NDHaa2J+3dTJaFkOgiV7wUZOH/HRVqSX14You551DkVP9JgUWJ/ubEu4rc/54Z9I1pLh2YL/aFQmRPsvhTxix1ze1HloWoDDk0aqkxEs8WgOQ+RGyl9kJ+ixe0rWS/PaUl0bBbG8NR8AGyVxfrmVIeiiS+tmMMbw9u14oPJWJNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780587; c=relaxed/simple; bh=zGI68vhJO21Srfxst1zXsYQ6BW+4ZHnev/oN1irG8uo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iGpUtEbWSL9mAORGT6+T41vqaIX2hsQSuXKUqrk1WsbUAzbhAeC3unPHIYsQPyhNbx6nRdk2Bi/76yzbnLupwp9+i+XLqVFwphyh8JwECN5bfmDogI4VfJiXAbwxUNWzqGka7ele5CKGgxboVIjT7ohnOkXpVvuHs4xUbv0KajE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lH/jUXYq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lH/jUXYq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2204FC4CEE2; Mon, 13 Jan 2025 15:03:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780586; bh=zGI68vhJO21Srfxst1zXsYQ6BW+4ZHnev/oN1irG8uo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lH/jUXYqmH8ZKb1n/Aw11p/idXzeYHlV6QFUb2+Hd/8ma2lNv1USa0w4OBU0Ig1zO oQsu7RDV6nV09atjtgofArivwqHiTMvNoKrM8MeJSUnvU4Jd99rVS4+PASaW+i7b/S 7ZbjsGcbgfb+Pb6yUS/Ivmf0d4HdyJz+vsr6TIGfKJcRaeL7nSGMErW4ZUvR08Eb3b dYaU1WFRqeWNfi/ESqWc7jRwMus5qXaM/Qfyfe4okqqsmSL+jF/+GyuLnlE61PYLR5 z7yoILw1UJb4XIe850oAMI0/Xc5F0pmxNvtZ5Ss3vGlSZaWIiceFYPJutjXBYAghuM 8d98Kn7CvFBQQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 04/17] genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts Date: Tue, 14 Jan 2025 00:00:42 +0900 Message-ID: <20250113150253.3097820-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The genksyms parser has ambiguities in its grammar, which are currently suppressed by a workaround in scripts/genksyms/Makefile. Building genksyms with W=1 generates the following warnings: YACC scripts/genksyms/parse.tab.[ch] scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr] scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr] scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples The comment in the parser describes the current problem: /* This wasn't really a typedef name but an identifier that shadows one. */ Consider the following simple C code: typedef int foo; void my_func(foo foo) {} In the function parameter list (foo foo), the first 'foo' is a type specifier (typedef'ed as 'int'), while the second 'foo' is an identifier. However, the lexer cannot distinguish between the two. Since 'foo' is already typedef'ed, the lexer returns TYPE for both instances, instead of returning IDENT for the second one. To support shadowed identifiers, IDENT can be reduced to either a simple_type_specifier or a direct_abstract_declarator, which creates a grammatical ambiguity. Without analyzing the grammar context, it is very difficult to resolve this correctly. This commit introduces a flag, dont_want_type_specifier, which allows the parser to inform the lexer whether an identifier is expected. When dont_want_type_specifier is true, the type lookup is suppressed, and the lexer returns IDENT regardless of any preceding typedef. After this commit, only 3 shift/reduce conflicts will remain. Signed-off-by: Masahiro Yamada --- scripts/genksyms/genksyms.h | 3 +++ scripts/genksyms/lex.l | 9 ++++++++- scripts/genksyms/parse.y | 37 +++++++++++++++---------------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/scripts/genksyms/genksyms.h b/scripts/genksyms/genksyms.h index 8c45ada59ece..0c355075f0e6 100644 --- a/scripts/genksyms/genksyms.h +++ b/scripts/genksyms/genksyms.h @@ -12,6 +12,7 @@ #ifndef MODUTILS_GENKSYMS_H #define MODUTILS_GENKSYMS_H 1 +#include #include #include @@ -66,6 +67,8 @@ struct string_list *copy_list_range(struct string_list *start, int yylex(void); int yyparse(void); +extern bool dont_want_type_specifier; + void error_with_pos(const char *, ...) __attribute__ ((format(printf, 1, 2))); /*----------------------------------------------------------------------*/ diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l index a4d7495eaf75..e886133af578 100644 --- a/scripts/genksyms/lex.l +++ b/scripts/genksyms/lex.l @@ -12,6 +12,7 @@ %{ #include +#include #include #include #include @@ -113,6 +114,12 @@ MC_TOKEN ([~%^&*+=|<>/-]=)|(&&)|("||")|(->)|(<<)|(>>) /* The second stage lexer. Here we incorporate knowledge of the state of the parser to tailor the tokens that are returned. */ +/* + * The lexer cannot distinguish whether a typedef'ed string is a TYPE or an + * IDENT. We need a hint from the parser to handle this accurately. + */ +bool dont_want_type_specifier; + int yylex(void) { @@ -207,7 +214,7 @@ repeat: goto repeat; } } - if (!suppress_type_lookup) + if (!suppress_type_lookup && !dont_want_type_specifier) { if (find_symbol(yytext, SYM_TYPEDEF, 1)) token = TYPE; diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 20cb3db7f149..dc575d467bbf 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -12,6 +12,7 @@ %{ #include +#include #include #include #include "genksyms.h" @@ -148,6 +149,7 @@ simple_declaration: current_name = NULL; } $$ = $3; + dont_want_type_specifier = false; } ; @@ -169,6 +171,7 @@ init_declarator_list: is_typedef ? SYM_TYPEDEF : SYM_NORMAL, decl, is_extern); current_name = NULL; $$ = $1; + dont_want_type_specifier = true; } | init_declarator_list ',' init_declarator { struct string_list *decl = *$3; @@ -184,6 +187,7 @@ init_declarator_list: is_typedef ? SYM_TYPEDEF : SYM_NORMAL, decl, is_extern); current_name = NULL; $$ = $3; + dont_want_type_specifier = true; } ; @@ -210,7 +214,7 @@ decl_specifier: remove_node($1); $$ = $1; } - | type_specifier + | type_specifier { dont_want_type_specifier = true; $$ = $1; } | type_qualifier ; @@ -307,15 +311,7 @@ direct_declarator: current_name = (*$1)->string; $$ = $1; } - } - | TYPE - { if (current_name != NULL) { - error_with_pos("unexpected second declaration name"); - YYERROR; - } else { - current_name = (*$1)->string; - $$ = $1; - } + dont_want_type_specifier = false; } | direct_declarator '(' parameter_declaration_clause ')' { $$ = $4; } @@ -335,8 +331,7 @@ nested_declarator: ; direct_nested_declarator: - IDENT - | TYPE + IDENT { $$ = $1; dont_want_type_specifier = false; } | direct_nested_declarator '(' parameter_declaration_clause ')' { $$ = $4; } | direct_nested_declarator '(' error ')' @@ -362,8 +357,9 @@ parameter_declaration_list_opt: parameter_declaration_list: parameter_declaration + { $$ = $1; dont_want_type_specifier = false; } | parameter_declaration_list ',' parameter_declaration - { $$ = $3; } + { $$ = $3; dont_want_type_specifier = false; } ; parameter_declaration: @@ -375,6 +371,7 @@ abstract_declarator: ptr_operator abstract_declarator { $$ = $2 ? $2 : $1; } | direct_abstract_declarator + { $$ = $1; dont_want_type_specifier = false; } ; direct_abstract_declarator: @@ -385,12 +382,6 @@ direct_abstract_declarator: remove_node($1); $$ = $1; } - /* This wasn't really a typedef name but an identifier that - shadows one. */ - | TYPE - { remove_node($1); - $$ = $1; - } | direct_abstract_declarator '(' parameter_declaration_clause ')' { $$ = $4; } | direct_abstract_declarator '(' error ')' @@ -440,9 +431,9 @@ member_specification: member_declaration: decl_specifier_seq_opt member_declarator_list_opt ';' - { $$ = $3; } + { $$ = $3; dont_want_type_specifier = false; } | error ';' - { $$ = $2; } + { $$ = $2; dont_want_type_specifier = false; } ; member_declarator_list_opt: @@ -452,7 +443,9 @@ member_declarator_list_opt: member_declarator_list: member_declarator - | member_declarator_list ',' member_declarator { $$ = $3; } + { $$ = $1; dont_want_type_specifier = true; } + | member_declarator_list ',' member_declarator + { $$ = $3; dont_want_type_specifier = true; } ; member_declarator: From patchwork Mon Jan 13 15:00:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937591 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8909523C715; Mon, 13 Jan 2025 15:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780588; cv=none; b=VQ7zp7u4CXYl/c3lWCkQDgBtMywSXGWXJTRMGjYmmCmijxiIwg9+fb4pNp2OjvzHC4pvPG8bkeOGDjRNca7fMW7ouj4vX0AXvaHpLfvo1NS9Xew6nRpUStwv29wXOS7wRfZE0CdNeacverB6bLwbwsl4srgI+xqcE7Dce1Sdj7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780588; c=relaxed/simple; bh=H/QgONtgX+DHQUuK5veY4TDv2g+fNHM+DnMwui/0mbM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NT+Fl2e0CytX3oXkC2F8uXU8h4aYybDxC9Almri73rZmzdCwQ6tjeelMmc0aR/oo/dzkeNO9NbyyL61iqKmk3+Yl4NfjqJ6N/+nP1G+AfY4EMvBse4e5TvdtiqaOnARUFJJJzF8KimCOo4tdaCHNz7QArgrBf1XV/b6sfIzfmvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=os+r1svb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="os+r1svb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72E50C4CED6; Mon, 13 Jan 2025 15:03:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780588; bh=H/QgONtgX+DHQUuK5veY4TDv2g+fNHM+DnMwui/0mbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=os+r1svb+Tg+iVSzdbVEfEP3rlenUKnrjMe+27A31cqwhoBxrCx6/TMEQaKjZWbee QhztbZpH4BOWCWqCwfPdHhejmBl1hArIlda3ndzcnDkL9tIXtB5tuSYKm20h6cxV52 2fZV/laIvVcMcGmWJojuvVTYwul1gmFj/bBW1Mhl3BE9oJMGbpvXjD5iKpQwydLiNh IJXKuUSAQvazk6Bp3C/21zQFhtmcRLMeWKFGP1KAcZjj6KdXFwZDs8+1yyAqI5kxww qvqpagDHPSNP/WEsrgXZ1WwpivOEQ5hzVvq4fOpkTMNmVwKYEpwVfGE6shUfwO2bKg x1HAcDsFSGITA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 05/17] genksyms: fix last 3 shift/reduce conflicts Date: Tue, 14 Jan 2025 00:00:43 +0900 Message-ID: <20250113150253.3097820-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The genksyms parser has ambiguities in its grammar, which are currently suppressed by a workaround in scripts/genksyms/Makefile. Building genksyms with W=1 generates the following warnings: YACC scripts/genksyms/parse.tab.[ch] scripts/genksyms/parse.y: warning: 3 shift/reduce conflicts [-Wconflicts-sr] scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples The ambiguity arises when decl_specifier_seq is followed by '(' because the following two interpretations are possible: - decl_specifier_seq direct_abstract_declarator '(' parameter_declaration_clause ')' - decl_specifier_seq '(' abstract_declarator ')' This issue occurs because the current parser allows an empty string to be reduced to direct_abstract_declarator, which is incorrect. K&R [1] explains the correct grammar: ::= {}+ | {}+ | {}+ ::= | | ::= ( ) | {}? [ {}? ] | {}? ( {}? ) We need to consider the difference between the following two examples: [Example 1] ( ) can become void my_func(int (foo)); ... is equivalent to: void my_func(int foo); [Example 2] ( ) can become typedef int foo; void my_func(int (foo)); ... is equivalent to: void my_func(int (*callback)(int)); Please note that the function declaration is identical in both examples, but the preceding typedef creates the distinction. I introduced a new term, open_paren, to enable the type lookup immediately after the '(' token. Without this, we cannot distinguish between [Example 1] and [Example 2]. With this commit, all conflicts are resolved. [1]: https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index dc575d467bbf..fafce939c32f 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -363,35 +363,47 @@ parameter_declaration_list: ; parameter_declaration: - decl_specifier_seq abstract_declarator + decl_specifier_seq abstract_declarator_opt { $$ = $2 ? $2 : $1; } ; +abstract_declarator_opt: + /* empty */ { $$ = NULL; } + | abstract_declarator + ; + abstract_declarator: - ptr_operator abstract_declarator + ptr_operator + | ptr_operator abstract_declarator { $$ = $2 ? $2 : $1; } | direct_abstract_declarator { $$ = $1; dont_want_type_specifier = false; } ; direct_abstract_declarator: - /* empty */ { $$ = NULL; } - | IDENT + IDENT { /* For version 2 checksums, we don't want to remember private parameter names. */ remove_node($1); $$ = $1; } - | direct_abstract_declarator '(' parameter_declaration_clause ')' + | direct_abstract_declarator open_paren parameter_declaration_clause ')' { $$ = $4; } - | direct_abstract_declarator '(' error ')' + | direct_abstract_declarator open_paren error ')' { $$ = $4; } | direct_abstract_declarator BRACKET_PHRASE { $$ = $2; } - | '(' abstract_declarator ')' + | open_paren parameter_declaration_clause ')' { $$ = $3; } - | '(' error ')' + | open_paren abstract_declarator ')' { $$ = $3; } + | open_paren error ')' + { $$ = $3; } + | BRACKET_PHRASE + ; + +open_paren: + '(' { $$ = $1; dont_want_type_specifier = false; } ; function_definition: From patchwork Mon Jan 13 15:00:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937592 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F017323D3CD; Mon, 13 Jan 2025 15:03:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780590; cv=none; b=jMOK/QuxjB4oZMx6KwPQXt0rmEdsLmQRumH82DVc4QuoTTHIH8rSXMb/inHgEn4+B5IzBH/9QFNuwqSFasT3NQBDESda63ADT3RrDpon5JYRbD8ohETM+m6z7jM5zEtB9C08FgPXDpex4cgfGvR4/ocAGIiLF9/L9qdBTpPb8Vo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780590; c=relaxed/simple; bh=cKHuwhs5W1dFmJ/Kf1Fd8/c98XBQjhpg9ao/hRjEQc0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eII4F7S7+sYMknAuJ6H6Se6s2znrey3e/+NJR3xPDLXaUqpJd/aUnpTDln1MHHTgQn89LneUTkECj2MG7/S8XW53N3V3ZTTk0Q3uywEJhp2FrvLvnx/V1vX1vDYJWV3UAMPgpLOtZa/M3VM/3m6LF/1VWzdXdeZ3E42Orll1aTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wci9umLg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wci9umLg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4C4BC4CED6; Mon, 13 Jan 2025 15:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780589; bh=cKHuwhs5W1dFmJ/Kf1Fd8/c98XBQjhpg9ao/hRjEQc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wci9umLgdaVMz91h/b5FtSb8owqxICvJEVNMlG1p4eFmYOnQnQZsxHM6JLEnPb49b hovMl0v67L8atcDbIuV4vKeuFc/hfVblJiZ/6d2SokI/lE7o7CE7E8JsEZIrZiPkam x6lCD52EZ5WwJp83EG6KxfUK/DqdOrSdeCeb69TrjXgAiCKApu3Dq6PNeeio8mpVKk 48BaQ0USoyamf0e4mvrK41sLV4+8SnEU9mthH8B05EO/LEWu6Vx5UM+a4LXcCszcY1 OYj5rWNXiOH4c0KgvV/Eqg7HuVOMMCUV4YsiVP4R5Ru1pJPQRMk4G3vD9UNqZFEJQo Myl4wthhCIMEQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 06/17] genksyms: remove Makefile hack Date: Tue, 14 Jan 2025 00:00:44 +0900 Message-ID: <20250113150253.3097820-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This workaround was introduced for suppressing the reduce/reduce conflict warnings because the %expect-rr directive, which is applicable only to GLR parsers, cannot be used for genksyms. Since there are no longer any conflicts, this Makefile hack is now unnecessary. Signed-off-by: Masahiro Yamada --- scripts/genksyms/Makefile | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/scripts/genksyms/Makefile b/scripts/genksyms/Makefile index 312edccda736..4350311fb7b3 100644 --- a/scripts/genksyms/Makefile +++ b/scripts/genksyms/Makefile @@ -4,24 +4,6 @@ hostprogs-always-y += genksyms genksyms-objs := genksyms.o parse.tab.o lex.lex.o -# FIXME: fix the ambiguous grammar in parse.y and delete this hack -# -# Suppress shift/reduce, reduce/reduce conflicts warnings -# unless W=1 is specified. -# -# Just in case, run "$(YACC) --version" without suppressing stderr -# so that 'bison: not found' will be displayed if it is missing. -ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),) - -quiet_cmd_bison_no_warn = $(quiet_cmd_bison) - cmd_bison_no_warn = $(YACC) --version >/dev/null; \ - $(cmd_bison) 2>/dev/null - -$(obj)/pars%.tab.c $(obj)/pars%.tab.h: $(src)/pars%.y FORCE - $(call if_changed,bison_no_warn) - -endif - # -I needed for generated C source to include headers in source tree HOSTCFLAGS_parse.tab.o := -I $(src) HOSTCFLAGS_lex.lex.o := -I $(src) From patchwork Mon Jan 13 15:00:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937593 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EA8E23D3E9; Mon, 13 Jan 2025 15:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780591; cv=none; b=a+A6OkvVZ+7sVtbCGygbqNe5sgH6BS+xkZM7Iwla9lhKfc285kN9xUwgqsMS6LahK9skmlx3hmDPez8r1L2HjwgeLbeDxV2u561WETYeKvPUItQxHx6LJxSdymPtUABDr+QJJpM66Kpy0cuoZLP9xmoj4JX9z/oS1TFDgzgO+rQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780591; c=relaxed/simple; bh=RiN/aonjOGuE8UTKv6uSZEanQjGJXSf0h64lzIRusSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P+b32OyNCZjr23r5x84PrHIe5LkCcUcRUz6L8LF2pRlgqiW8kGdXZDhWV0jvBuOPk/d6Vk4pq+rlRtsr7wjjk+uDqkCaXs2r+I0GVOC86zSJlqTjm0dII4Q3COVgK4zA8MlmKcxw4xItA21sJzq+XYW9JPPzl/mQJC14MQKh+5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tSSVnEQ8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tSSVnEQ8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAF93C4CEE2; Mon, 13 Jan 2025 15:03:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780590; bh=RiN/aonjOGuE8UTKv6uSZEanQjGJXSf0h64lzIRusSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tSSVnEQ83o2jcOtXjKdeit1krsPUhKKU/H5EJa2Bd+f/9A1WgxKsu734qK7dnN6Qc p/8ym/8yEkQg2tE6fQz7UVC5cwq9mHK41RswxrW7TjQUZ7ZfJY4/toIFAVxy3HMW/U 8ql+5uYFtUfndOJVQtVrK8FiNcaeGzMR8pPg047Iuf5vq0KfufkU9+I2dMxV2mff6o pLk6H3TmKoNEpqZdYLIwql+gKx4B1BcvX29CHCjiMGPhBButUvIj9K6htEr23EZaZ5 viaZz29gA3CGN15fXd9cnSVHlsuApH80X/7EVPAo2T8dk6vAu6jVx+R7i+gpd7LT7Q b0L0cIIThBBUA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 07/17] genksyms: restrict direct-abstract-declarator to take one parameter-type-list Date: Tue, 14 Jan 2025 00:00:45 +0900 Message-ID: <20250113150253.3097820-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 While there is no more grammatical ambiguity in genksyms, the parser logic is still inaccurate. For example, genksyms accepts the following invalid C code: void my_func(int ()(int)); This should result in a syntax error because () cannot be reduced to . ( ) can be reduced, but must not be empty in the following grammar from K&R [1]: ::= ( ) | {}? [ {}? ] | {}? ( {}? ) Furthermore, genksyms accepts the following weird code: void my_func(int (*callback)(int)(int)(int)); The parser allows to recursively absorb multiple ( {}? ), but this behavior is incorrect. In the example above, (*callback) should be followed by at most one (int). [1]: https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index fafce939c32f..03cdd8d53c13 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -381,20 +381,24 @@ abstract_declarator: ; direct_abstract_declarator: + direct_abstract_declarator1 + | direct_abstract_declarator1 open_paren parameter_declaration_clause ')' + { $$ = $4; } + | open_paren parameter_declaration_clause ')' + { $$ = $3; } + ; + +direct_abstract_declarator1: IDENT { /* For version 2 checksums, we don't want to remember private parameter names. */ remove_node($1); $$ = $1; } - | direct_abstract_declarator open_paren parameter_declaration_clause ')' + | direct_abstract_declarator1 open_paren error ')' { $$ = $4; } - | direct_abstract_declarator open_paren error ')' - { $$ = $4; } - | direct_abstract_declarator BRACKET_PHRASE + | direct_abstract_declarator1 BRACKET_PHRASE { $$ = $2; } - | open_paren parameter_declaration_clause ')' - { $$ = $3; } | open_paren abstract_declarator ')' { $$ = $3; } | open_paren error ')' From patchwork Mon Jan 13 15:00:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937594 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7E7D23ED6F; Mon, 13 Jan 2025 15:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780592; cv=none; b=sjmgzKRamIT6KVAxOV3Qcw4RZuvq29YVoBHMIc9TzmJNgEiKCNIF+eqvVi+HjQS0idUNYW25wS064SC/5y6nZNTM2+H4cVW2jdGLd9kBXVmMyPktXy07E/qWGCEKE8OM4HNFt621PjiBW8XTy9A97PzD3IeeJqhZRdfF1O01big= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780592; c=relaxed/simple; bh=1XEqICoW5bCK9qLPwTMIN712gYss/wBf1UHwd91O+qs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HmcdPXZYh7SWEvUnv07HBxPxr7QdugL9hteYBO5MgphNx+q0kNZfdOXe6OMCZv3MGqaLSr+ZoLYmPnmQWUwA/fEFbw320dCGugLus0fiki/GBTV+Yr65BqxUE9KtCiv5yeMrTTd3V2ECwpdTDM+X+NEULtumDXHTcrpOrkmdQms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ANQQxS56; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ANQQxS56" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7143EC4CEE3; Mon, 13 Jan 2025 15:03:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780592; bh=1XEqICoW5bCK9qLPwTMIN712gYss/wBf1UHwd91O+qs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ANQQxS565+9aWe0jGHLytm+SW9qQ/i4NSolUnh1H72M5ArGKkxJX+NA/cubVH06d+ LOrVPluvrBttzhkTqIRWgeKVIpyCGwOg9grZ+wKZQs8jSlHfzyiwnoo14waa8Z+Z6e 3d3O7VFhdnDWSYQcaIF4n2L/gQ5aILs81E2Ep29pCOSatZ5cmehZ0lYN7LuVBt+FJP tuzyVafHn5Ev8xz0r5kzsnnXb+l4i3CIuJYN5zEQIvK1QiHfWklzHYE/GcanCNl9xL d341+N4SHYZXWlQLPGzcAojqq5PnVWiam84+S7JI29iPDcIq+yD1afAvnk6zP9gCaN 1pR858N/ztO7g== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 08/17] genksyms: restrict direct-declarator to take one parameter-type-list Date: Tue, 14 Jan 2025 00:00:46 +0900 Message-ID: <20250113150253.3097820-9-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Similar to the previous commit, this change makes the parser logic a little more accurate. Currently, genksyms accepts the following invalid code: struct foo { int (*callback)(int)(int)(int); }; A direct-declarator should not recursively absorb multiple ( parameter-type-list ) constructs. In the example above, (*callback) should be followed by at most one (int). Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 03cdd8d53c13..33a6aab53b69 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -331,12 +331,16 @@ nested_declarator: ; direct_nested_declarator: + direct_nested_declarator1 + | direct_nested_declarator1 '(' parameter_declaration_clause ')' + { $$ = $4; } + ; + +direct_nested_declarator1: IDENT { $$ = $1; dont_want_type_specifier = false; } - | direct_nested_declarator '(' parameter_declaration_clause ')' + | direct_nested_declarator1 '(' error ')' { $$ = $4; } - | direct_nested_declarator '(' error ')' - { $$ = $4; } - | direct_nested_declarator BRACKET_PHRASE + | direct_nested_declarator1 BRACKET_PHRASE { $$ = $2; } | '(' nested_declarator ')' { $$ = $3; } From patchwork Mon Jan 13 15:00:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937595 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E6B324633F; Mon, 13 Jan 2025 15:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780595; cv=none; b=tsVMGfW0mNQE6paZTEd+DYr9shAAOE+s60GeKF913Ok07rK43rKsMadTQFz2FSPehfpUJRNBGcjDQYb8xQvpG0NrbtStVAmoxC2wgmE7Ljf1p6GaSfjRLNVkv6VWqPBJa3NAWeENCH4DsIlJCjQXIU5Fxf1dwLzASJ4/krWDvvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780595; c=relaxed/simple; bh=PfKY4hMHBliNrr+kB89PDTK5pTJ42rOLJlyN9uzG4mc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oZL7zxme9r3iWFjuV3EvjcDMkT+UR/N8edyWB1aFFgeCEsywwUrqKmC1/ExuX7/2qXNeM5XfOOTwYXjiUHYU4tkdeAvNCVDVIkbHD/NKqFA6U7kbCLkRBxYXTzU7/R/Mxqk/NgOKFWozOlN7dHXYgojaZamhBqN9TnsPuCTy/xY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RxmAiebt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RxmAiebt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA006C4CEE5; Mon, 13 Jan 2025 15:03:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780593; bh=PfKY4hMHBliNrr+kB89PDTK5pTJ42rOLJlyN9uzG4mc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RxmAiebtvyZPCC94xe9haKdtqusNNEmaizgExpkrAXG21XJEZAQgcHCgg80rOXzAH ProxzWMix3qtzz22CMO3LKB/vL48r1O4beGC63O8SbO6xix1D1rH60m9OrcprWHWDt 37ceVZqpm8SYHgYmLdt2zZv7owN2Z2twS/EK2GwmMbjXD5q1x6FPGPomkZGMslXv2D s2/IpeozkfiC2nvqou3ox0jmxsvKzQSTSgCK7ES0K2QIKwO6fO1NrLSpTcihavyti1 M1GtIgaHRA0ol7LeNPxhXa94nLEUA7VxVrfW1zUVsHjQreWEgt8ssAoRk5hDyvx6Fs jWSIDe3tb7RKw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 09/17] genksyms: record attributes consistently for init-declarator Date: Tue, 14 Jan 2025 00:00:47 +0900 Message-ID: <20250113150253.3097820-10-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 I believe the missing action here is a bug. For rules with no explicit action, the following default is used: { $$ = $1; } However, in this case, $1 is the value of attribute_opt itself. As a result, the value of attribute_opt is always NULL. The following test code demonstrates inconsistent behavior. int x __attribute__((__aligned__(4))); int y __attribute__((__aligned__(4))) = 0; The attribute is recorded only when followed by an initializer. This commit adds the correct action to propagate the value of the ATTRIBUTE_PHRASE token. With this change, the attribute in the example above is consistently recorded for both 'x' and 'y'. [Before] $ cat < Defn for type0 y == Hash table occupancy 2/4096 = 0.000488281 [After] $ cat < Defn for type0 y == Hash table occupancy 2/4096 = 0.000488281 Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 33a6aab53b69..e3c160046143 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -480,7 +480,7 @@ member_bitfield_declarator: attribute_opt: /* empty */ { $$ = NULL; } - | attribute_opt ATTRIBUTE_PHRASE + | attribute_opt ATTRIBUTE_PHRASE { $$ = $2; } ; enum_body: From patchwork Mon Jan 13 15:00:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937596 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22987246342; Mon, 13 Jan 2025 15:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780595; cv=none; b=N4jx7pd7l2zIUrnF+UrNOzKKmPriKXW+Ieg5uB8UUTgM/Ll8OT8gaGP5FNFx2mLOR9tF+7hIhCJ7tQlQ1ilrYOcZdQ91OYI2vMXkv+Mu2Cuylj/HYjq91oEeqKhwL7ZDn/F2b7QMYg7n2KYYaC7ln0dliJiiMEBuIelxBXAp1HA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780595; c=relaxed/simple; bh=gl+dkIBbAjpPyPqoYKA51tUTj6PDx8224vetyPM6EYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PFxjMHHW1ywXK+Z2/oEi5mPdrpCtbhMIIKWgWy5pY89Yqov2RzAXP5oHeqwr4o5wL3dWYOzSO5LdhxwLl2uAJaYwUeS5mvFKgiHGj/eLVoKbD+MGx6YzmoRp5rk1qINqEiXrNBT/P9l7j9OraF6yyLHndLsThxLhisssyZRhxLA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P0/Ben0B; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P0/Ben0B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23829C4CEE3; Mon, 13 Jan 2025 15:03:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780595; bh=gl+dkIBbAjpPyPqoYKA51tUTj6PDx8224vetyPM6EYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P0/Ben0BNYE0WEm20vpagdfXDSPMD0TON5peRa0J12hcoikPV7dEBefUogk4XulZY WRFAKIZurFiUUkFBr0isGoDDDkX17OX2hq68j1eTCedau+k5dWP1CrCrV5WRj+ibIa vMeff4LitqfuXTxURHR+TwJLgFl7R9oEvvFp6ekEM4Ww0Y6lyAX3Udf6wzHXND6O03 ASbuEfp9syaF1QQ0iRHKPuUBAhmEh1LAIuu/FXmdjdKUj5r2ECiYZelo29jhEK8IXI n8Cg5VshZFXCUveGSXohW3UwuuRYG9C11DMdknSVGY8aFLul3WeiAm7RL5Mm1vY74i +jkF49ue0jK1w== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 10/17] genksyms: decouple ATTRIBUTE_PHRASE from type-qualifier Date: Tue, 14 Jan 2025 00:00:48 +0900 Message-ID: <20250113150253.3097820-11-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The __attribute__ keyword can appear in more contexts than 'const' or 'volatile'. To avoid grammatical conflicts with future changes, ATTRIBUTE_PHRASE should not be reduced into type_qualifier. No functional changes are intended. Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index e3c160046143..cd933a95548d 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -216,6 +216,7 @@ decl_specifier: } | type_specifier { dont_want_type_specifier = true; $$ = $1; } | type_qualifier + | ATTRIBUTE_PHRASE ; storage_class_specifier: @@ -285,11 +286,13 @@ type_qualifier_seq_opt: type_qualifier_seq: type_qualifier + | ATTRIBUTE_PHRASE | type_qualifier_seq type_qualifier { $$ = $2; } + | type_qualifier_seq ATTRIBUTE_PHRASE { $$ = $2; } ; type_qualifier: - CONST_KEYW | VOLATILE_KEYW | ATTRIBUTE_PHRASE + CONST_KEYW | VOLATILE_KEYW | RESTRICT_KEYW { /* restrict has no effect in prototypes so ignore it */ remove_node($1); From patchwork Mon Jan 13 15:00:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937597 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B05B284A5E; Mon, 13 Jan 2025 15:03:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780596; cv=none; b=kqLVkacKf5XdOdUiRJfHNUS9jqZo/EvSR15EboFfXhGd8X/awbdFTCQEeolH0jBR7VcZMOZZaoFngggD8YRqx5TmW7UIvyS9QIy/EbNgPOI++aNYe346zBZ9zyIF0sGxd7lXF93cZUrSJ9exgP9FseRmDSMqFhL91BFBvpDQl/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780596; c=relaxed/simple; bh=kTQ5gOGpVQ9PHwyiEtrh257p/iiiDkX5GwwMnmZsaUs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sVDALtzJntwgBspux7x/o5axz1sXzCO3OkBvPrGExeLAjeSTSlVeYep8GO1S2BS9hHAN0ZTTZvo53luSNAAsTLq4U8E4HaTAHLj7pev+nkVySDadzi0vxkX0/q2SzwdCWLpz0Vr1JxHxm6EtrTJvDdTjQaGVMY3p8Exa0cSk9LE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KOyuPKxU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KOyuPKxU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78948C4CED6; Mon, 13 Jan 2025 15:03:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780596; bh=kTQ5gOGpVQ9PHwyiEtrh257p/iiiDkX5GwwMnmZsaUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KOyuPKxU/uiMoYl/MXgGCeN4Dp6G6v98YPIntEtMGBEDvMwfAE+p0cedy68nDlCkQ N98rQbX3EYQ+k3Ss8FGyzkIo9Ik8w72rpXr4veikMhMHuqpXJkan3CHh1Aq6wvKOCL 8ZWH20up4LWzNv4/gdWaST18oNT7U4VDALNapkMTESFrfNs9sYgaNk7R6sQMsvqHE+ qZHgctKfTafHJ3bVINR8q6a5hXmg8eBkf31qQAFPProuw7G4C9RR5765P8jGZDJl5N RIoseEWWHP6v5G+ScPXBNUY0AvFZ6F8oaBBOWAuDjAYLcC7cW8nq4eW73KgA9+hZar 0LIVqhyU+CxnQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 11/17] genksyms: fix syntax error for attribute before abstract_declarator Date: Tue, 14 Jan 2025 00:00:49 +0900 Message-ID: <20250113150253.3097820-12-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A longstanding issue with genksyms is that it has hidden syntax errors. When a syntax error occurs, yyerror() is called. However, error_with_pos() is a no-op unless the -w option is provided. You can observe syntax errors by manually passing the -w option. For example, with CONFIG_MODVERSIONS=y on v6.13-rc1: $ make -s KCFLAGS=-D__GENKSYMS__ init/main.i $ cat init/main.i | scripts/genksyms/genksyms -w [ snip ] ./include/linux/efi.h:1225: syntax error The syntax error occurs in the following code in include/linux/efi.h: efi_status_t efi_call_acpi_prm_handler(efi_status_t (__efiapi *handler_addr)(u64, void *), u64 param_buffer_addr, void *context); The issue arises from __efiapi, which is defined as either __attribute__((ms_abi)) or __attribute__((regparm(0))). This commit allows abstract_declarator to be prefixed with attributes. To avoid conflicts, I tweaked the rule for decl_specifier_seq. Due to this change, a standalone attribute cannot become decl_specifier_seq. Otherwise, I do not know how to resolve the conflicts. The following code, which was previously accepted by genksyms, will now result in a syntax error: void my_func(__attribute__((unused))x); I do not think it is a big deal because GCC also fails to parse it. $ echo 'void my_func(__attribute__((unused))x);' | gcc -c -x c - :1:37: error: unknown type name 'x' Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index cd933a95548d..54e16c2e0b4b 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -203,8 +203,9 @@ decl_specifier_seq_opt: ; decl_specifier_seq: - decl_specifier { decl_spec = *$1; } + attribute_opt decl_specifier { decl_spec = *$2; } | decl_specifier_seq decl_specifier { decl_spec = *$2; } + | decl_specifier_seq ATTRIBUTE_PHRASE { decl_spec = *$2; } ; decl_specifier: @@ -216,7 +217,6 @@ decl_specifier: } | type_specifier { dont_want_type_specifier = true; $$ = $1; } | type_qualifier - | ATTRIBUTE_PHRASE ; storage_class_specifier: @@ -406,8 +406,8 @@ direct_abstract_declarator1: { $$ = $4; } | direct_abstract_declarator1 BRACKET_PHRASE { $$ = $2; } - | open_paren abstract_declarator ')' - { $$ = $3; } + | open_paren attribute_opt abstract_declarator ')' + { $$ = $4; } | open_paren error ')' { $$ = $3; } | BRACKET_PHRASE From patchwork Mon Jan 13 15:00:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937598 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C26428EC90; Mon, 13 Jan 2025 15:03:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780598; cv=none; b=IhCx4OfpoqGRWSA125SwgR0Hwox3qcBMTDxN7vinRG6l8tnpgp5Gzs/kBOEnwWg8xqDxnAsexaC0C8SqxFOtp+K4hhNPovgjhnEe/4dWtCE3SojYWv8H31LRhVsYvlVq85CJ20fmp24dxXrtwuJEg2HdIJq4ywhkX295X1Y/3Nc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780598; c=relaxed/simple; bh=AG7pHJDASGQ58M1lrrHCxlNDhJODKLJBdg+zBnInz6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ADGfrUxlxX6lZpBixvSTN7EcgNXBeyHR6amoJdY9fGnF6812IZqw2TiUiek7SvXWlvCgwSqHiMEXqpzd89kxbqULHt7vLEhjQFhw2kekqysKMssBqb6l1TbmH6Wxz+I+1XZ3Yn0trvbYmswi5J1WezNfV2c+1L2twTzUk0BHAzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H6s6jKkr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H6s6jKkr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E26EAC4CEE2; Mon, 13 Jan 2025 15:03:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780597; bh=AG7pHJDASGQ58M1lrrHCxlNDhJODKLJBdg+zBnInz6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H6s6jKkrHlmvC/OsWBWJ6bp2GrfWXip/OWkMRAc5xcbWiiiuOdKg3Ut4yKI+n7g3a Ji72gd0o1mroZvzzp/mdWjyON4r3hxOUUmsUBtJwAa9J/7tBqrQm5cPpqrN+jXqmCT K5McMI7qx6HOyz26OSmF9ewoO6ggjAQ65+neeaXTsJZQL4YYUh4oVk0jEERhlaTfMW cP/KNWqCRgh/YNTbBW3x46LR2VK/7cHuybVeaCx9qn7i/7O4f3ooyqnZqOxtW1SS/k b4RsIrttUYpslMWtjfRf0+jivFEunkDnDpu/Xx1Uf4tA7kV7iIHGH5i6n9xT9TweNl tNsMO3+3NGcVA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 12/17] genksyms: fix syntax error for attribute before nested_declarator Date: Tue, 14 Jan 2025 00:00:50 +0900 Message-ID: <20250113150253.3097820-13-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A longstanding issue with genksyms is that it has hidden syntax errors. When a syntax error occurs, yyerror() is called. However, error_with_pos() is a no-op unless the -w option is provided. You can observe syntax errors by manually passing the -w option. For example, with CONFIG_MODVERSIONS=y on v6.13-rc1: $ make -s KCFLAGS=-D__GENKSYMS__ drivers/acpi/prmt.i $ cat drivers/acpi/prmt.i | scripts/genksyms/genksyms -w [ snip ] drivers/acpi/prmt.c:56: syntax error The syntax error occurs in the following code in drivers/acpi/prmt.c: struct prm_handler_info { [ snip ] efi_status_t (__efiapi *handler_addr)(u64, void *); [ snip ] }; The issue arises from __efiapi, which is defined as either __attribute__((ms_abi)) or __attribute__((regparm(0))). This commit allows nested_declarator to be prefixed with attributes. Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 54e16c2e0b4b..49d3e536b9a8 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -345,8 +345,8 @@ direct_nested_declarator1: { $$ = $4; } | direct_nested_declarator1 BRACKET_PHRASE { $$ = $2; } - | '(' nested_declarator ')' - { $$ = $3; } + | '(' attribute_opt nested_declarator ')' + { $$ = $4; } | '(' error ')' { $$ = $3; } ; From patchwork Mon Jan 13 15:00:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937599 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2A1D28EC9D; Mon, 13 Jan 2025 15:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780599; cv=none; b=Ueqcf8KfE620v01Cyf9EjPfKxz8OEgp7qp3jgjY7GIKqUVrAd5YpOxQ/82TrJS2PYcXIESLGufQRe+/OcdUEhcuwWZ/h/sbb55f53oO8C3cSYl87PZdhSmxG4NU7zp7tt+6C5dUQzRuk0uf5nWw3lA1NQlzR1RVoF2KJWNQMEqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780599; c=relaxed/simple; bh=pgv9FKCG4AUzpL30eZ4Yc5tAtzFwIXBxtFKEtiHS16o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BVntp1rnG6jaPHpXGKtGmo6NA+T/P/2Td8xQYqiCWlFP5D5QrHwZE/wYfDs8UEyQy8HGiWMQUB6VfO1VFyT67U1mC6bqYC6RFT5IOIRN33Fh5YkHhQZDg4lwPiVpYXLArReNOgawKnzRvUowltHB6xPMB0/AActc1d2Y41gVgpM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DdWwVceL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DdWwVceL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36065C4CEE4; Mon, 13 Jan 2025 15:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780598; bh=pgv9FKCG4AUzpL30eZ4Yc5tAtzFwIXBxtFKEtiHS16o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DdWwVceLCHMLuzuEgLSNK2rbCDEULeWdGW76ek/OpnvdnsvhiTMGlJnWYatEv4XU3 NrnY7jhihiKc8cjbgMBakm+DiwqNfRbEfv7yi7TOCNBB8ZsJe7CqdcJFYIjx96DagE 3wd/66jbKGtV/QkfJF5/tpZyuHYpKLmbkpcqMzk9PjVUYtwjMdGetl6Q8dtZlCtTlj 2R7K7dzKAaFDFZGilK/ZgMNmBBsHjWm7kdXal+gYUCRERlXNHTg53s5gLAx6cxgiLu wkwuNCG61LkEN4l3rvnYKF4Vj1OBNq0KSA+BuQBF0pNeHBiwbGVAp10SC8iqOtmGbG 0w/K2COTaj1AQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 13/17] genksyms: fix syntax error for attribute after abstact_declarator Date: Tue, 14 Jan 2025 00:00:51 +0900 Message-ID: <20250113150253.3097820-14-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A longstanding issue with genksyms is that it has hidden syntax errors. When a syntax error occurs, yyerror() is called. However, error_with_pos() is a no-op unless the -w option is provided. You can observe syntax errors by manually passing the -w option. For example, with CONFIG_MODVERSIONS=y on v6.13-rc1: $ make -s KCFLAGS=-D__GENKSYMS__ kernel/module/main.i $ cat kernel/module/main.i | scripts/genksyms/genksyms -w [ snip ] kernel/module/main.c:97: syntax error The syntax error occurs in the following code in kernel/module/main.c: static void __mod_update_bounds(enum mod_mem_type type __maybe_unused, void *base, unsigned int size, struct mod_tree_root *tree) { [ snip ] } The issue arises from __maybe_unused, which is defined as __attribute__((__unused__)). This commit allows direct_abstract_declarator to be followed with attributes. Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 49d3e536b9a8..82774df50642 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -383,8 +383,8 @@ abstract_declarator: ptr_operator | ptr_operator abstract_declarator { $$ = $2 ? $2 : $1; } - | direct_abstract_declarator - { $$ = $1; dont_want_type_specifier = false; } + | direct_abstract_declarator attribute_opt + { $$ = $2; dont_want_type_specifier = false; } ; direct_abstract_declarator: From patchwork Mon Jan 13 15:00:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937600 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86E843DAC0E; Mon, 13 Jan 2025 15:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780601; cv=none; b=HBz5qLa8tdx/FLLag4mo6y1XMmlxujJLLnluWzPZlomUuGxbn6qEGGA08Q82S8iG1TrKvvU06h92/kc5nuVNu6887Y3uFyAuPEYGy3PTGpd1OGhyvt+Iyj+0XN7YGj/fZym7vBIEE/g48smo0/tYnSAvLmNjWwE8VTkMxhskeDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780601; c=relaxed/simple; bh=YOebZEpx92Zn2bKInQjvTjR90LO6pMXMhbWNbq0f53g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s69uFkPk5dYhYizgWLKmwUpxUwsHm2XfrjQ+xmgEU1BmzKxoXbG25rFI4QAXjtAuyOLrWr6O0Qarx8ESpbHO0K2l1XWTQIKcgwqYnY51g5YQlNjIlPVgSVKm6NzGdJh2pLpHg/qBFOEdn2GA3/R/Zh1JoaSiIZCv/O7kZ8rGtfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dB2nawas; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dB2nawas" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54FE6C4CEE3; Mon, 13 Jan 2025 15:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780600; bh=YOebZEpx92Zn2bKInQjvTjR90LO6pMXMhbWNbq0f53g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dB2nawasMmV+952PagoG4LKbCbqAEwgOrsEp5EbVu6Q4YX85cQAt1HqijcTE1lL7P ryO+K+wVax/gPA48gULD9a0RDqvPtBn4EBlLGwa+Ao8dxa4z5zGW2sABfZRvhPh6bG x0KxNesTgrnmpWG23ZdJUoBO0AR/dNfjw0XBRQP88vUhEzs2PZWYXKKH4n0RAuDdta +P6VRO8u7bZPcSD5tLrUzdk5XZcSlISzc9l28sJ6Ye5NhpFX4x+aWYVWWBPysEE7pF pUgEBQSHjeOW79/MJMmKTCQd13V7PiSLG105MD3qo8Acccmbks3vJEAOtVwFqQWEUT 7OUfy746TLsFw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 14/17] genksyms: fix syntax error for attribute after 'struct' Date: Tue, 14 Jan 2025 00:00:52 +0900 Message-ID: <20250113150253.3097820-15-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A longstanding issue with genksyms is that it has hidden syntax errors. When a syntax error occurs, yyerror() is called. However, error_with_pos() is a no-op unless the -w option is provided. You can observe syntax errors by manually passing the -w option. For example, with CONFIG_MODVERSIONS=y on v6.13-rc1: $ make -s KCFLAGS=-D__GENKSYMS__ arch/x86/kernel/cpu/mshyperv.i $ cat arch/x86/kernel/cpu/mshyperv.i | scripts/genksyms/genksyms -w [ snip ] ./arch/x86/include/asm/svm.h:122: syntax error The syntax error occurs in the following code in arch/x86/include/asm/svm.h: struct __attribute__ ((__packed__)) vmcb_control_area { [ snip ] }; The issue arises from __attribute__ immediately after the 'struct' keyword. This commit allows the 'struct' keyword to be followed by attributes. The lexer must be adjusted because dont_want_brace_phase should not be decremented while processing attributes. Signed-off-by: Masahiro Yamada --- scripts/genksyms/lex.l | 7 ++++++- scripts/genksyms/parse.y | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l index e886133af578..a1f969dcf24f 100644 --- a/scripts/genksyms/lex.l +++ b/scripts/genksyms/lex.l @@ -438,7 +438,12 @@ fini: if (suppress_type_lookup > 0) --suppress_type_lookup; - if (dont_want_brace_phrase > 0) + + /* + * __attribute__() can be placed immediately after the 'struct' keyword. + * e.g.) struct __attribute__((__packed__)) foo { ... }; + */ + if (token != ATTRIBUTE_PHRASE && dont_want_brace_phrase > 0) --dont_want_brace_phrase; yylval = &next_node->next; diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 82774df50642..33639232a709 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -234,16 +234,16 @@ type_specifier: /* References to s/u/e's defined elsewhere. Rearrange things so that it is easier to expand the definition fully later. */ - | STRUCT_KEYW IDENT - { remove_node($1); (*$2)->tag = SYM_STRUCT; $$ = $2; } + | STRUCT_KEYW attribute_opt IDENT + { remove_node($1); (*$3)->tag = SYM_STRUCT; $$ = $3; } | UNION_KEYW IDENT { remove_node($1); (*$2)->tag = SYM_UNION; $$ = $2; } | ENUM_KEYW IDENT { remove_node($1); (*$2)->tag = SYM_ENUM; $$ = $2; } /* Full definitions of an s/u/e. Record it. */ - | STRUCT_KEYW IDENT class_body - { record_compound($1, $2, $3, SYM_STRUCT); $$ = $3; } + | STRUCT_KEYW attribute_opt IDENT class_body + { record_compound($1, $3, $4, SYM_STRUCT); $$ = $4; } | UNION_KEYW IDENT class_body { record_compound($1, $2, $3, SYM_UNION); $$ = $3; } | ENUM_KEYW IDENT enum_body @@ -254,7 +254,7 @@ type_specifier: | ENUM_KEYW enum_body { add_symbol(NULL, SYM_ENUM, NULL, 0); $$ = $2; } /* Anonymous s/u definitions. Nothing needs doing. */ - | STRUCT_KEYW class_body { $$ = $2; } + | STRUCT_KEYW attribute_opt class_body { $$ = $3; } | UNION_KEYW class_body { $$ = $2; } ; From patchwork Mon Jan 13 15:00:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937601 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E5583DAC0F; Mon, 13 Jan 2025 15:03:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780601; cv=none; b=MRW4kDkDPKBo+6jiIh+sUJD9v+Is3PFV6nDtE5jY4iE3rtIzxmA50DFQU60/zhKd0y8qm4IwmwY7XXeqEiDLwEdWr9tVapZe3zq8SdKsb9f8qlLVcM134yrMzZCBkEjQgRMKYbXRc8qqYU3ZN+0ZV7+80Ef/fsRotaVMoGD2LHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780601; c=relaxed/simple; bh=irRz0rENFFet/M5R/l3u/tAEsJgv8MwLdXc5mdYqJa0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GCGJgmyj5np2F+a5F10QR2WqmHtAN2+3YFj59Zxn7mmXAhAbsQSp//1OR756jElr5TQSOw8TcspHLlIP4NIzMZ+P7mZzEhxjHhqCzTT3TzxI8J/YkCtnyVqVOL/KcbmfAAyb02raYaSfmQ7c7yisZu7+wm8bUCf+CJpb05HV9Tk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HKzl9sEW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HKzl9sEW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CD56C4CED6; Mon, 13 Jan 2025 15:03:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780601; bh=irRz0rENFFet/M5R/l3u/tAEsJgv8MwLdXc5mdYqJa0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HKzl9sEW61tLiFRhVyh09jnN1MKEu9IuOaNLbmpGLHrAS+2IIuIMWSxdUw4qIRY3s cVibJe7LTGvXoeFT/5WCK5SC/9yk8LG6QJccf6c8s8WN7PlQpJWjZ7vnHcJGZVKfxM aPWGDsiSwggi5obr+eONOkfXXP+gjTLbbOwl4AmR6MXRRg/VYaq7v/35Sw0yhszRCJ 7fIc61jcn7SX4ACCQFr6ZMKS2v2wfz4Qfn4D/DMOY8MTV5aWidTfvZKrMVccEF5vpq tu1yc/Mc80hc7pahTyfb0gRDV+4utNBkMFUXzbR+KacuSjKFfDZpno7pjn9Vyb1U4S YuxySDy5G709A== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 15/17] genksyms: fix syntax error for attribute after 'union' Date: Tue, 14 Jan 2025 00:00:53 +0900 Message-ID: <20250113150253.3097820-16-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A longstanding issue with genksyms is that it has hidden syntax errors. When a syntax error occurs, yyerror() is called. However, error_with_pos() is a no-op unless the -w option is provided. You can observe syntax errors by manually passing the -w option. For example, with CONFIG_MODVERSIONS=y on v6.13-rc1: $ make -s KCFLAGS=-D__GENKSYMS__ fs/lockd/svc.i $ cat fs/lockd/svc.i | scripts/genksyms/genksyms -w [ snip ] ./include/net/addrconf.h:35: syntax error The syntax error occurs in the following code in include/net/addrconf.h: union __packed { [ snip ] }; The issue arises from __attribute__ immediately after the 'union' keyword. This commit allows the 'union' keyword to be followed by attributes. Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index 33639232a709..a2cd035a78c9 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -236,16 +236,16 @@ type_specifier: so that it is easier to expand the definition fully later. */ | STRUCT_KEYW attribute_opt IDENT { remove_node($1); (*$3)->tag = SYM_STRUCT; $$ = $3; } - | UNION_KEYW IDENT - { remove_node($1); (*$2)->tag = SYM_UNION; $$ = $2; } + | UNION_KEYW attribute_opt IDENT + { remove_node($1); (*$3)->tag = SYM_UNION; $$ = $3; } | ENUM_KEYW IDENT { remove_node($1); (*$2)->tag = SYM_ENUM; $$ = $2; } /* Full definitions of an s/u/e. Record it. */ | STRUCT_KEYW attribute_opt IDENT class_body { record_compound($1, $3, $4, SYM_STRUCT); $$ = $4; } - | UNION_KEYW IDENT class_body - { record_compound($1, $2, $3, SYM_UNION); $$ = $3; } + | UNION_KEYW attribute_opt IDENT class_body + { record_compound($1, $3, $4, SYM_UNION); $$ = $4; } | ENUM_KEYW IDENT enum_body { record_compound($1, $2, $3, SYM_ENUM); $$ = $3; } /* @@ -255,7 +255,7 @@ type_specifier: { add_symbol(NULL, SYM_ENUM, NULL, 0); $$ = $2; } /* Anonymous s/u definitions. Nothing needs doing. */ | STRUCT_KEYW attribute_opt class_body { $$ = $3; } - | UNION_KEYW class_body { $$ = $2; } + | UNION_KEYW attribute_opt class_body { $$ = $3; } ; simple_type_specifier: From patchwork Mon Jan 13 15:00:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937602 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3447C1C5D53; Mon, 13 Jan 2025 15:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780603; cv=none; b=fj7hg2NVwEj7SPnez1tTRYS5pzmckRqi+0Klufv4v7U4rQiJDoki21GvVj487fAbueUNq0pXt/5Qsg2MnDRkkymxMn2vxqStINugT1XOx6Pcb6PHMNXicjCyccojYCxXXiQiytkMNTkid5+QrQHnoyZO77GysWbxOC5Q6/f49J4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780603; c=relaxed/simple; bh=M8vxA+N6dxX1TDO6D2OqIt0UpI6aGCTC68g5bvsCVds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B6ZIcuTKw59JhOsZBWz1a7oeiCbez/iTcGZUFzTx/80EwvcCMt6mgj4tO03PgU202wNZYGbvSHWlt4OH2b2oBslKysxvNgCUlCaE2y/zBRH8VvLTMFvTZZ5hyXa1KFDxl8oIoe4qzTDXql7K9mlmtsWo0cC4AgvbEi0mO/13yxM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CkAwDzYX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CkAwDzYX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0AB3C4CED6; Mon, 13 Jan 2025 15:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780602; bh=M8vxA+N6dxX1TDO6D2OqIt0UpI6aGCTC68g5bvsCVds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CkAwDzYX9FDk8Z3p19UlBIP0v/oKHMBDrh+11EN+EoJv2+nH2MzYlFm9/vhCX8xcL FD90BR/Zy+xtqY85AhxVooQRq38MW3wyisRdvYNCXMEfrfBq88E2krpdDDlRE9OWEZ cTmifRjxWy8DRTnjYjgExtL9TXScIy6vOg1Ufq8++PsIxKwlpCNomFqb5uoA7s5tHC nL7f1T73HRh7yZ8lyBmSj7ftmo/2e+Xa9u0z8zu/Hed/jaU3eMJxsS4kO0ko/L5OIi 3CLFOEA2pq8I1Oc3XSPmpg4xgOHuQUDKYci8va0NszQtttuPVcYIWHze0yCpbxijZY S2quhq23BgoQA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 16/17] genksyms: fix syntax error for builtin (u)int*x*_t types Date: Tue, 14 Jan 2025 00:00:54 +0900 Message-ID: <20250113150253.3097820-17-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A longstanding issue with genksyms is that it has hidden syntax errors. When a syntax error occurs, yyerror() is called. However, error_with_pos() is a no-op unless the -w option is provided. You can observe syntax errors by manually passing the -w option. For example, genksyms fails to parse the following code in arch/arm64/lib/xor-neon.c: static inline uint64x2_t eor3(uint64x2_t p, uint64x2_t q, uint64x2_t r) { [ snip ] } The syntax error occurs because genksyms does not recognize the uint64x2_t keyword. This commit adds support for builtin types described in Arm Neon Intrinsics Reference. Signed-off-by: Masahiro Yamada --- scripts/genksyms/lex.l | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l index a1f969dcf24f..22aeb57649d9 100644 --- a/scripts/genksyms/lex.l +++ b/scripts/genksyms/lex.l @@ -51,6 +51,7 @@ MC_TOKEN ([~%^&*+=|<>/-]=)|(&&)|("||")|(->)|(<<)|(>>) %% +u?int(8|16|32|64)x(1|2|4|8|16)_t return BUILTIN_INT_KEYW; /* Keep track of our location in the original source files. */ ^#[ \t]+{INT}[ \t]+\"[^\"\n]+\".*\n return FILENAME; From patchwork Mon Jan 13 15:00:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13937603 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BC201C5D78; Mon, 13 Jan 2025 15:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780604; cv=none; b=NCfyagb2EadEk17/2q9vUOa0+nozoszZ2qBnpfFQfGz9MoSwp9x15v64K5AguL5HHnui6e4M/Vez5iOddw6IMcYL/M4kc5zE9V2kuzFXFyugmFjJVpyPj0YbZfl2Rl5NeiCaznaD+iHuPwdkF4EbvgvSTTdnPsVukXyc6TTDNso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736780604; c=relaxed/simple; bh=kIUvhNzM7OmNhQu+exGqY1ty6rurLo/YLLZzSzfmQ/A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MGWD9rs9fx4lwMxfB/Ayrnzdtv7hWeVAbDlWxm+lnBIXE5CJgyb16Q6zx87xrYV2F0zqxDljaHnvs9ZzMVuzDxSVA/tkvGw3O0GxSClGNTEJDuq20x/Hu37jf8YKDUfiL+9G02X4wd+g5n2HXph97W9M3B5XM8VXxM4A3iKCMx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OCmMqQzy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OCmMqQzy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44520C4CEE3; Mon, 13 Jan 2025 15:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736780604; bh=kIUvhNzM7OmNhQu+exGqY1ty6rurLo/YLLZzSzfmQ/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OCmMqQzyeMMEGwd30DLMRA3NsZ7I/ViBExUa0BbOAfk4LsXhFig578Ps7i0xuPAfm RLUzSYFt0oOC3Ugc6jsimHiIrpvNpvGPY/arHY+lD32wB3271+k+UR7kiOmFP74/DL WcZD9JSHzNFIfR0iQw5nCH8DAQQT/82D6seDVpqpA0rr8OfLn3j+xgN2MTGFBxxBKI pUIlrdlvexAnq0ZREh5D3fn7WNNiXZfvyKx8TVoOjDsigptnWVkD8xGyl/Rqm467ef VwxQeTy1N5JtDoj6gJcoSQbEMY5eV99TPbpn7mp6b4uCg/dDeEelyXmqSN7N8J8/Sm AZxeNo3roFAMg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 17/17] genksyms: fix syntax error for attribute before init-declarator Date: Tue, 14 Jan 2025 00:00:55 +0900 Message-ID: <20250113150253.3097820-18-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org> References: <20250113150253.3097820-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A longstanding issue with genksyms is that it has hidden syntax errors. For example, genksyms fails to parse the following valid code: int x, __attribute__((__section__(".init.data")))y; Here, only 'y' is annotated by the attribute, although I am not aware of actual uses of this pattern in the kernel tree. When a syntax error occurs, yyerror() is called. However, error_with_pos() is a no-op unless the -w option is provided. You can observe syntax errors by manually passing the -w option. $ echo 'int x, __attribute__((__section__(".init.data")))y;' | scripts/genksyms/genksyms -w :1: syntax error This commit allows attributes to be placed between a comma and init_declarator. Signed-off-by: Masahiro Yamada --- scripts/genksyms/parse.y | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y index a2cd035a78c9..ee600a804fa1 100644 --- a/scripts/genksyms/parse.y +++ b/scripts/genksyms/parse.y @@ -173,9 +173,9 @@ init_declarator_list: $$ = $1; dont_want_type_specifier = true; } - | init_declarator_list ',' init_declarator - { struct string_list *decl = *$3; - *$3 = NULL; + | init_declarator_list ',' attribute_opt init_declarator + { struct string_list *decl = *$4; + *$4 = NULL; free_list(*$2, NULL); *$2 = decl_spec; @@ -186,7 +186,7 @@ init_declarator_list: add_symbol(current_name, is_typedef ? SYM_TYPEDEF : SYM_NORMAL, decl, is_extern); current_name = NULL; - $$ = $3; + $$ = $4; dont_want_type_specifier = true; } ;