From owner-freebsd-arch@FreeBSD.ORG Thu Oct 4 20:02:26 2012 Return-Path: Delivered-To: freebsd-arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5A416106566C; Thu, 4 Oct 2012 20:02:26 +0000 (UTC) (envelope-from dimitry@andric.com) Received: from tensor.andric.com (tensor.andric.com [87.251.56.140]) by mx1.freebsd.org (Postfix) with ESMTP id 13B218FC16; Thu, 4 Oct 2012 20:02:25 +0000 (UTC) Received: from [192.168.0.6] (spaceball.home.andric.com [192.168.0.6]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 898695C59; Thu, 4 Oct 2012 22:02:19 +0200 (CEST) Message-ID: <506DEB4C.5020508@andric.com> Date: Thu, 04 Oct 2012 22:02:20 +0200 From: Dimitry Andric User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121002 Thunderbird/16.0 MIME-Version: 1.0 To: Andriy Gapon References: <506C385C.3020400@FreeBSD.org> In-Reply-To: <506C385C.3020400@FreeBSD.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-arch@FreeBSD.org Subject: Re: x86 boot code build X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Oct 2012 20:02:26 -0000 On 2012-10-03 15:06, Andriy Gapon wrote: > Currently we produce "slightly" different binaries for x86 boot code depending > whether MACHINE_CPUARCH is i386 or amd64. I think that there is no good reason > for this, since in both cases we use exactly the same code and target the same > classes of machines. In other words, the binaries should be interchangeable[*]. > > The difference boils down to using -march=i386 on amd64 while i386 uses default > compiler flags, which are equivalent to -march=i486 -mtune=generic. Yes, I also noticed this inconsistency during some other work in sys/boot, and I ended up with this diff in my backlog: Index: sys/boot/i386/Makefile.inc =================================================================== --- sys/boot/i386/Makefile.inc (revision 241194) +++ sys/boot/i386/Makefile.inc (working copy) @@ -5,12 +5,13 @@ BINDIR?= /boot LOADER_ADDRESS?=0x200000 -CFLAGS+= -ffreestanding -mpreferred-stack-boundary=2 \ +CFLAGS+= -march=i386 -ffreestanding -mpreferred-stack-boundary=2 \ -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float +NO_CPU_CFLAGS= LDFLAGS+= -nostdlib .if ${MACHINE_CPUARCH} == "amd64" -CFLAGS+= -m32 -march=i386 +CFLAGS+= -m32 ACFLAGS+= -m32 LDFLAGS+= -m elf_i386_fbsd AFLAGS+= --32 > If my analysis is correct, the only thing affected by the flags in the boot code > is use of leave instruction when -Os is _not_ specified. > For -march=i386 our gcc prefers using leave. For -march=i486 it thinks that > movs+pops are faster than leave and so prefers to not use it. If -Os is > specified, then leave is always used because it results in smaller machine code. > > So, as it is now, on amd64 we produce slightly smaller boot binaries where size > doesn't matter. Where size really matters (-Os) we produce identical binaries. > > If we decide that it makes sense to converge i386 and amd64 boot build options, > which should we pick? Well, do we still officially support any real i386 machines? If so, we should still use -march=i386 for the boot code. Otherwise, let's start using -march=i486 explicitly. So like: Index: sys/boot/i386/Makefile.inc =================================================================== --- sys/boot/i386/Makefile.inc (revision 241194) +++ sys/boot/i386/Makefile.inc (working copy) @@ -5,12 +5,13 @@ BINDIR?= /boot LOADER_ADDRESS?=0x200000 -CFLAGS+= -ffreestanding -mpreferred-stack-boundary=2 \ +CFLAGS+= -march=i486 -ffreestanding -mpreferred-stack-boundary=2 \ -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float +NO_CPU_CFLAGS= LDFLAGS+= -nostdlib .if ${MACHINE_CPUARCH} == "amd64" -CFLAGS+= -m32 -march=i386 +CFLAGS+= -m32 ACFLAGS+= -m32 LDFLAGS+= -m elf_i386_fbsd AFLAGS+= --32