From 6580e7f1a9dd0949dda354f463e778241ea73861 Mon Sep 17 00:00:00 2001 From: Kito Cheng Date: Tue, 23 Aug 2016 17:40:28 +0800 Subject: [PATCH] panic: Fix unaligned memory access panic Some target's gcc will detect the address is unaligned and then expand to byte load sequence, make the address to volatile can prevent gcc optimize it. BUG=none BRANCH=none TEST=make buildall; Verified that "crash unaligned" causes a panic on it83xx. Change-Id: Ieb4f5f8fc65854aefe307fa675fe87d7581452ed Signed-off-by: Kito Cheng Reviewed-on: https://chromium-review.googlesource.com/374281 Reviewed-by: Shawn N --- common/panic_output.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/panic_output.c b/common/panic_output.c index b278ac1acb..269f08db6c 100644 --- a/common/panic_output.c +++ b/common/panic_output.c @@ -177,8 +177,9 @@ static int command_crash(int argc, char **argv) stack_overflow_recurse(1); #endif } else if (!strcasecmp(argv[1], "unaligned")) { + volatile intptr_t unaligned_ptr = 0xcdef; cflush(); - ccprintf("%08x", *(volatile int *)0xcdef); + ccprintf("%08x", *(volatile int *)unaligned_ptr); } else if (!strcasecmp(argv[1], "watchdog")) { while (1) ;