[m-dev.] Patch: support for shared objects on ARM
Sergey Khorev
iamphet at nm.ru
Thu Dec 15 18:31:43 AEDT 2005
JF> That's great! I'll take a look at your (revised) patch sometime
JF> over the next few days.
That revised patch wasn't correct as well, I should have been more careful. Please have a look at the patch below. It is the last revision, I promise :)
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 10:31:59.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
***************
*** 2025,2030 ****
--- 2025,2033 ----
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-*)
***************
*** 3432,3437 ****
--- 3435,3449 ----
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,
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