[zeromq-dev] ZMQ3.2: Error in ARM/Thumb2 assembly (atomic_ptr.hpp)

Arthur O'Dwyer arthur at push.am
Thu Aug 9 20:59:21 CEST 2012

In zeromq/3.2/src/atomic_ptr.hpp, we have the following code:

#elif defined ZMQ_ATOMIC_PTR_ARM
            T *old;
            unsigned int flag;
            __asm__ volatile (
                "       dmb     sy\n\t"
                "1:     ldrex   %1, [%3]\n\t"
                "       mov     %0, #0\n\t"
                "       teq     %1, %4\n\t"
+                "       it      eq\n\t"
                "       strexeq %0, %5, [%3]\n\t"
                "       teq     %0, #0\n\t"
                "       bne     1b\n\t"
                "       dmb     sy\n\t"
                : "=&r"(flag), "=&r"(old), "+Qo"(ptr)
                : "r"(&ptr), "r"(cmp_), "r"(val_)
                : "cc");
            return old;

I've added the line starting with "+" above.
When compiled for a Thumb2 target such as an iPhone, the original code
gives the following error:

In file included from .../src/mailbox.cpp:22:
In file included from .../src/mailbox.hpp:32:
In file included from .../src/ypipe.hpp:25:
.../src/atomic_ptr.hpp:143:41: error:
      predicated instructions must be in IT block
                "       teq     %1, %4\n\t"
<inline asm>:5:9: note: instantiated into assembly here
               strexeq r9, r2, [r3]

The reason is that on Thumb2, the conditional instruction "strexeq"
cannot be used without a preceding "it" (if-then) instruction. The
"it" mnemonic doesn't generate any code on non-Thumb targets, so it is
safe to include in both cases. The fix is simply to add the line
starting with "+" above. (Remove the "+" first, of course.)

I would have posted this on a bug tracker, but there doesn't seem to
be any "Issues" link on the Github page and the "official bug tracker"
at zeromq.jira.com is dead, so I figure this mailing list is the best
chance we have of getting the issue fixed in a timely manner.


More information about the zeromq-dev mailing list