bootstate: use structure pointers for scheduling callbacks
The GCC 4.9.2 update showed that the boot_state_init_entry
structures were being padded and assumed to be aligned in to an
increased size. The bootstate scheduler for static entries,
boot_state_schedule_static_entries(), was then calculating the
wrong values within the array. To fix this just use a pointer to
the boot_state_init_entry structure that needs to be scheduled.
In addition to the previous issue noted above, the .bs_init
section was sitting in the read only portion of the image while
the fields within it need to be writable. Also, the
boot_state_schedule_static_entries() was using symbol comparison
to terminate a loop which in C can lead the compiler to always
evaluate the loop at least once since the language spec indicates
no 2 symbols can be the same value.
Change-Id: I6dc5331c2979d508dde3cd5c3332903d40d8048b
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/8699
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
diff --git a/src/lib/dynamic_cbmem.c b/src/lib/dynamic_cbmem.c
index daa3717..3b008c7 100644
--- a/src/lib/dynamic_cbmem.c
+++ b/src/lib/dynamic_cbmem.c
@@ -435,11 +435,7 @@
cbmem_initialize();
}
-BOOT_STATE_INIT_ENTRIES(cbmem_bscb) = {
- BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY,
- init_cbmem_pre_device, NULL),
-};
-
+BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, init_cbmem_pre_device, NULL);
#else
static void init_cbmem_post_device(void *unused)
@@ -450,10 +446,8 @@
cbmem_initialize_empty();
}
-BOOT_STATE_INIT_ENTRIES(cbmem_bscb) = {
- BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY,
- init_cbmem_post_device, NULL),
-};
+BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY,
+ init_cbmem_post_device, NULL);
#endif
void cbmem_add_bootmem(void)
diff --git a/src/lib/gcov-glue.c b/src/lib/gcov-glue.c
index ab9062b..615624f 100644
--- a/src/lib/gcov-glue.c
+++ b/src/lib/gcov-glue.c
@@ -150,8 +150,6 @@
__gcov_flush();
}
-BOOT_STATE_INIT_ENTRIES(gcov_bscb) = {
- BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, coverage_init, NULL),
- BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, coverage_exit, NULL),
- BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, coverage_exit, NULL),
-};
+BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, coverage_init, NULL);
+BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, coverage_exit, NULL);
+BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, coverage_exit, NULL);
diff --git a/src/lib/hardwaremain.c b/src/lib/hardwaremain.c
index 32162eb..d16aa09 100644
--- a/src/lib/hardwaremain.c
+++ b/src/lib/hardwaremain.c
@@ -432,18 +432,16 @@
static void boot_state_schedule_static_entries(void)
{
- extern struct boot_state_init_entry _bs_init_begin;
- extern struct boot_state_init_entry _bs_init_end;
- struct boot_state_init_entry *cur;
+ extern struct boot_state_init_entry *_bs_init_begin[];
+ struct boot_state_init_entry **slot;
- cur = &_bs_init_begin;
+ for (slot = &_bs_init_begin[0]; *slot != NULL; slot++) {
+ struct boot_state_init_entry *cur = *slot;
- while (cur != &_bs_init_end) {
if (cur->when == BS_ON_ENTRY)
boot_state_sched_on_entry(&cur->bscb, cur->state);
else
boot_state_sched_on_exit(&cur->bscb, cur->state);
- cur++;
}
}
diff --git a/src/lib/rmodule.ld b/src/lib/rmodule.ld
index c1669be..065b5b6 100644
--- a/src/lib/rmodule.ld
+++ b/src/lib/rmodule.ld
@@ -49,6 +49,8 @@
. = ALIGN(8);
_bs_init_begin = .;
KEEP(*(.bs_init));
+ LONG(0);
+ LONG(0);
_bs_init_end = .;
. = ALIGN(8);