I have recently tried to upgrade x86info from 1.21 to 1.24-r1 and I get this error: i686-pc-linux-gnu-gcc -O2 -march=i686 -pipe -MMD -o havecpuid.o -c havecpuid.c i686-pc-linux-gnu-gcc -O2 -march=i686 -pipe -MMD -o cpuid.o -c cpuid.c i686-pc-linux-gnu-gcc -O2 -march=i686 -pipe -MMD -o dumpregs.o -c dumpregs.c cpuid.c: In function `native_cpuid': cpuid.c:65: error: can't find a register in class `BREG' while reloading `asm' make: *** [cpuid.o] Error 1 make: *** Waiting for unfinished jobs.... * * ERROR: sys-apps/x86info-1.24-r1 failed. * Call stack: * ebuild.sh, line 48: Called src_compile * environment, line 2128: Called die * The specific snippet of code: * emake x86info CC="$(tc-getCC)" CFLAGS="${CFLAGS}" || die "emake failed" * The die message: * emake failed I am building in a chrooted environment on a new system that used one of the autobuild tarballs to install from. I will attach my emerge info too. For reference, 1.21 compiles perfectly. Reproducible: Always Steps to Reproduce: 1. build a new system 2. during the chroot work, try and emerge x86info 3. sit back and wait for it to error
Created attachment 191749 [details] emerge --info
This looks like a standard hardened/pic issue to me, so I've CCed the hardened team...
Version 1.21 builds correctly because it does not contain the troublesome asm statement. The offending function sets CPU affinity to ensure it runs on the correct CPU, then uses an asm statement to run the cpuid instruction and relies on gcc for load/store around the asm statement. Since the asm statement explicitly requests register b for one of the outputs, gcc fails. There are several paths forward: (1) Disable PIC for the package. This is overkill, in my opinion. (2) Split the offending function into one that sets up CPU affinity, and a separate one that performs the cpuid instruction. The latter can be done without absolute memory references, so it will not generate text relocations when it is moved into a file built without PIC. (3) Move the cpuid instruction into a function generated entirely in an asm block, by manually emitting a function label and using an extern declaration in the C code to call the label. (4) Take a hint from the existing PIC patch to rework the asm statement so that it does not need to clobber ebx. I will prepare a patch to do this, as it seems least invasive.
Created attachment 191813 [details, diff] Patch to fix cpuid invocation in cpuid.c not to clobber PIC register This patch is needed in addition to 1.21-pic.patch, which the ebuild already applies. I have not yet reported this upstream, but can do so later this week if no one else on this bug does so. As noted in the patch header, this is a targeted fix: only x86_32 builds with __PIC__ defined will see any change in the generated code.
look at the util-linux-2.15-cpuid-pic.patch change ... simpler to redirect the register directly rather than clobbering it indirectly
It looks about equivalent to me. Either way, ebx is spilled and we declare some register as unavailable, whether due to the clobber of edi or the output to esi. Mine uses memory for the output, whereas yours hits memory for the spill. Feel free to modify my patch if you prefer the style in your patch to util-linux. It was only intended as a convenience if someone wanted to fix this without drafting a code patch of their own.
Created attachment 199477 [details, diff] proposed patch updated I had to slightly update the proposed patch as it did not apply cleanly on my system for some reason. Tested with sys-apps/x86info-1.24-r2, works fine. See attachment, cheers.
Hope it'll be included.
added to cvs, thanks http://sources.gentoo.org/sys-apps/x86info/x86info-1.24-r2.ebuild?r1=1.2&r2=1.3 http://sources.gentoo.org/sys-apps/x86info/files/x86info-1.24-pic.patch?rev=1.1