musl/arch/sh/crt_arch.h
Rich Felker e9e770dfd6 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.
2015-09-22 20:51:59 +00:00

72 lines
1.2 KiB
C

#ifdef __SH_FDPIC__
__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"
" mov.l 1f, r5 \n"
" mov.l 1f+4, r6 \n"
" add r0, r5 \n"
" bsr __fdpic_fixup \n"
" add r0, r6 \n"
" mov r0, r12 \n"
#endif
" mov r10, r5 \n"
" mov r15, r4 \n"
" mov.l r9, @-r15 \n"
" mov.l r8, @-r15 \n"
" mov #-16, r0 \n"
" bsr " START "_c \n"
" and r0, r15 \n"
".align 2 \n"
"1: .long __ROFIXUP_LIST__@PCREL \n"
" .long __ROFIXUP_END__@PCREL + 4 \n"
);
#ifndef SHARED
#include "fdpic_crt.h"
#endif
#else
__asm__(
".text \n"
".global " START " \n"
START ": \n"
" mova 1f, r0 \n"
" mov.l 1f, r5 \n"
" add r0, r5 \n"
" mov r15, r4 \n"
" mov #-16, r0 \n"
" and r0, r15 \n"
" bsr " START "_c \n"
" nop \n"
".align 2 \n"
".weak _DYNAMIC \n"
".hidden _DYNAMIC \n"
"1: .long _DYNAMIC-. \n"
);
#endif
/* used by gcc for switching the FPU between single and double precision */
#ifdef SHARED
__attribute__((__visibility__("hidden")))
#endif
const unsigned long __fpscr_values[2] = { 0, 0x80000 };