[m-dev.] Patch: support for shared objects on ARM
Sergey Khorev
iamphet at nm.ru
Thu Dec 15 16:26:37 AEDT 2005
SK> diff -cr ../mercury-0.12.bak/configure.in ./configure.in
SK> *** ../mercury-0.12.bak/configure.in Mon Dec 5 09:03:57 2005
SK> --- ./configure.in Wed Dec 14 13:06:33 2005
Sorry. That patch isn't fully correct. The fixed one is:
diff -cr ../mercury-compiler-0.12.1.bak/configure.in ./configure.in
*** ../mercury-compiler-0.12.1.bak/configure.in 2005-12-06 08:09:07.000000000 +0300
--- ./configure.in 2005-12-15 08:20:26.000000000 +0300
***************
*** 1960,1966 ****
# (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
# 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
--- 1960,1966 ----
# (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, 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
***************
*** 3432,3437 ****
--- 3432,3447 ----
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
+ CFLAGS_FOR_GOTOS="$CFLAGS_FOR_GOTOS -fomit-frame-pointer"
+ # 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,
diff -cr ../mercury-compiler-0.12.1.bak/runtime/mercury_goto.h ./runtime/mercury_goto.h
*** ../mercury-compiler-0.12.1.bak/runtime/mercury_goto.h 2004-04-14 05:31:56.000000000 +0400
--- ./runtime/mercury_goto.h 2005-12-15 08:16:42.000000000 +0300
***************
*** 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 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-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