- __COMMAND(#section, name, #name, args, cmd, flags, 1, idby, handler, NULL)
-#define TOPLEVEL(name, args, cmd, flags, idby, handler, help) \
- __COMMAND(NULL, name, #name, args, cmd, flags, 0, idby, handler, help)
-extern struct cmd __start___cmd;
-extern struct cmd __stop___cmd;
+ __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 1, idby, handler, NULL, NULL)
+
+#define TOPLEVEL(_name, _args, _nlcmd, _flags, _idby, _handler, _help) \
+ struct cmd \
+ __section ## _ ## _name \
+ __attribute__((used)) __attribute__((section("__cmd"))) = { \
+ .name = (#_name), \
+ .args = (_args), \
+ .cmd = (_nlcmd), \
+ .nl_msg_flags = (_flags), \
+ .idby = (_idby), \
+ .handler = (_handler), \
+ .help = (_help), \
+ }
+#define SECTION(_name) \
+ struct cmd __section ## _ ## _name \
+ __attribute__((used)) __attribute__((section("__cmd"))) = { \
+ .name = (#_name), \
+ .hidden = 1, \
+ }
+
+#define DECLARE_SECTION(_name) \
+ extern struct cmd __section ## _ ## _name;