Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Nov 2011 20:08:24 -0600
From:      "Conrad J. Sabatier" <conrads@cox.net>
To:        Olivier Smedts <olivier@gid0.org>
Cc:        freebsd-ports@freebsd.org
Subject:   Re: Can't compile kde4 and kdelibs4 with an uptodate amd64 Releng machine. (
Message-ID:  <20111122200824.63a8c929@cox.net>
In-Reply-To: <CABzXLYOR_LD4eZXrOye8_OFtMBR=n9htjdDM6iLbBgWgrwg3Vw@mail.gmail.com>
References:  <20111121074243.18902mpt8znqto40@econet.encontacto.net> <20111121100945.2c888eaf@cox.net> <CABzXLYNF6T-GzOVL9OBjPKfOfb9xjkN4_ffa=V=rZma4OdBVHQ@mail.gmail.com> <20111121153828.4e04a92a@cox.net> <CABzXLYOR_LD4eZXrOye8_OFtMBR=n9htjdDM6iLbBgWgrwg3Vw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 21 Nov 2011 23:19:08 +0100
Olivier Smedts <olivier@gid0.org> wrote:

> 2011/11/21 Conrad J. Sabatier <conrads@cox.net>:
> >
> > I've been using the (undocumented, at least in /etc/make.conf)
> > CPUTYPE?=3Dnative with no problems for quite some time now. =A0Let gcc
> > detect the processor type and generate the appropriate code.
> > Eliminates any guesswork in trying to select the correct setting for
> > CPUTYPE.
>=20
> CPUTYPE=3Dnative is not recognized by /usr/share/mk/bsd.cpu.mk (that's
> the real purpose of CPUTYPE, it does not only change the -march
> compiler setting).
> The proper way of doing what you're doing, after numerous tests and
> researchs, seems to be :
>=20
> CPUTYPE?=3Dcore2 (for example, to let /usr/share/mk/bsd.cpu.mk do its
> job) CFLAGS=3D-O2 -pipe -march=3Dnative (because you want the compiler to
> detect the cpu it's running on and optimize the code for it)
> NO_CPU_CFLAGS=3Dyes (because you wanted to force the -march, you don't
> want another one to be added on the command line)
> COPTFLAGS=3D-O2 -pipe -march=3Dnative (same thing for kernel CFLAGS)
> NO_CPU_COPTFLAGS=3Dyes
>=20
> This way, bsd.cpu.mk can set useful MACHINE_CPU for your CPUTYPE, but
> you let the compiler determine which processor to optimize the code
> for with the -march. I add NO_CPU_CFLAGS and NO_CPU_COPTFLAGS to be
> able to specify -march=3Dnative in the CFLAGS, cause it's different from
> CPUTYPE.
>=20
> Now why do I force -march=3Dcore2 and don't use -march=3Dnative ? Because
> our base gcc does not use the correct flags on my Core2 CPU if using
> -march=3Dnative :
> % /usr/bin/gcc -### -march=3Dnative md5.c
> Using built-in specs.
> Target: amd64-undermydesk-freebsd
> Configured with: FreeBSD/amd64 system compiler
> Thread model: posix
> gcc version 4.2.1 20070831 patched [FreeBSD]
>  "/usr/libexec/cc1" "-quiet" "-D_LONGLONG" "md5.c" "-march=3Dcore2"
> "-mtune=3Dgeneric" "-quiet" "-dumpbase" "md5.c" "-auxbase" "md5" "-o"
> "/var/tmp//ccYJKvGN.s"
>  "/usr/bin/as" "-Qy" "-o" "/var/tmp//ccR6Lu5X.o"
> "/var/tmp//ccYJKvGN.s" "/usr/bin/ld" "--eh-frame-hdr"
> "-dynamic-linker" "/libexec/ld-elf.so.1" "/usr/lib/crt1.o"
> "/usr/lib/crti.o" "/usr/lib/crtbegin.o" "-L/usr/lib" "-L/usr/lib"
> "/var/tmp//ccR6Lu5X.o" "-lgcc" "--as-needed" "-lgcc_s"
> "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s"
> "--no-as-needed" "/usr/lib/crtend.o" "/usr/lib/crtn.o"
>=20
> See the "-mtune=3Dgeneric" ? Crap ! You don't want that (manpage :
> Produce code optimized for the most common IA32/AMD64/EM64T
> processors.  If you know the CPU on which your code will run, then you
> should use the corresponding -mtune option instead of -mtune=3Dgeneric.
> But, if you do not know exactly what CPU users of your application
> will have, then you should use this option.)
>=20
> % /usr/bin/gcc -### -march=3Dcore2 md5.c
> Using built-in specs.
> Target: amd64-undermydesk-freebsd
> Configured with: FreeBSD/amd64 system compiler
> Thread model: posix
> gcc version 4.2.1 20070831 patched [FreeBSD]
>  "/usr/libexec/cc1" "-quiet" "-D_LONGLONG" "md5.c" "-quiet"
> "-dumpbase" "md5.c" "-march=3Dcore2" "-auxbase" "md5" "-o"
> "/var/tmp//ccL8Bvk4.s"
>  "/usr/bin/as" "-Qy" "-o" "/var/tmp//ccLrppPo.o"
> "/var/tmp//ccL8Bvk4.s" "/usr/bin/ld" "--eh-frame-hdr"
> "-dynamic-linker" "/libexec/ld-elf.so.1" "/usr/lib/crt1.o"
> "/usr/lib/crti.o" "/usr/lib/crtbegin.o" "-L/usr/lib" "-L/usr/lib"
> "/var/tmp//ccLrppPo.o" "-lgcc" "--as-needed" "-lgcc_s"
> "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s"
> "--no-as-needed" "/usr/lib/crtend.o" "/usr/lib/crtn.o"
>=20
> No -mtune=3Dgeneric. According to the gcc manpage for the x86 arch,
> -march=3Dcore2 is sufficient to have proper values for -mtune, -mcpu...
> (Generate instructions for the machine type cpu-type.  The choices for
> cpu-type are the same as for -mtune.  Moreover, specifying
> -march=3Dcpu-type implies -mtune=3Dcpu-type.)

Strange, it seems to "just work" on my machine (note the -march and
-mtune settings):

$ /usr/bin/gcc -### -march=3Dnative hello.c
Using built-in specs.
Target: amd64-undermydesk-freebsd
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.1 20070831 patched [FreeBSD]
 "/usr/libexec/cc1" "-quiet" "-D_LONGLONG" "hello.c" "-march=3Dk8"
"-mtune=3Dk8" "-quiet" "-dumpbase" "hello.c" "-auxbase" "hello" "-o"
"/tmp/ccAXYamu.s" "/usr/bin/as" "-Qy" "-o" "/tmp/ccIpMJgw.o"
"/tmp/ccAXYamu.s" "/usr/bin/ld" "--eh-frame-hdr" "-dynamic-linker"
"/libexec/ld-elf.so.1" "/usr/lib/crt1.o" "/usr/lib/crti.o"
"/usr/lib/crtbegin.o" "-L/usr/lib" "-L/usr/lib" "/tmp/ccIpMJgw.o"
"-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc"
"--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/crtend.o"
"/usr/lib/crtn.o"

I've never seen any problems with this in src or ports makes, either.
I do seem to recall having a look at bsd.cpu.mk a long, long time ago,
and it appeared to me that it simply passed any unrecognized CPUTYPE
through unchanged, which my experience does seem to bear out.

--=20
Conrad J. Sabatier
conrads@cox.net



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111122200824.63a8c929>