[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#1017537: armel buildd misconfiguration



On Wed, Aug 24, 2022 at 8:03 PM Thorsten Glaser <tg@mirbsd.de> wrote:
> Do you think it would be worth compiling a VERY tiny program from
> execute_before_dh-auto-build that just runs an swp instruction, and
> if that fails, issue a message pointing to your message? I’m doing
> something similar for mksh wrt. the existence of /dev/{tty,pts,ptmx}
> but here it can obviously only be done if not cross-compiling (but
> that’s not a problem because the tests can only run then either).

Yes, that sounds reasonable in principle. I've tried to come up with a
minimal test case like

echo 'int main(void) { static int a, b, c; return
__atomic_exchange_n(&a, b, 0); }' | \
  gcc -S -xc - -O2 -o testswp

However, this does not actually use the swp instruction but calls
the correct libgcc function __sync_val_compare_and_swap_4(),
which in turn uses a VDSO helper provided by the kernel to
do this in a portable way using either swp or ldrex/strex depending
on the running CPU.

So an even better way to handle this would be to use the gcc
builtins in place of the assembler implementation, or copy
the portable code from musl, which uses the VSDO version
explicitly:

#define a_cas a_cas
static inline int a_cas(volatile int *p, int t, int s)
{
        for (;;) {
                register int r0 __asm__("r0") = t;
                register int r1 __asm__("r1") = s;
                register volatile int *r2 __asm__("r2") = p;
                register uintptr_t r3 __asm__("r3") = __a_cas_ptr;
                int old;
                __asm__ __volatile__ (
                        BLX " r3"
                        : "+r"(r0), "+r"(r3) : "r"(r1), "r"(r2)
                        : "memory", "lr", "ip", "cc" );
                if (!r0) return t;
                if ((old=*p)!=t) return old;
        }
}


Reply to: