diff mbox series

[1/2] command.h: Add a U_BOOT_LONGHELP macro

Message ID 20231007191308.2222470-1-trini@konsulko.com
State Accepted
Delegated to: Tom Rini
Headers show
Series [1/2] command.h: Add a U_BOOT_LONGHELP macro | expand

Commit Message

Tom Rini Oct. 7, 2023, 7:13 p.m. UTC
In order to be able to discard unused long help texts without further
linker lists, add a macro for defining the long help messages which uses
__maybe_unused.  This allows us to discard them as unreferenced as part
of the link.

Signed-off-by: Tom Rini <trini@konsulko.com>
---
 include/command.h | 3 +++
 1 file changed, 3 insertions(+)

Comments

Simon Glass Oct. 7, 2023, 8:18 p.m. UTC | #1
On Sat, 7 Oct 2023 at 13:13, Tom Rini <trini@konsulko.com> wrote:
>
> In order to be able to discard unused long help texts without further
> linker lists, add a macro for defining the long help messages which uses
> __maybe_unused.  This allows us to discard them as unreferenced as part
> of the link.
>
> Signed-off-by: Tom Rini <trini@konsulko.com>
> ---
>  include/command.h | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass Oct. 15, 2023, 2:39 p.m. UTC | #2
Hi Tom,

On Sat, 7 Oct 2023 at 13:13, Tom Rini <trini@konsulko.com> wrote:
>
> In order to be able to discard unused long help texts without further
> linker lists, add a macro for defining the long help messages which uses
> __maybe_unused.  This allows us to discard them as unreferenced as part
> of the link.
>
> Signed-off-by: Tom Rini <trini@konsulko.com>
> ---
>  include/command.h | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/include/command.h b/include/command.h
> index 34ea989b39b4..a836ea795ab6 100644
> --- a/include/command.h
> +++ b/include/command.h
> @@ -322,6 +322,9 @@ int cmd_source_script(ulong addr, const char *fit_uname, const char *confname);
>  # define _CMD_HELP(x)
>  #endif
>
> +#define U_BOOT_LONGHELP(_cmdname, text)                                        \
> +       static __maybe_unused const char _cmdname##_help_text[] = text;

I just noticed this...do you really want the ; at the end? The only
purpose I can see is if you want the macro to compile to nothing.
Otherwise it is more normal to put it on the invocations, isn't it?

> +
>  #define U_BOOT_SUBCMDS_DO_CMD(_cmdname)                                        \
>         static int do_##_cmdname(struct cmd_tbl *cmdtp, int flag,       \
>                                  int argc, char *const argv[],          \
> --
> 2.34.1
>

Regards,
Simon
Tom Rini Oct. 16, 2023, 1:09 p.m. UTC | #3
On Sun, Oct 15, 2023 at 08:39:44AM -0600, Simon Glass wrote:
> Hi Tom,
> 
> On Sat, 7 Oct 2023 at 13:13, Tom Rini <trini@konsulko.com> wrote:
> >
> > In order to be able to discard unused long help texts without further
> > linker lists, add a macro for defining the long help messages which uses
> > __maybe_unused.  This allows us to discard them as unreferenced as part
> > of the link.
> >
> > Signed-off-by: Tom Rini <trini@konsulko.com>
> > ---
> >  include/command.h | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/include/command.h b/include/command.h
> > index 34ea989b39b4..a836ea795ab6 100644
> > --- a/include/command.h
> > +++ b/include/command.h
> > @@ -322,6 +322,9 @@ int cmd_source_script(ulong addr, const char *fit_uname, const char *confname);
> >  # define _CMD_HELP(x)
> >  #endif
> >
> > +#define U_BOOT_LONGHELP(_cmdname, text)                                        \
> > +       static __maybe_unused const char _cmdname##_help_text[] = text;
> 
> I just noticed this...do you really want the ; at the end? The only
> purpose I can see is if you want the macro to compile to nothing.
> Otherwise it is more normal to put it on the invocations, isn't it?

I'll drop that when I apply it.
Tom Rini Oct. 16, 2023, 9:32 p.m. UTC | #4
On Sat, Oct 07, 2023 at 03:13:07PM -0400, Tom Rini wrote:

> In order to be able to discard unused long help texts without further
> linker lists, add a macro for defining the long help messages which uses
> __maybe_unused.  This allows us to discard them as unreferenced as part
> of the link.
> 
> Signed-off-by: Tom Rini <trini@konsulko.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/include/command.h b/include/command.h
index 34ea989b39b4..a836ea795ab6 100644
--- a/include/command.h
+++ b/include/command.h
@@ -322,6 +322,9 @@  int cmd_source_script(ulong addr, const char *fit_uname, const char *confname);
 # define _CMD_HELP(x)
 #endif
 
+#define U_BOOT_LONGHELP(_cmdname, text)					\
+	static __maybe_unused const char _cmdname##_help_text[] = text;
+
 #define U_BOOT_SUBCMDS_DO_CMD(_cmdname)					\
 	static int do_##_cmdname(struct cmd_tbl *cmdtp, int flag,	\
 				 int argc, char *const argv[],		\