[m-rev.] diff: make shared libs work in asm_fast grades on x86_64

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Aug 1 16:08:50 AEST 2006


I'm not going to commit this until I fix some problems with some of
the G12 components w.r.t to PIC.

Estimated hours taken: 4.5
Branches: main, release

Add support for shared libraries on x86_64 Linux.

configure.in:
 	Enable for support for shared libraries on x86-64 Linux ELF
 	systems.

 	Make the default linkage shared on x86_64.

runtime/machdeps/x86_64_regs.h:
 	Add an explanation of a problem with our use of r15 as a global
 	register and PIC with the medium and large code models.  (We
 	don't encounter this problem because we currently use the small
 	code model.)

 	Fix the comments attached to the register variable declarations.
 	We do not have three different versions of succip.

runtime/mercury_goto.h:
 	Add x86_64 specific hacks.

scripts/mgnuc.in:
 	Conform to the above changes.

Julien.

Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.457
diff -u -r1.457 configure.in
--- configure.in	25 Jul 2006 14:03:56 -0000	1.457
+++ configure.in	1 Aug 2006 05:06:24 -0000
@@ -2067,7 +2067,7 @@
  	mips-*)
  		CFLAGS_FOR_GOTOS="$CFLAGS_FOR_GOTOS -fomit-frame-pointer"
  		;;
-	i*86-*)
+	i*86-*|x86_64*)
  		CFLAGS_FOR_REGS="-fno-builtin -fno-omit-frame-pointer"
  		;;
  	# We need a special-case hack here, because the auto-config 
@@ -3081,6 +3081,13 @@
  		NUM_REAL_R_TEMPS=0
  		HAVE_DELAY_SLOT=
  		;;
+	x86_64*)
+		# NUM_REAL_REGS=4
+		# but succip and sp are real reg, so subtract 2
+		NUM_REAL_R_REGS=2
+		NUM_REAL_R_TEMPS=0
+		HAVE_DELAY_SLOT=
+		;;
  	alpha*-*)
  		# NUM_REAL_REGS=7
  		# but succip, sp, and hp are real regs, so subtract 3
@@ -3261,7 +3268,7 @@
  DEFAULT_LINKAGE="shared"

  case "$host" in
-	i*86-*-linux|i*86-*-linux-gnu)
+	i*86-*-linux|i*86-*-linux-gnu|x86_64-*-linux*)
  		case $ac_cv_prog_gcc in
  		yes)
  			AC_MSG_RESULT(yes)
@@ -3311,7 +3318,15 @@
  		esac
  		# Shared libraries are not the default on x86 systems that
  		# use ELF -- see README.Linux
-		DEFAULT_LINKAGE=static
+		# They are the default on x86_64 systems that use ELF.
+		case "$host" in
+			i*86-*-linux|i*86-*-linux-gnu)
+				DEFAULT_LINKAGE=static
+				;;
+			*)
+				DEFAULT_LINKAGE=shared
+				;;
+		esac
  		;;
  	m68*-linux|m68*-linux-gnu)
  		AC_MSG_RESULT(yes)
Index: runtime/mercury_goto.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_goto.h,v
retrieving revision 1.44
diff -u -r1.44 mercury_goto.h
--- runtime/mercury_goto.h	25 Jul 2006 14:03:55 -0000	1.44
+++ runtime/mercury_goto.h	31 Jul 2006 14:28:31 -0000
@@ -275,11 +275,11 @@
    #define MR_ASM_FALLTHROUGH(label) \
    	goto MR_skip(label);

-#elif defined(__i386__) || defined(__mc68000__)
+#elif defined(__i386__) || defined(__mc68000__) || defined(__x86_64__)

    /*
    ** The following hack works around a stack leak on the i386.
-  ** (and apparently the 68000 too).
+  ** (and apparently the 68000 and x86_64 too).
    **
    ** The problem is that gcc pushes function parameters onto
    ** the stack when calling C functions such as GC_malloc(),
@@ -306,6 +306,11 @@
    	{ register int stack_pointer __asm__("esp");	\
    	__asm__("" : : "g"(stack_pointer)); }		\
    	goto *(label)
+  #elif defined(__x86_64__)
+    #define MR_ASM_JUMP(label)				\
+	{ register int stack_pointer __asm__("rsp");	\
+	__asm__("" : : "g"(stack_pointer)); }		\
+	goto *(label)
    #elif defined(__mc68000__)
      #define MR_ASM_JUMP(label)				\
    	{ register int stack_pointer __asm__("sp");	\
Index: runtime/machdeps/x86_64_regs.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/machdeps/x86_64_regs.h,v
retrieving revision 1.1
diff -u -r1.1 x86_64_regs.h
--- runtime/machdeps/x86_64_regs.h	30 Aug 2005 03:13:54 -0000	1.1
+++ runtime/machdeps/x86_64_regs.h	1 Aug 2006 05:01:00 -0000
@@ -15,14 +15,27 @@
  ** At the moment we're only using the callee-save registers
  ** (r12-r15).
  **
+** The following assignment of global registers assumes that
+** we are using the x86_64's small code model.  (For gcc
+** this is the default code model.)  If we ever use the medium or
+** large code models with PIC then we most probably will *not* be
+** able to use r15 as a global register (because it may be needed in
+** function prologues to calculate the GOT address).  In that case
+** we may be able to use rbx as a global register in place of r15.
+**
+** For further details see section 3.5.3 of:
+**
+**	System V Application Binary Interface
+** 	AMD64 Processor Architecture Supplement
+**
+** which is available at: <http://www.x86-64.org/documentation/>
  */
-
  #define MR_NUM_REAL_REGS 4

  register	MR_Word	MR_mr0 __asm__("r12");	/* sp */
  register	MR_Word	MR_mr1 __asm__("r13");	/* succip */
-register	MR_Word	MR_mr2 __asm__("r14");	/* succip */
-register	MR_Word	MR_mr3 __asm__("r15");	/* succip */
+register	MR_Word	MR_mr2 __asm__("r14");	/* r1 */
+register	MR_Word	MR_mr3 __asm__("r15");	/* r2 */

  #define MR_real_reg_number_mr0	r12
  #define MR_real_reg_number_mr1	r13
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.114
diff -u -r1.114 mgnuc.in
--- scripts/mgnuc.in	25 Jan 2006 04:57:48 -0000	1.114
+++ scripts/mgnuc.in	31 Jul 2006 05:52:21 -0000
@@ -441,7 +441,7 @@
              ;;
          esac
          ;;
-    i*86-*)
+    i*86-*|x86_64*)
          # The use of stack_pointer in the ASM_JUMP macro defined in
          # runtime/mercury_goto.h causes lots of warnings about using possibly
          # uninitialized variables; there's no easy way to supress them except

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list