From owner-freebsd-current@FreeBSD.ORG Fri Mar 9 00:16:53 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id D3482106566B; Fri, 9 Mar 2012 00:16:53 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (cl-327.ede-01.nl.sixxs.net [IPv6:2001:7b8:2ff:146::2]) by mx1.freebsd.org (Postfix) with ESMTP id 7FA4D8FC19; Fri, 9 Mar 2012 00:16:53 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7:0:9d09:6a8a:331f:682d] (unknown [IPv6:2001:7b8:3a7:0:9d09:6a8a:331f:682d]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id ED8B15C37; Fri, 9 Mar 2012 01:16:51 +0100 (CET) Message-ID: <4F594BF4.9060802@FreeBSD.org> Date: Fri, 09 Mar 2012 01:16:52 +0100 From: Dimitry Andric Organization: The FreeBSD Project User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120229 Thunderbird/11.0 MIME-Version: 1.0 To: Jia-Shiun Li References: In-Reply-To: X-Enigmail-Version: 1.4a1pre Content-Type: multipart/mixed; boundary="------------060704000108040704050100" Cc: freebsd-current@freebsd.org, Jung-uk Kim , John Baldwin Subject: Re: boot2 overflow when building with clang X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Mar 2012 00:16:53 -0000 This is a multi-part message in MIME format. --------------060704000108040704050100 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2012-03-07 05:51, Jia-Shiun Li wrote: > I am not familiar with boot2, but it looks like allocated size for > boot2 is not enough to hold code generated by clang. Reverting r232570 > fixes it. Please test the attached diff. Since it modifies bsd.sys.mk, either run "make install" in share/mk, or use "make buildenv" before rebuilding sys/boot/i386/boot2. It would also be nice if you could test the actual installation of the bootstrap, and its proper operation. However, be sure to have some way of recovering the first 16 sectors of your disk before you do so. :) --------------060704000108040704050100 Content-Type: text/x-diff; name="boot2-shrink-1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="boot2-shrink-1.diff" diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk index 401e671..a8770cc 100644 --- a/share/mk/bsd.sys.mk +++ b/share/mk/bsd.sys.mk @@ -100,8 +100,10 @@ CWARNFLAGS += -Wno-unknown-pragmas .if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang" CLANG_NO_IAS = -no-integrated-as -CLANG_OPT_SMALL = -mllvm -stack-alignment=8 -mllvm -inline-threshold=3 \ - -mllvm -enable-load-pre=false +CLANG_OPT_SMALL = -mllvm -stack-alignment=8 \ + -mllvm -inline-threshold=3 \ + -mllvm -enable-load-pre=false \ + -mllvm -simplifycfg-dup-ret .endif .if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ diff --git a/sys/boot/i386/boot2/Makefile b/sys/boot/i386/boot2/Makefile index 68e49ed..5cec4b5 100644 --- a/sys/boot/i386/boot2/Makefile +++ b/sys/boot/i386/boot2/Makefile @@ -26,6 +26,8 @@ CFLAGS= -Os \ -fno-guess-branch-probability \ -fomit-frame-pointer \ -fno-unit-at-a-time \ + -ffunction-sections \ + -fdata-sections \ -mno-align-long-strings \ -mrtd \ -mregparm=3 \ diff --git a/sys/boot/i386/boot2/boot2.c b/sys/boot/i386/boot2/boot2.c index 8291249..37314f1 100644 --- a/sys/boot/i386/boot2/boot2.c +++ b/sys/boot/i386/boot2/boot2.c @@ -148,8 +148,8 @@ static int xputc(int); static int xgetc(int); static inline int getc(int); -static void memcpy(void *, const void *, int); -static void +static __noinline void memcpy(void *, const void *, int); +static __noinline void memcpy(void *dst, const void *src, int len) { const char *s = src; @@ -223,10 +223,7 @@ main(void) { uint8_t autoboot; ino_t ino; - size_t nbyte; - opts = 0; - kname = NULL; dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base); v86.ctl = V86_FLAGS; v86.efl = PSL_RESERVED_DEFAULT | PSL_I; @@ -242,10 +239,8 @@ main(void) autoboot = 1; if ((ino = lookup(PATH_CONFIG)) || - (ino = lookup(PATH_DOTCONFIG))) { - nbyte = fsread(ino, cmd, sizeof(cmd) - 1); - cmd[nbyte] = '\0'; - } + (ino = lookup(PATH_DOTCONFIG))) + fsread(ino, cmd, sizeof(cmd) - 1); if (*cmd) { memcpy(cmddup, cmd, sizeof(cmd)); --------------060704000108040704050100--