about summary refs log tree commit diff
path: root/arch
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-09-22 03:54:42 +0000
committerRich Felker <dalias@aerifal.cx>2015-09-22 03:54:42 +0000
commit7a9669e977e5f750cf72ccbd2614f8b72ce02c4c (patch)
treed06ed21dee895141171fda5d73998df3d1cb9282 /arch
parent3958144ede01a7e64a56c0430f053bfd80ff02eb (diff)
downloadmusl-7a9669e977e5f750cf72ccbd2614f8b72ce02c4c.tar.gz
musl-7a9669e977e5f750cf72ccbd2614f8b72ce02c4c.tar.xz
musl-7a9669e977e5f750cf72ccbd2614f8b72ce02c4c.zip
add general fdpic support in dynamic linker and arch support for sh
at this point not all functionality is complete. the dynamic linker
itself, and main app if it is also loaded by the kernel, take
advantage of fdpic and do not need constant displacement between
segments, but additional libraries loaded by the dynamic linker follow
normal ELF semantics for mapping still. this fully works, but does not
admit shared text on nommu.

in terms of actual functional correctness, dlsym's results are
presently incorrect for function symbols, RTLD_NEXT fails to identify
the caller correctly, and dladdr fails almost entirely.

with the dynamic linker entry point working, support for static pie is
automatically included, but linking the main application as ET_DYN
(pie) probably does not make sense for fdpic anyway. ET_EXEC is
equally relocatable but more efficient at representing relocations.
Diffstat (limited to 'arch')
-rw-r--r--arch/sh/crt_arch.h3
-rw-r--r--arch/sh/reloc.h12
2 files changed, 12 insertions, 3 deletions
diff --git a/arch/sh/crt_arch.h b/arch/sh/crt_arch.h
index e9745f9b..b902dcc8 100644
--- a/arch/sh/crt_arch.h
+++ b/arch/sh/crt_arch.h
@@ -12,7 +12,10 @@ START ": \n"
 "	bsr __fdpic_fixup \n"
 "	 add r0, r6 \n"
 "	mov r0, r12 \n"
+"	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"
diff --git a/arch/sh/reloc.h b/arch/sh/reloc.h
index 73bacebb..c571fe4a 100644
--- a/arch/sh/reloc.h
+++ b/arch/sh/reloc.h
@@ -36,9 +36,15 @@
 #define REL_FUNCDESC    R_SH_FUNCDESC
 #define REL_FUNCDESC_VAL R_SH_FUNCDESC_VALUE
 #undef  REL_RELATIVE
-#define CRTJMP(pc,sp) __asm__ __volatile__( \
-	"mov.l @%0+,r0 ; mov.l @%0,r12 ; jmp @r0 ; mov %1,r15" \
-	: : "r"(pc), "r"(sp) : "r0", "memory" )
+#define DL_FDPIC 1
+#define CRTJMP(pc,sp) do { \
+	register size_t r8 __asm__("r8") = ((size_t *)(sp))[-2]; \
+	__asm__ __volatile__( "jmp @%0 ; mov %1,r15" \
+	: : "r"(pc), "r"(sp), "r"(r8) : "memory" ); } while(0)
+#define GETFUNCSYM(fp, sym, got) __asm__ ( \
+	"mov.l 1f,%0 ; add %1,%0 ; bra 2f ; nop ; .align 2 \n" \
+	"1:	.long " #sym "@GOTOFFFUNCDESC \n2:" \
+	: "=&r"(*fp) : "r"(got) : "memory" )
 #else
 #define CRTJMP(pc,sp) __asm__ __volatile__( \
 	"jmp @%0 ; mov %1,r15" : : "r"(pc), "r"(sp) : "memory" )