[Skiboot] [PATCH 3/4] branch-to-NULL assert for ELFv2 ABI

Nicholas Piggin npiggin at gmail.com
Wed Sep 25 11:01:35 AEST 2019


The ELFv1 branch to NULL catcher puts a function descriptor at 0 which
points to a function that asserts. For ELFv2, put a trap at address 0.

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 asm/head.S  |  2 ++
 core/init.c | 21 +++++++++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/asm/head.S b/asm/head.S
index e78dc520a..58f9aea97 100644
--- a/asm/head.S
+++ b/asm/head.S
@@ -35,6 +35,8 @@
 	. = 0
 .global __head
 __head:
+	trap
+
 	/* This entry point is used when booting with a flat device-tree
 	 * pointer in r3
 	 */
diff --git a/core/init.c b/core/init.c
index 7dc061198..62d9c709f 100644
--- a/core/init.c
+++ b/core/init.c
@@ -15,6 +15,7 @@
 #include <opal.h>
 #include <opal-msg.h>
 #include <elf.h>
+#include <elf-abi.h>
 #include <io.h>
 #include <cec.h>
 #include <device.h>
@@ -757,13 +758,25 @@ static void __nomcount do_ctors(void)
 		(*call)();
 }
 
-#ifndef PPC64_ELF_ABI_v2
+#ifdef ELF_ABI_v2
+static void setup_branch_null_catcher(void)
+{
+	asm volatile(							\
+		".section .rodata"				"\n\t"	\
+		"3:	.string	\"branch to NULL\""		"\n\t"	\
+		".previous"					"\n\t"	\
+		".section .trap_table,\"aw\""			"\n\t"	\
+		".llong	0"					"\n\t"	\
+		".llong	3b"					"\n\t"	\
+		".previous"					"\n\t"	\
+		);
+}
+#else
 static void branch_null(void)
 {
 	assert(0);
 }
 
-
 static void setup_branch_null_catcher(void)
 {
        void (*bn)(void) = branch_null;
@@ -775,10 +788,6 @@ static void setup_branch_null_catcher(void)
         */
        memcpy_null(0, bn, 16);
 }
-#else
-static void setup_branch_null_catcher(void)
-{
-}
 #endif
 
 void copy_sreset_vector(void)
-- 
2.23.0



More information about the Skiboot mailing list