[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: toolchain/45673: gcc on i386 current generates bad code for assembler code in lock.h
The following reply was made to PR toolchain/45673; it has been noted by GNATS.
From: Alan Barrett <apb%cequrux.com@localhost>
Subject: Re: toolchain/45673: gcc on i386 current generates bad code for
assembler code in lock.h
Date: Thu, 11 Oct 2012 11:04:41 +0200
Building lang/gcc47 from pkgsrc, on a NetBSD/i386 -current host, fails
as described in this PR, with:
/usr/include/x86/lock.h:108: Error: bad register name `%sil'
The problematic source file is gcc-4.7.0/libiberty/physmem.c,
which includes <sys/sysctl.h> which (through several levels of
includes) eventually includes <x86/lock.h>. x86/lock.h contains
static __inline int
val = __SIMPLELOCK_LOCKED;
__asm volatile ("xchgb %0,(%2)" :
:"0" (val), "r" (lockp));
return val == __SIMPLELOCK_UNLOCKED;
The physmem.s file that I get from invoking the compiler with the
"-save-temps" flag, and without any "-O" flags, includes this code:
# 108 "/usr/include/x86/lock.h" 1
# 0 "" 2
The assembler is correctly complaining that %sil is not a valid
If I change <x86/lock.h> to have "=qQ" or "=q" instead of "=r" in
the register constraint for the (val) output, then gcc chooses to
use the %dl register, not %sil, and compilation is successful.
With "-O", the entire function is optimised away (because it's not
There may be a gcc bug, as earlier commenters on thei PAR said,
because %sil is not a valid register for i386. However, changing
the register constraint in <x86/lock.h> from "=r" to "=q" or "=qQ"
seems to me to be a simple, safe, and reasonable solution to the
problem without needing to modify gcc.
I have performed a complete build of NetBSD-current/i386 with
"=qQ" in the relevant place in src/sys/arch/x86/include/lock.h,
and it passes all tests. Also, the output from "objdump -d" is
identical before and after this change, for both the i386 GENERIC
and MONOLITHIC kernels.
--apb (Alan Barrett)
Main Index |
Thread Index |