Date: Sat, 28 Oct 2017 07:31:33 -0700 From: Mark Millard <markmi@dsl-only.net> To: Dimitry Andric <dim@FreeBSD.org> Cc: =?utf-8?Q?Eddy_Petri=C8=99or?= <eddy.petrisor@gmail.com>, freebsd-arm <freebsd-arm@freebsd.org>, freebsd-toolchain@freebsd.org Subject: Re: lib/clan/llvm.build.mk: Shouldn't BUILD_TRIPLE definition rely host 'cc -dumpmachine'? Message-ID: <7CAFD8CC-BDA1-4E89-BD7E-D0089E27036F@dsl-only.net> In-Reply-To: <CDAA0CB5-F1FC-40FE-AEC5-56FD64654671@FreeBSD.org> References: <CAK0XTWczya8vg_sQZPqz-ZyYZRMq1v6p%2Bjs90S%2BjaDHxo2=1gA@mail.gmail.com> <CDAA0CB5-F1FC-40FE-AEC5-56FD64654671@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2017-Oct-28, at 4:11 AM, Dimitry Andric <dim at FreeBSD.org> wrote: > On 27 Oct 2017, at 08:23, Eddy Petri=C8=99or <eddy.petrisor at = gmail.com> wrote: >>=20 >> I am trying to make the FreeBSD code base build from a Linux host and >> found this bit which defines BUILD_TRIPLE in a way which to my >> untrained eyes look like overengineering. >>=20 >> .if ${TARGET_ARCH:Marmv6*} && (!defined(CPUTYPE) || = ${CPUTYPE:M*soft*} =3D=3D "") >> TARGET_ABI=3D -gnueabihf >> .elif ${TARGET_ARCH:Marm*} >> TARGET_ABI=3D -gnueabi >> .else >> TARGET_ABI=3D >> .endif >> VENDOR=3D unknown >> OS_VERSION=3D freebsd12.0 >>=20 >> TARGET_TRIPLE?=3D >> = ${TARGET_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION}${T= ARGET_ABI} >> BUILD_TRIPLE?=3D >> = ${BUILD_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION} >=20 > I don't see much overengineering here? :) We simply trust BUILD_ARCH, > as it is passed in by the top-level Makefile.inc1. This is how most = of > these down-level Makefiles work. Running all kinds of commands to > figure out architectures and the like should be avoided in such > Makefiles. >=20 >> To support a Linux host I made these changes that is using 'cc >> -dumpmachine' to get the correct BUILD_TRIPLE, >=20 > Unfortunately, this is the wrong option to do so. The gcc manual = says: >=20 > -dumpmachine > Print the compiler=E2=80=99s target machine (for example, = =E2=80=98i686-pc-linux-gnu=E2=80=99) > -and don=E2=80=99t do anything else. Yep --and it is even more complicated: gcc vs. clang are sometimes different for the target listed. . . For example -m32 for amd64 changes the clang result: # clang -dumpmachine x86_64-unknown-freebsd12.0 # clang -dumpmachine -m32 i386-unknown-freebsd12.0 But it does not change the gcc result: (I happen to have only gcc7 around.) # gcc7 -dumpmachine -m32 x86_64-portbld-freebsd12.0 # gcc7 -dumpmachine=20 x86_64-portbld-freebsd12.0 (powerpc64 vs. powerpc is the same for the -m32 handling for -dumpmachine .) > E.g, it prints the *target* tripe, not the build triple. My guess is that Eddy was depending on plain cc being a "self hosting" (target=3Dbuild) type of compiler command in his intended environment(s). Various linux distributions patch uname and its -p code (for example). Even for the same kernel being in use, giving different textual results. -m seemed more stable in my limited testing. Everyplace that uses uname probably needs to be reviewed for a possible re-work. BUILD_ARCH and its use is an example. >> but I am wondering if >> it shouldn't be OK for building on a FreeBSD host >>=20 >> .if ${TARGET_ARCH:Marmv6*} && (!defined(CPUTYPE) || = ${CPUTYPE:M*soft*} =3D=3D "") >> TARGET_ABI=3D -gnueabihf >> .elif ${TARGET_ARCH:Marm*} >> TARGET_ABI=3D -gnueabi >> .else >> TARGET_ABI=3D >> .endif >> VENDOR=3D unknown >> OS_VERSION=3D freebsd12.0 >> +BUILD_OS!=3D uname -s >> + >=20 > Again, this should be set by the top-level Makefiles, not in this one. >=20 >>=20 >> TARGET_TRIPLE?=3D >> = ${TARGET_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION}${T= ARGET_ABI} >> +.if ${BUILD_OS} =3D=3D FreeBSD >> BUILD_TRIPLE?=3D >> = ${BUILD_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION} >> +.else >> +HOST_CC_DUMPMACHINE!=3D cc -dumpmachine >> +BUILD_TRIPLE?=3D ${HOST_CC_DUMPMACHINE} >> +.endif >>=20 >> What do you think, should the code be instead: >>=20 >> .if ${TARGET_ARCH:Marmv6*} && (!defined(CPUTYPE) || = ${CPUTYPE:M*soft*} =3D=3D "") >> TARGET_ABI=3D -gnueabihf >> .elif ${TARGET_ARCH:Marm*} >> TARGET_ABI=3D -gnueabi >> .else >> TARGET_ABI=3D >> .endif >> VENDOR=3D unknown >> OS_VERSION=3D freebsd12.0 >>=20 >> TARGET_TRIPLE?=3D >> = ${TARGET_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION}${T= ARGET_ABI} >> +HOST_CC_DUMPMACHINE!=3D cc -dumpmachine >> +BUILD_TRIPLE?=3D ${HOST_CC_DUMPMACHINE} >=20 > No, this is definitely incorrect, as stated above. It certainly would not be appropriate for general use on FreeBSD: more of a local workaround for an odd context, not a general solution. =3D=3D=3D Mark Millard markmi at dsl-only.net
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7CAFD8CC-BDA1-4E89-BD7E-D0089E27036F>