summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-10-14 11:48:43 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-10-14 12:03:30 +0200
commit1e4a948673d709a2f8fcb9229b3cca77f3a25d51 (patch)
tree3e55bf42cf7bef48b1e304914a273786102fd676 /include
parent59523901d29386f0bf86750b6bf8c8222ab22a33 (diff)
downloadbarebox-1e4a948673d709a2f8fcb9229b3cca77f3a25d51.tar.gz
barebox-1e4a948673d709a2f8fcb9229b3cca77f3a25d51.tar.xz
command: Use array of pointers to commands
We used to store the commands as a linker array. One problem with this is that on X86_64 for unknown reasons the linker uses a different struct alignment than the compiler, so when we use the linker to compose the array and the compiler to iterate over it we have to play tricks with manually adjusting the alignment. The other problem is that we declare the commands as const (and also put it in .rodata), but in fact we do not treat it as const: we put the commands onto a list which modifies the struct list_head list member of struct command. With this patch we no longer put the command themselves into an array, but instead create an array of pointers to the commands. This inherently solves the second issue as well. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/command.h21
1 files changed, 9 insertions, 12 deletions
diff --git a/include/command.h b/include/command.h
index 0afc5c7550..7555d0053c 100644
--- a/include/command.h
+++ b/include/command.h
@@ -53,15 +53,10 @@ struct command {
const char *help; /* Help message (long) */
void (*usage)(void);
#endif
-}
-#ifdef __x86_64__
-/* This is required because the linker will put symbols on a 64 bit alignment */
-__attribute__((aligned(64)))
-#endif
-;
+};
-extern struct command __barebox_cmd_start;
-extern struct command __barebox_cmd_end;
+extern struct command * const __barebox_cmd_start[];
+extern struct command * const __barebox_cmd_end[];
/* common/command.c */
@@ -89,10 +84,12 @@ int run_command(const char *cmd);
#endif /* __ASSEMBLY__ */
-#define BAREBOX_CMD_START(_name) \
-extern const struct command __barebox_cmd_##_name; \
-const struct command __barebox_cmd_##_name \
- __attribute__ ((unused,section (".barebox_cmd_" __stringify(_name)))) = { \
+#define BAREBOX_CMD_START(_name) \
+static struct command __barebox_cmd_##_name; \
+const struct command *barebox_cmd_##_name \
+ __attribute__ ((unused,section (".barebox_cmd_" __stringify(_name)))) \
+ = &__barebox_cmd_##_name; \
+static struct command __barebox_cmd_##_name = { \
.name = #_name,
#define BAREBOX_CMD_END \