Patrick Georgi (patrick@georgi-clan.de) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4719
-gerrit
commit da6092dbfb67b487e1334897a38f93246432b224 Author: Patrick Georgi patrick@georgi-clan.de Date: Sat Jan 18 18:26:56 2014 +0100
CAR_GLOBAL: enforce compiler to check if _start != _end
There are some fun rules C compilers can use to optimize their code. One of them is the assumption that two symbols point to two different addresses. In this case this wasn't true, resulting in unintended code execution (and later, a crash) with a clang build.
Change-Id: I1496b22e1d1869ed0610e321b6ec6a83252e9d8b Signed-off-by: Patrick Georgi patrick@georgi-clan.de --- src/cpu/x86/car.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/cpu/x86/car.c b/src/cpu/x86/car.c index 2eb3f79..3b766c8 100644 --- a/src/cpu/x86/car.c +++ b/src/cpu/x86/car.c @@ -74,10 +74,22 @@ void *car_get_var_ptr(void *var) return &migrated_base[offset]; }
+void run_migrations(car_migration_func_t *start, car_migration_func_t *end) __attribute__((noinline)); +void run_migrations(car_migration_func_t *start, car_migration_func_t *end) +{ + car_migration_func_t *migrate_func; + + /* Call all the migration functions. */ + migrate_func = start; + while (migrate_func != end) { + (*migrate_func)(); + migrate_func++; + } +} + void car_migrate_variables(void) { void *migrated_base; - car_migration_func_t *migrate_func; size_t car_data_size = &_car_data_end[0] - &_car_data_start[0];
/* Check if already migrated. */ @@ -96,10 +108,5 @@ void car_migrate_variables(void) /* Mark that the data has been moved. */ car_migrated = ~0;
- /* Call all the migration functions. */ - migrate_func = &_car_migrate_start; - while (migrate_func != &_car_migrate_end) { - (*migrate_func)(); - migrate_func++; - } + run_migrations(&_car_migrate_start, &_car_migrate_end); }