https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66593
--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> --- (In reply to David Malcolm from comment #0) > Currently libgccjit uses -mtune=generic; I'm working on enabling > -mtune=native for libgccjit. > > However, on i386/x86_64 with a non-bootstrap build using gcc < 5, > host_detect_local_cpu does nothing. > > This is due to: > > commit b587c12551143c14f023860a1dbdf7316ae71f27 > Author: uros <uros@138bc75d-0d04-0410-961f-82ee72b054a4> > Date: Fri Oct 17 06:00:58 2014 +0000 > > * config/i386/cpuid.h (__cpuid): Remove definitions that handle %ebx > register in a special way. > (__cpuid_count): Ditto. > * config/i386/driver-i386.h: Protect with > "#if defined(__GNUC__) && (__GNUC__ >= 5 || !defined(__PIC__))". > (host_detect_local_cpu): Mention that GCC with non-fixed %ebx > is required to compile the function. > > Uros said (in https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01516.html): > > The only drawback would be that non-bootstrapped build with gcc < 5.0 > > will ignore -march=native, but I think this should be acceptable." > > Jakub said (in https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01520.html): > > At least on Linux, driver-i386.c should not be built with PIC normally, > > so at least changing > > #if __GNUC__ >= 5 > > to > > #if defined(__GNUC__) && (__GNUC__ >= 5 || !defined(__PIC__)) > > would limit the -march=native change for non-bootstrapped compilers to > > Darwin only (or what other targets use PIC by default?). > > The jit builds with PIC, and -mtune=native would be highly appropriate for > jitted-code; so this is a somewhat bigger deal. > > Currently the instructions for building libgccjit recommend > --disable-bootstrap, so everyone following those on i386/x86_64 with gcc < 5 > as the system compiler is going to get a hobbled -mtune=native. > > That said, the above code runs inside the driver, and libgccjit doesn't yet > run that part of the driver, so some extra work will be needed by me on top > of this before we can get it to do better than -mtune=generic. The core of the problem lies in cpuid.h. The definitions of __cpuid and __cpuid_count now use "b" register constraint which is not usable with GCC < 5 when -fPIC is used (these versions just declare %ebx as fixed, unallocable PIC register). We *really* don't want to litter cpuid.h with a compatibility stuff (there were horrible bugs when 64bit code used %xchgl with 32bit registers), since cpuid.h is intended to be used with the just built compiler. To avoid the troubles, I'd suggest to just document that gcc-5 is needed for x86 -mtune=native jit and cut away the past. Otherwise, we could introduce some kind of local cpuid-compat.h to house all the compatibility stuff and hide the file in some dark corner.