Blob Blame History Raw
From d46ef7856c5b8f6f883350fc9523ca6c3399a1a5 Mon Sep 17 00:00:00 2001
From: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Date: Fri, 26 Feb 2016 11:26:54 +0530
Subject: [PATCH] core/stack: Fix __builtin_frame_address issue

GCC 6 warns if we pass nonzero values to __builtin_frame_address(). Hence
reorganize the code and pass zero to __builtin_frame_address().

core/stack.c: In function '__backtrace':
core/stack.c:34:17: error: calling '__builtin_frame_address' with a nonzero argument is unsafe [-Werror=frame-address]
  unsigned long *fp = __builtin_frame_address(1);

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 core/stack.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/core/stack.c b/core/stack.c
index 17f89d4..ead2b6d 100644
--- a/core/stack.c
+++ b/core/stack.c
@@ -31,10 +31,14 @@ extern uint32_t _stext, _etext;
 void __nomcount __backtrace(struct bt_entry *entries, unsigned int *count)
 {
 	unsigned int room = *count;
-	unsigned long *fp = __builtin_frame_address(1);
+	unsigned long *fp = __builtin_frame_address(0);
+
+	if (!fp || (unsigned long)fp > top_of_ram)
+		return;
 
 	*count = 0;
 	while(room) {
+		fp = (unsigned long *)fp[0];
 		if (!fp || (unsigned long)fp > top_of_ram)
 			break;
 		entries->sp = (unsigned long)fp;
@@ -42,7 +46,6 @@ void __nomcount __backtrace(struct bt_entry *entries, unsigned int *count)
 		entries++;
 		*count = (*count) + 1;
 		room--;
-		fp = (unsigned long *)fp[0];
 	}
 }
 
-- 
2.5.0