On 09/21/2017 19:00, [email protected] wrote:
> 
>>> [...]
>>> kBuild: Compiling VBoxRemPrimary
>>> - 
>>> /usr/ports/emulators/virtualbox-ose/work/VirtualBox-5.1.28/src/recompiler/target-i386/op_helper.c
>>> In file included
>>> from 
>>> /usr/ports/emulators/virtualbox-ose/work/VirtualBox-5.1.28/src/recompiler/target-i386/op_helper.c:29:
>>>     
>>> /usr/ports/emulators/virtualbox-ose/work/VirtualBox-5.1.28/src/recompiler/target-i386/exec.h:41:38:
>>> error: register 'r14' unsuitable for global register variables on this
>>> target register struct CPUX86State *env asm(AREG0); ^
>>> /usr/ports/emulators/virtualbox-ose/work/VirtualBox-5.1.28/src/recompiler/dyngen-exec.h:81:15:
>>> note: expanded from macro 'AREG0'
>>> #define AREG0 "r14"  
>>
>> Turns out that the fix for this is to make sure that devel/kBuild
>> is compiled with GCC, not clang; thus, that module of VBox that
>> has global register variable (and fails to build with clang) is
>> automagically built with gcc. So some parts of VBox are built
>> with base clang, some with gcc from ports; it is awkward, but
>> it all works somehow.
> 
> Alternatively, one can try changing 'r14' to 'rbp' in definition
> of "AREG0" for amd64 at src/recompiler/dyngen-exec.h:81. This is
> the only place where gcc is needed, as clang cannot handle r14
> for now [0].
> 
> I recompiled kBuild with clang, and succeeded compiling virtualbox-ose
> with 'r14' to 'rbp' change. It seems to work normally, but I don't know
> what are the performance implications of using up rbp.
> 
> [0] clang/lib/Basic/Targets/X86.h:
>   860   bool validateGlobalRegisterVariable(StringRef RegName, unsigned 
> RegSize,
>   861                                       bool &HasSizeMismatch) const 
> override {
>   862     // rsp and rbp are the only 64-bit registers the x86 backend can 
> currently
>   863     // handle.
>   864     if (RegName.equals("rsp") || RegName.equals("rbp")) {
>   865       // Check that the register size is 64-bit.
>   866       HasSizeMismatch = RegSize != 64;
>   867       return true;
>   868     }

Please try the attached patch.

Jung-uk Kim
Index: emulators/virtualbox-ose/Makefile
===================================================================
--- emulators/virtualbox-ose/Makefile	(revision 450418)
+++ emulators/virtualbox-ose/Makefile	(working copy)
@@ -227,8 +227,12 @@ KMK_FLAGS+=	-j${MAKE_JOBS_NUMBER}
 PATCH_DEPENDS+=	${LOCALBASE}/share/kBuild/tools/GXX3.kmk:devel/kBuild
 EXTRA_PATCHES+=	${PATCHDIR}/extrapatch-Config.kmk \
 		${PATCHDIR}/extrapatch-src-VBox-Devices-PC-ipxe-Makefile.kmk \
-		${PATCHDIR}/extrapatch-src-recompiler-Makefile.kmk
+		${PATCHDIR}/extrapatch-src_recompiler_dyngen-exec.h \
+		${PATCHDIR}/extrapatch-src_recompiler_tcg_i386_tcg-target.h
+.if ${COMPILER_VERSION} < 35
+EXTRA_PATCHES+=	${PATCHDIR}/extrapatch-src-recompiler-Makefile.kmk
 .endif
+.endif
 
 .if ${PYTHON_MAJOR_VER} >= 3
 PLIST_SUB+=	PYTHON_PYCDIR=/__pycache__/ \
Index: emulators/virtualbox-ose/files/extrapatch-src_recompiler_dyngen-exec.h
===================================================================
--- emulators/virtualbox-ose/files/extrapatch-src_recompiler_dyngen-exec.h	(nonexistent)
+++ emulators/virtualbox-ose/files/extrapatch-src_recompiler_dyngen-exec.h	(working copy)
@@ -0,0 +1,21 @@
+--- src/recompiler/dyngen-exec.h.orig	2017-09-13 09:34:47 UTC
++++ src/recompiler/dyngen-exec.h
+@@ -75,10 +75,18 @@ typedef void * host_reg_t;
+ # ifndef VBOX
+ #define AREG0 "ebp"
+ # else  /* VBOX - why are we different? frame-pointer optimizations on mac? */
++#  ifndef __clang__
+ #  define AREG0 "esi"
++#  else  /* __clang __ */
++#   define AREG0 "ebp"
++#  endif /* __clang __ */
+ # endif /* VBOX */
+ #elif defined(__x86_64__)
++# ifndef __clang__
+ #define AREG0 "r14"
++# else  /* __clang__ */
++#  define AREG0 "rbp"
++# endif /* __clang__ */
+ #elif defined(_ARCH_PPC)
+ #define AREG0 "r27"
+ #elif defined(__arm__)

Property changes on: emulators/virtualbox-ose/files/extrapatch-src_recompiler_dyngen-exec.h
___________________________________________________________________
Added: fbsd:nokeywords
## -0,0 +1 ##
+yes
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: emulators/virtualbox-ose/files/extrapatch-src_recompiler_tcg_i386_tcg-target.h
===================================================================
--- emulators/virtualbox-ose/files/extrapatch-src_recompiler_tcg_i386_tcg-target.h	(nonexistent)
+++ emulators/virtualbox-ose/files/extrapatch-src_recompiler_tcg_i386_tcg-target.h	(working copy)
@@ -0,0 +1,23 @@
+--- src/recompiler/tcg/i386/tcg-target.h.orig	2017-09-13 09:34:48 UTC
++++ src/recompiler/tcg/i386/tcg-target.h
+@@ -120,12 +120,20 @@ enum {
+ 
+ /* Note: must be synced with dyngen-exec.h */
+ #if TCG_TARGET_REG_BITS == 64
++# ifndef __clang__
+ # define TCG_AREG0 TCG_REG_R14
++# else  /* __clang__ */
++#  define TCG_AREG0 TCG_REG_RBP
++# endif /* __clang__ */
+ #else
+ # ifndef VBOX /* we're using ESI instead of EBP, probably due to frame pointer opt issues */
+ # define TCG_AREG0 TCG_REG_EBP
+ # else  /* VBOX */
++#  ifndef __clang__
+ #  define TCG_AREG0 TCG_REG_ESI
++#  else  /* __clang__ */
++#   define TCG_AREG0 TCG_REG_EBP
++#  endif /* __clang__ */
+ # endif /* VBOX */
+ #endif
+ 

Property changes on: emulators/virtualbox-ose/files/extrapatch-src_recompiler_tcg_i386_tcg-target.h
___________________________________________________________________
Added: fbsd:nokeywords
## -0,0 +1 ##
+yes
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to