[Mono-dev] gc_test_and_set + arm architectures

Brian Luczkiewicz brian at sooloos.com
Wed Jul 27 09:59:59 EDT 2011

This code (duplicated below, from gc_locks.h) is a little bit troublesome.
I'm not sure what the best way to resolve is, but I figured I'd raise the
issue anyways.

On most architectures, building for an old CPU then running on a newer one
is safe. For example, running code compiled for i386 on a modern intel cpu
generally turns out ok.

With mono+arm this is not the case. If I use gcc to build for arm with no
-march/etc flags, gcc builds for armv5. If I run this mono on an SMP armv7a
machine, I get deadlocks and terribleness, because test+set is broken. The
comments seems to suggest that someone anticipated this issue, but never
followed up.

Any ideas how we can make this experience better? If it's truly not possible
to write a single code path that is suitable for both CPUs when building for
armv5, maybe code built for armv5 should force mono into a single cpu or
assert at boot if run on an SMP arm machine.


        inline static int GC_test_and_set(volatile unsigned int *addr) {#if
defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_7A__) ||
          int ret, tmp;
          __asm__ __volatile__ (
"ldrex %0, [%3]\n"
                                 "strex %1, %2, [%3]\n"
                                 "teq %1, #0\n"
                                 "bne 1b\n"
                                 : "=&r" (ret), "=&r" (tmp)
                                 : "r" (1), "r" (addr)
                                 : "memory", "cc");
          return ret;
          int oldval;
          /* SWP on ARM is very similar to XCHG on x86.  Doesn't lock the
           * bus because there are no SMP ARM machines.  If/when there are,
           * this code will likely need to be updated. */
          /* See linuxthreads/sysdeps/arm/pt-machine.h in glibc-2.1 */
          __asm__ __volatile__("swp %0, %1, [%2]"
                             : "=&r"(oldval)
                             : "r"(1), "r"(addr)
                             : "memory");
          return oldval;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110727/3511c04c/attachment.html 

More information about the Mono-devel-list mailing list