Re: [PATCH] compiler.h: Avoid the usage of __typeof_unqual__() when __GENKSYMS__ is defined
From: Uros Bizjak
Date: Sun Apr 13 2025 - 17:20:25 EST
On Sun, Apr 6, 2025 at 5:36 PM Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
> > You are still seeing the warnings because __typeof_unqual__
> > is not only the issue.
> >
> > Hint:
> >
> > $ make -s KCFLAGS=-D__GENKSYMS__ arch/x86/kernel/setup_percpu.i
> > $ grep 'this_cpu_off;' arch/x86/kernel/setup_percpu.i
>
> I see.
>
> With my workaround, this_cpu_off is declared as:
>
> extern __attribute__((section(".data..percpu" "..hot.."
> "this_cpu_off"))) __typeof__(unsigned long) this_cpu_off;
>
> while without workaround, the same variable is declared as:
>
> extern __seg_gs __attribute__((section(".data..percpu" "..hot.."
> "this_cpu_off"))) __typeof__(unsigned long) this_cpu_off;
>
> It looks that genksyms should be extended to handle (or ignore)
> __seg_gs/__seg_fs named address prefix. Somewhat surprising, because
> genksyms can process:
>
> extern __attribute__((section(".data..percpu" "..hot.."
> "const_current_task"))) __typeof__(struct task_struct * const
> __seg_gs) const_current_task
>
> without problems.
>
> I'm sorry, but I'm not able to extend genksyms with a new keyword by myself...
The following patch that handles typeof_unqual() as typeof(), and in
addition ignores __seg_gs similar to how other type qualifiers are
ignored, avoids genksyms errors.
Uros.
diff --git a/scripts/genksyms/keywords.c b/scripts/genksyms/keywords.c
index b85e0979a00c..ee1499d27061 100644
--- a/scripts/genksyms/keywords.c
+++ b/scripts/genksyms/keywords.c
@@ -17,6 +17,8 @@ static struct resword {
{ "__signed__", SIGNED_KEYW },
{ "__typeof", TYPEOF_KEYW },
{ "__typeof__", TYPEOF_KEYW },
+ { "__typeof_unqual", TYPEOF_KEYW },
+ { "__typeof_unqual__", TYPEOF_KEYW },
{ "__volatile", VOLATILE_KEYW },
{ "__volatile__", VOLATILE_KEYW },
{ "__builtin_va_list", VA_LIST_KEYW },
@@ -40,6 +42,10 @@ static struct resword {
// KAO. },
// { "attribute", ATTRIBUTE_KEYW },
+ // X86 named address space qualifiers
+ { "__seg_gs", X86_SEG_KEYW },
+ { "__seg_fs", X86_SEG_KEYW },
+
{ "auto", AUTO_KEYW },
{ "char", CHAR_KEYW },
{ "const", CONST_KEYW },
@@ -57,6 +63,7 @@ static struct resword {
{ "struct", STRUCT_KEYW },
{ "typedef", TYPEDEF_KEYW },
{ "typeof", TYPEOF_KEYW },
+ { "typeof_unqual", TYPEOF_KEYW },
{ "union", UNION_KEYW },
{ "unsigned", UNSIGNED_KEYW },
{ "void", VOID_KEYW },
diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
index ee600a804fa1..efdcf07c4eb6 100644
--- a/scripts/genksyms/parse.y
+++ b/scripts/genksyms/parse.y
@@ -91,6 +91,8 @@ static void record_compound(struct string_list **keyw,
%token TYPEOF_KEYW
%token VA_LIST_KEYW
+%token X86_SEG_KEYW
+
%token EXPORT_SYMBOL_KEYW
%token ASM_PHRASE
@@ -292,7 +294,8 @@ type_qualifier_seq:
;
type_qualifier:
- CONST_KEYW | VOLATILE_KEYW
+ X86_SEG_KEYW
+ | CONST_KEYW | VOLATILE_KEYW
| RESTRICT_KEYW
{ /* restrict has no effect in prototypes so ignore it */
remove_node($1);