[m-rev.] diff: shared objects on ARM

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Jan 4 16:08:23 AEDT 2006


Estimated hours taken: 0.5 (+ unknown by Sergey Khorev)
Branches: main, release

Commit Sergey Khorev's patch for supporting shared objects on the
ARM architecture.

configure.in:
runtime/mercury_goto.h:
	Support PIC and non-local gotos on the ARM architecture.

Julien.

Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.442
diff -u -r1.442 configure.in
--- configure.in	2 Dec 2005 06:53:18 -0000	1.442
+++ configure.in	4 Jan 2006 04:22:02 -0000
@@ -2076,7 +2076,7 @@
 # (Actually I don't know if `-fno-functions-cse' is really needed.
 # Maybe you can get away without it.  But better to err on the safe side...)
 #
-# For alpha and for mips, and probably on other architectures, when using
+# For alpha, mips, and ARM, and probably on other architectures, when using
 # non-local gotos we need -fomit-frame-pointer, otherwise when compiling
 # with --no-c-optimize we run into a problem similar to the one above:
 # Gcc generates code which initializes the frame pointer in the
@@ -2141,6 +2141,9 @@
 		mercury_cv_asm_labels=no
 		mercury_cv_gcc_labels=no
 		;;
+ 	arm*-*)
+ 		CFLAGS_FOR_GOTOS="$CFLAGS_FOR_GOTOS -fomit-frame-pointer"
+ 		;;
 	# On hppa64, ia64 and powerpc64 the test programs appear to work, but
 	# larger programs die with an Illegal Instruction fault.
 	hppa64-*)
@@ -3567,6 +3570,15 @@
 		    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.
+ 		CFLAGS_FOR_PIC="-mpic-register=sl $CFLAGS_FOR_PIC"
+ 		;;
 	*)
 		# CFLAGS_FOR_PIC is used by boehm_gc/Makefile when creating
 		# libgc.a.  If the system doesn't support shared libraries,
Index: runtime/mercury_goto.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_goto.h,v
retrieving revision 1.42
diff -u -r1.42 mercury_goto.h
--- runtime/mercury_goto.h	11 Oct 2005 04:45:52 -0000	1.42
+++ runtime/mercury_goto.h	4 Jan 2006 04:38:18 -0000
@@ -465,6 +465,66 @@
 	"	.type _entry_" MR_STRINGIFY(label) ",#function\n"
   #endif

+#elif defined(__arm__)
+
+   /*
+   ** The following code for supporting non-local gotos and PIC on ARM
+   ** is thanks to Sergey Khorev <iamphet at nm.ru>.
+   */
+   #if MR_PIC
+
+     /*
+     ** At each entry point, where we may have been jumped to from
+     ** code in a different 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 it 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 a few clock 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-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list