From e9e770dfd6224a5ff7932b6115a35005dce7be29 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Tue, 22 Sep 2015 20:51:59 +0000
Subject: have sh/fdpic entry point set fdpic personality if needed

the entry point code supports being loaded by a loader which is not
fdpic-aware (in practice, either kernel with mmu or qemu without fdpic
support). this mostly just works, but signal handling will wrongly use
a function descriptor address as a code address if the personality is
not adjusted to fdpic.

ideally this code could be placed with sigaction so that it's not
needed except if/when a signal handler is installed. however,
personality is incorrectly maintained per-thread by the kernel, rather
than per-process, so it's necessary to correct the personality before
any threads are started. also, in order to skip the personality
syscall when an fdpic-aware loader is used, we need to be able to
detect how the program was loaded, and this information is only
readily available at the entry point.
---
 arch/sh/crt_arch.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'arch/sh')

diff --git a/arch/sh/crt_arch.h b/arch/sh/crt_arch.h
index d63ce0d1..948bcb79 100644
--- a/arch/sh/crt_arch.h
+++ b/arch/sh/crt_arch.h
@@ -4,6 +4,18 @@ __asm__(
 ".text \n"
 ".global " START " \n"
 START ": \n"
+"	tst r8, r8 \n"
+"	bf 1f \n"
+"	mov #68, r3 \n"
+"	add r3, r3 \n"
+"	mov #8, r4 \n"
+"	swap.w r4, r4 \n"
+"	trapa #31 \n"
+"	nop \n"
+"	nop \n"
+"	nop \n"
+"	nop \n"
+"1:	nop \n"
 #ifndef SHARED
 "	mov r8, r4 \n"
 "	mova 1f, r0 \n"
-- 
cgit v1.2.3-70-g09d2