The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] scripts/sorttable: guard long_size under MCOUNT_SORT_ENABLED
@ 2026-06-03 19:17 Dakkshesh
  2026-07-10  0:22 ` Nathan Chancellor
  0 siblings, 1 reply; 2+ messages in thread
From: Dakkshesh @ 2026-06-03 19:17 UTC (permalink / raw)
  To: gregkh; +Cc: stable, linux-kernel, Dakkshesh

clang's -Wunused-but-set-global (a sub-warning of
-Wunused-but-set-variable, enabled via -Wall), points out an
unused static global variable in scripts/sorttable.c:

scripts/sorttable.c:452:12: error: variable 'long_size' set but not
  used [-Werror,-Wunused-but-set-variable]

long_size is only read inside MCOUNT_SORT_ENABLED blocks. In upstream,
it is implicitly resolved by commit b055f4c431e3 ("sorttable: Move ELF
parsing into scripts/elf-parse.[ch]") which refactors the file entirely.

Cc: stable@vger.kernel.org
Signed-off-by: Dakkshesh <beakthoven@gmail.com>
---
 scripts/sorttable.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/sorttable.c b/scripts/sorttable.c
index deed676bf..674b24a97 100644
--- a/scripts/sorttable.c
+++ b/scripts/sorttable.c
@@ -449,7 +449,9 @@ static inline void *get_index(void *start, int entsize, int index)
 }
 
 static int extable_ent_size;
+#ifdef MCOUNT_SORT_ENABLED
 static int long_size;
+#endif
 
 #define ERRSTR_MAXSZ	256
 
@@ -1311,7 +1313,9 @@ static int do_file(char const *const fname, void *addr)
 		};
 
 		e = efuncs;
+#ifdef MCOUNT_SORT_ENABLED
 		long_size		= 4;
+#endif
 		extable_ent_size	= 8;
 
 		if (r2(&ehdr->e32.e_ehsize) != sizeof(Elf32_Ehdr) ||
@@ -1348,7 +1352,9 @@ static int do_file(char const *const fname, void *addr)
 		};
 
 		e = efuncs;
+#ifdef MCOUNT_SORT_ENABLED
 		long_size		= 8;
+#endif
 		extable_ent_size	= 16;
 
 		if (r2(&ehdr->e64.e_ehsize) != sizeof(Elf64_Ehdr) ||
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] scripts/sorttable: guard long_size under MCOUNT_SORT_ENABLED
  2026-06-03 19:17 [PATCH] scripts/sorttable: guard long_size under MCOUNT_SORT_ENABLED Dakkshesh
@ 2026-07-10  0:22 ` Nathan Chancellor
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Chancellor @ 2026-07-10  0:22 UTC (permalink / raw)
  To: Dakkshesh; +Cc: gregkh, stable, linux-kernel

Hi Dakkshesh,

Thanks for the patch!

On Thu, Jun 04, 2026 at 12:47:08AM +0530, Dakkshesh wrote:
> clang's -Wunused-but-set-global (a sub-warning of
> -Wunused-but-set-variable, enabled via -Wall), points out an
> unused static global variable in scripts/sorttable.c:
> 
> scripts/sorttable.c:452:12: error: variable 'long_size' set but not
>   used [-Werror,-Wunused-but-set-variable]

Our CI also notices this in stable kernels, breaking our build due to
-Werror in at least 6.18 and newer.

  https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/28937469245

> long_size is only read inside MCOUNT_SORT_ENABLED blocks. In upstream,
> it is implicitly resolved by commit b055f4c431e3 ("sorttable: Move ELF
> parsing into scripts/elf-parse.[ch]") which refactors the file entirely.

FWIW, I am a little confused how b055f4c431e3 avoids this issue (even
though I confirmed that it did by a reverse bisect). If I preprocess
scripts/sorttable.c before and after that change, long_size is still
only set but not used. I think that this change (or a different version
of it, see below) is probably still relevant to upstream, rather than
just stable, even if the warning is not currently visible there. If
folks disagree with that assessment, the commit message should make it
more clear that this fix is intended for stable only.

> Cc: stable@vger.kernel.org
> Signed-off-by: Dakkshesh <beakthoven@gmail.com>
> ---
>  scripts/sorttable.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/sorttable.c b/scripts/sorttable.c
> index deed676bf..674b24a97 100644
> --- a/scripts/sorttable.c
> +++ b/scripts/sorttable.c
> @@ -449,7 +449,9 @@ static inline void *get_index(void *start, int entsize, int index)
>  }
>  
>  static int extable_ent_size;
> +#ifdef MCOUNT_SORT_ENABLED

These ifdefs are pretty ugly and Linus did not love them for a different
patch upstream:

  https://lore.kernel.org/CAHk-=wh9eUk9+BOGwP7ni4OZPZSCfgZQ43n53XWuh3rHhMxwfA@mail.gmail.com/

>  static int long_size;

I think it would be better to drop the ifdefs and just mark this as
__maybe_unused to be done with it. It should make the diff more
stomachable for silencing a warning like this.

> +#endif
>  
>  #define ERRSTR_MAXSZ	256
>  
> @@ -1311,7 +1313,9 @@ static int do_file(char const *const fname, void *addr)
>  		};
>  
>  		e = efuncs;
> +#ifdef MCOUNT_SORT_ENABLED
>  		long_size		= 4;
> +#endif
>  		extable_ent_size	= 8;
>  
>  		if (r2(&ehdr->e32.e_ehsize) != sizeof(Elf32_Ehdr) ||
> @@ -1348,7 +1352,9 @@ static int do_file(char const *const fname, void *addr)
>  		};
>  
>  		e = efuncs;
> +#ifdef MCOUNT_SORT_ENABLED
>  		long_size		= 8;
> +#endif
>  		extable_ent_size	= 16;
>  
>  		if (r2(&ehdr->e64.e_ehsize) != sizeof(Elf64_Ehdr) ||
> -- 
> 2.54.0
> 
> 

-- 
Cheers,
Nathan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-10  0:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 19:17 [PATCH] scripts/sorttable: guard long_size under MCOUNT_SORT_ENABLED Dakkshesh
2026-07-10  0:22 ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox