Bug 223971

Summary: devel/kBuild 0.1.9998_10 and lang/gcc6 6.4.0_3 fails to build on VirtualBox guests with CPU Core 2
Product: Ports & Packages Reporter: Vladimir Druzenko <vvd>
Component: Individual Port(s)Assignee: Virtualbox Team (Nobody) <vbox>
Status: Closed Overcome By Events    
Severity: Affects Only Me CC: jkim, vvd
Priority: --- Flags: bugzilla: maintainer-feedback? (vbox)
Version: Latest   
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
devel/kBuild 0.1.9998_10 build log with error
none
diff of cpuid-etallen output host and guest
none
diff of cpuid output host and guest none

Description Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-29 15:57:58 UTC
Created attachment 188402 [details]
devel/kBuild 0.1.9998_10 build log with error

devel/kBuild 0.1.9998_10

[1]
* FreeBSD 11.1 amd64 as host
* VirtualBox 5.1.28
* host CPU Core i7 920
* FreeBSD 11.1 amd64 as guest
* CPUTYPE?=core2 in /etc/make.conf
= build fine =

[2]
* FreeBSD 11.1 amd64 as host
* VirtualBox 5.1.30
* host CPU Core 2 Quad Q6600
* FreeBSD 11.1 amd64 as guest
* CPUTYPE?=core2 (and without too) in /etc/make.conf
= build with error =

[3]
* FreeBSD 11.1 amd64 on bare metal
* CPU Core 2 Quad Q6600 or Core 2 Duo E7200
* CPUTYPE?=core2 in /etc/make.conf
= build fine =
Comment 1 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-29 16:12:18 UTC
Just tested: same situation with kBuild-0.1.9998_9 too.
Comment 2 Jung-uk Kim freebsd_committer freebsd_triage 2017-11-29 18:00:55 UTC
Sorry but guest does not support same instructions as the host.  For example, FreeBSD guest does not support AVX instructions ATM.
Comment 3 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-29 18:25:08 UTC
Created attachment 188407 [details]
diff of cpuid-etallen output host and guest
Comment 4 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-29 18:25:55 UTC
Created attachment 188408 [details]
diff of cpuid output host and guest
Comment 5 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-29 18:27:53 UTC
Core2 don't support AVX and SSE4.
Comment 6 Jung-uk Kim freebsd_committer freebsd_triage 2017-11-29 18:37:59 UTC
(In reply to vvd from comment #5)
> Core2 don't support AVX and SSE4.

My point was we cannot use the same CPUTYPE for both host/guest in general.
Comment 7 Jung-uk Kim freebsd_committer freebsd_triage 2017-11-29 18:42:19 UTC
BTW, if you look closely, you will see gcc is crashing.

/usr/obj/usr/ports/devel/kBuild/work/kBuild-0.1.9998/src/kmk/job.c: In function 'load_too_high':
/usr/obj/usr/ports/devel/kBuild/work/kBuild-0.1.9998/src/kmk/job.c:2195:9: internal compiler error: Illegal instruction
         last_sec = LOAD_WEIGHT_B * job_counter;
         ^~~~~~~~

I believe you have to recompile gcc without CPUTYPE.
Comment 8 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-29 18:50:05 UTC
(In reply to Jung-uk Kim from comment #7)
> BTW, if you look closely, you will see gcc is crashing.
Yes, I saw.

> I believe you have to recompile gcc without CPUTYPE.
Why it work fine on CPU Core i7 920 with same CPUTYPE in guest system?
Comment 9 Jung-uk Kim freebsd_committer freebsd_triage 2017-11-29 19:02:45 UTC
(In reply to vvd from comment #8)
> Why it work fine on CPU Core i7 920 with same CPUTYPE in guest system?

Honestly, I do not know until I see the dumped gcc.core.  Basically, VirtualBox masks off some features from host CPUID as you can see from VBox.log.  Therefore, it still depends on host CPUID.
Comment 10 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-29 19:12:23 UTC
(In reply to Jung-uk Kim from comment #9)
Can't find gcc.core and no information about cores in /var/log/messages too.
Comment 11 Jung-uk Kim freebsd_committer freebsd_triage 2017-11-29 19:28:44 UTC
(In reply to vvd from comment #10)
Try

find /usr/obj/usr/ports/devel/kBuild/work/kBuild-0.1.9998 -name "*.core"

BTW, I looked around a bit.  Intel Westmere and later CPUs have VT-x "unrestricted guest" feature.  When VirtualBox finds the feature from host CPU, it lets guests use certain instructions.  I believe that is why your Core i7 is okay.  FYI, AMD-V does not have this "restriction".
Comment 12 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-29 21:52:49 UTC
> find /usr/obj/usr/ports/devel/kBuild/work/kBuild-0.1.9998 -name "*.core"
I know and did it, but no *.core files.

> Intel Westmere and later CPUs have VT-x "unrestricted guest" feature.  When VirtualBox finds the feature from host CPU, it lets guests use certain instructions.  I believe that is why your Core i7 is okay.
Core i7 920 is Bloomfield, not Westmere. And, afaik, it don't have "unrestricted guest".
Comment 13 Jung-uk Kim freebsd_committer freebsd_triage 2017-11-29 22:30:52 UTC
(In reply to vvd from comment #12)
> I know and did it, but no *.core files.

Now I see that it's an internal error message from gcc itself.  Just rebuild gcc and try again.

> Core i7 920 is Bloomfield, not Westmere. And, afaik, it don't have "unrestricted 
> guest".

Then, I am out of wild guesses.
Comment 14 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-29 23:01:52 UTC
Error during build GCC (with CPUTYPE?=core2):

/opt/obj/usr/ports/lang/gcc6/work/.build/./gcc/xgcc -B/opt/obj/usr/ports/lang/gcc6/work/.build/./gcc/ -B/usr/local/x86_64-portbld-freebsd11.1/bin/ -B/usr/local/x86_64-portbld-freebsd11.1/lib/ -isystem /usr/local/x86_64-portbld-freebsd11.1/include -isystem /usr/local/x86_64-portbld-freebsd11.1/sys-include    -g -O2 -pipe -march=core2 -DLIBICONV_PLUG -fno-strict-aliasing -O2  -g -O2 -pipe -march=core2  -DLIBICONV_PLUG -fno-strict-aliasing -DIN_GCC    -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include   -fpic -pthread -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector   -fpic -pthread -I. -I. -I../.././gcc -I/opt/obj/usr/ports/lang/gcc6/work/gcc-6.4.0/libgcc -I/opt/obj/usr/ports/lang/gcc6/work/gcc-6.4.0/libgcc/. -I/opt/obj/usr/ports/lang/gcc6/work/gcc-6.4.0/libgcc/../gcc -I/opt/obj/usr/ports/lang/gcc6/work/gcc-6.4.0/libgcc/../include  -DHAVE_CC_TLS  -o _mulxc3.o -MT _mulxc3.o -MD -MP -MF _mulxc3.dep -DL_mulxc3 -c /opt/obj/usr/ports/lang/gcc6/work/gcc-6.4.0/libgcc/libgcc2.c -fvisibility=hidden -DHIDE_EXPORTS
/opt/obj/usr/ports/lang/gcc6/work/gcc-6.4.0/libgcc/libgcc2.c: In function '__mulxc3':
/opt/obj/usr/ports/lang/gcc6/work/gcc-6.4.0/libgcc/libgcc2.c:1955:6: internal compiler error: Illegal instruction
    a = COPYSIGN (isinf (a) ? 1 : 0, a);
    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
no stack trace because unwind library not available
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
gmake[4]: *** [Makefile:467: _mulxc3.o] Error 1
gmake[4]: Leaving directory '/opt/obj/usr/ports/lang/gcc6/work/.build/x86_64-portbld-freebsd11.1/libgcc'
gmake[3]: *** [Makefile:11798: all-target-libgcc] Error 2
gmake[3]: Leaving directory '/opt/obj/usr/ports/lang/gcc6/work/.build'
gmake[2]: *** [Makefile:878: all] Error 2
gmake[2]: Leaving directory '/opt/obj/usr/ports/lang/gcc6/work/.build'
===> Compilation failed unexpectedly.

Testing build gcc without any CPUTYPE.
Comment 15 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-30 11:41:08 UTC
(In reply to vvd from comment #14)
> Testing build gcc without any CPUTYPE.
I got the same error without CPUTYPE!
Comment 16 Vladimir Druzenko freebsd_committer freebsd_triage 2017-11-30 15:15:04 UTC
(In reply to vvd from comment #15)
Tested all build options of lang/gcc6 - same error.
One more time about environment:
* FreeBSD 11.1 amd64 as host
* VirtualBox 5.1.30
* host CPU Core 2 Quad Q6600
* FreeBSD 11.1 amd64 as guest
Comment 17 Vladimir Druzenko freebsd_committer freebsd_triage 2019-09-06 23:45:39 UTC
GCC 9.2.0, FreeBSD 12.0 - build fine now.