[m-dev.] gcc abort on runtime/mercury_atomic_ops.c

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Oct 24 14:14:51 AEST 2007


On Mon, 22 Oct 2007, Zoltan Somogyi wrote:

> On my laptop (alys, a Dell Inspiron 9400 with an Intel T2500 CPU), I get
> the following error from gcc:
>
> ../scripts/mgnuc --grade asm_fast.gc      --c-debug --no-ansi   --   -O0 -g    -c mercury_atomic_ops.c -o mercury_atomic_ops.o
> mercury_atomic_ops.c: In function `MR_compare_and_swap_word':
> mercury_atomic_ops.c:22: error: can't find a register in class `GENERAL_REGS' while reloading `asm'
>
> The output of gcc -v is:
>
> Reading specs from /usr/lib/gcc/i486-linux-gnu/3.4.6/specs
> Configured with: ../src/configure -v --enable-languages=c,c++,f77,pascal --prefix=/usr --libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --program-suffix=-3.4 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --with-tune=pentium4 i486-linux-gnu
> Thread model: posix
> gcc version 3.4.6 (Ubuntu 3.4.6-1ubuntu2)
>
> The error goes away if I delete the -O0 from the list of command line
> arguments. (I originally added it via Mmake.runtime.params, since I was
> trying to debug something in the runtime.)
>
> Does anyone know what specifically causes the incompatibility of -O0
> with this inline asm code? (I mean beside the x86's lack of registers,
> especially after we reserve some.)

No, although if you manually specify all the optimisation flags that
are documented as being enabled at O1 the problem still occurs.
If you specify -O1 the problem goes away you no longer get the error.
The error also goes away if you comment out one of the global register
declarations.

I've tried this with a few different (x86) machines / gcc versions and the
same thing happens on all of them.

I'll do the following:

(1) use the gcc 4.1 (and greater) builtin compare and swap by default
     when it is available.

(2) protecting the code in mercury_atomic_ops.[ch] with
     MR_LL_PARALLEL_CONJ so that other grades don't get broken when
     compiling at -O0.

(3) add a test to configure that checks that in the absence of
     gcc 4.1 we can compile mercury_atomic_ops on x86 machines
     and disables those grades that depend on it otherwise.

I'll also report this one as a bug in gcc as well.

On another matter related to the atomic ops module (this is for PeterW),
why is the signature of MR_compare_and_swap_word

MR_bool
MR_compare_and_swap_word(volatile MR_Integer *, MR_Integer, MR_Integer)

rather than:

MR_bool
MR_compare_and_swap_word(volatile MR_Word *, MR_Word, MR_Word)

?

Cheers,
Julien.


--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list