[m-dev.] Patch: support for shared objects on ARM

Sergey Khorev iamphet at nm.ru
Wed Dec 14 21:06:25 AEDT 2005


I've accidentally deleted previous thread so I've started the new one.
Finally, all tests passed.


diff -cr ../mercury-0.12.bak/configure.in ./configure.in
*** ../mercury-0.12.bak/configure.in	Mon Dec  5 09:03:57 2005
--- ./configure.in	Wed Dec 14 13:06:33 2005
***************
*** 3432,3437 ****
--- 3432,3451 ----
  		    AC_MSG_RESULT(no)
  		fi
  		;;
+ 	arm*-linux|arm*-linux-gnu)
+ 		AC_MSG_RESULT(yes)
+ 		EXT_FOR_SHARED_LIB=so
+ 		EXT_FOR_LINK_WITH_PIC_OBJECTS=o
+ 		# One can build gcc with a default PIC register other than sl
+ 		# so let's force it. If you change this, 
+ 		# update MR_ARM_PIC_REG in runtime/mercury_goto.h as well.
+ 		# -fomit-frame-pointer is required 
+ 		# to work with other optimised shared objects:
+ 		# it seems it's better to keep this optimisation 
+ 		# always turned on rather than always turned off
+ 		CFLAGS_FOR_PIC="-mpic-register=sl -fomit-frame-pointer \
+ 				$CFLAGS_FOR_PIC"
+ 		;;
  	*)
  		# CFLAGS_FOR_PIC is used by boehm_gc/Makefile when creating
  		# libgc.a.  If the system doesn't support shared libraries,
diff -cr ../mercury-0.12.bak/runtime/mercury_goto.h ./runtime/mercury_goto.h
*** ../mercury-0.12.bak/runtime/mercury_goto.h	Wed Apr 14 06:31:56 2004
--- ./runtime/mercury_goto.h	Wed Dec 14 13:06:33 2005
***************
*** 465,470 ****
--- 465,525 ----
  	"	.type _entry_" MR_STRINGIFY(label) ",#function\n"
    #endif
  
+ #elif defined(__arm__)
+ 
+   #if MR_PIC
+ 
+     /*
+     ** At each entry point, where we may have been jump to from
+     ** code in a difference C file, we need to set up the PIC register.
+     ** We do this by adding _GLOBAL_OFFSET_TABLE_ value to the PC register 
+     ** Current instruction address is (PC - 8) hence -(0b + 8)
+     ** (I don't understand the details exactly, this code is
+     ** basically copied from the output of `gcc -fpic -S' for a function
+     ** containing setjmp.)
+     ** A little bit more detail can be obtained from GCC source
+     ** (function arm_finalize_pic in gcc/config/arm/arm.c)
+     ** Note that `0f' means the label `0:' following the current
+     ** instruction, and `0b' means the label `0:' before the current
+     ** instruction.
+     ** GCC doesn't like when we clobber the PIC register but it seems we
+     ** can safely keep GCC uninformed because we just do GCC's work
+     ** and the PIC register is saved over call
+     ** Loading arbitrary immediate values into ARM registers is not possible
+     ** directly hence the .word directive in the code section and the branch 
+     ** instruction bypassing it.
+     ** If you change MR_ARM_PIC_REG, update CFLAGS_FOR_PIC (-mpic-register)
+     ** in configure.in.
+     */
+     #define MR_ARM_PIC_REG "sl"
+ 
+     #define MR_INLINE_ASM_FIXUP_REGS				\
+       "	    ldr	" MR_ARM_PIC_REG ", 1f\n"			\
+       "0:\n"							\
+       "	    add	" MR_ARM_PIC_REG ", pc, " MR_ARM_PIC_REG "\n"	\
+       "	    b 2f\n"						\
+       "1:\n"							\
+       "	    .word	_GLOBAL_OFFSET_TABLE_-(0b+8)\n"		\
+       "2:\n"
+ 
+     /* For Linux-ELF shared libraries, we need to declare that the type of labels
+     ** is #function (i.e. code, not data), otherwise the dynamic linker seems
+     ** to get confused, and we end up jumping into the data section.
+     ** Hence the `.type' directive below.
+     */
+     #ifdef __ELF__
+       #define MR_INLINE_ASM_ENTRY_LABEL_TYPE(label) \
+ 	  "	.type _entry_" MR_STRINGIFY(label) ",#function\n"
+     #endif
+ 
+     /*
+     ** Save few CPU ticks branching past MR_INLINE_ASM_FIXUP_REGS
+     */
+     #define MR_ASM_FALLTHROUGH(label) \
+       goto MR_skip(label);
+ 
+   #endif
+ 
  #endif
  
  /* for other architectures, these macros have default definitions */
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list