From owner-freebsd-hackers@FreeBSD.ORG Fri Jul 1 13:47:20 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 96F3B16A41C for ; Fri, 1 Jul 2005 13:47:20 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from mv.twc.weather.com (mv.twc.weather.com [65.212.71.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4BD5C43D49 for ; Fri, 1 Jul 2005 13:47:20 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from [10.50.41.231] (Not Verified[65.202.103.25]) by mv.twc.weather.com with NetIQ MailMarshal (v6, 0, 3, 8) id ; Fri, 01 Jul 2005 10:01:07 -0400 From: John Baldwin To: freebsd-hackers@freebsd.org Date: Fri, 1 Jul 2005 09:40:12 -0400 User-Agent: KMail/1.8 References: <20050620152649.GA1201@stack.nl> <20050701053937.GA40965%imura@ryu16.org> In-Reply-To: <20050701053937.GA40965%imura@ryu16.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200507010940.13672.jhb@FreeBSD.org> Cc: Jilles Tjoelker , "R. Imura" Subject: Re: what(1) on kernel binary X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jul 2005 13:47:20 -0000 On Friday 01 July 2005 01:39 am, R. Imura wrote: > Hi, > > On Mon, Jun 20, 2005 at 05:26:49PM +0200, Jilles Tjoelker wrote: > > On FreeBSD 4.x, one could easily determine the version and compilation > > date of a kernel binary like this: > > > > jilles@toad /home/jilles% what /kernel > > /kernel: > > FreeBSD 4.11-STABLE #20: Mon May 9 18:43:52 CEST 2005 > > > > On FreeBSD 5.x/6.x with GCC 3.x, this doesn't work anymore. > > > > The cause is that these two arrays (in /sys/conf/newvers.sh) are now both > > aligned to a 32-byte boundary, so there are 28 null bytes between @(#) > > and the version number: > > > > char sccspad[32 - 4 /* sizeof(sccs) */] = { '\\0' }; > > char sccs[4] = { '@', '(', '#', ')' }; > > > > A possible solution is to change the two arrays to a single one > > containing 28 null bytes and @(#). > > > > char sccs[32] = { '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', > > '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', > > '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', > > '\\0', '@', '(', '#', ')' }; > > It works ok with the former option(A), but it doesn't with latter(B) with > my FreeBSD box. > > (A) cc -c vers.c > > (B) cc -c -O2 -frename-registers -pipe -fno-strict-aliasing -Wall > -Wredundant-decls -Wnested-externs -Wstrict-prototypes > -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual > -fformat-extensions -std=c99 -g -nostdinc -I- -I. -I/usr/src/sys > -I/usr/src/sys/contrib/dev/acpica -I/usr/src/sys/contrib/altq > -I/usr/src/sys/contrib/ipfilter -I/usr/src/sys/contrib/pf > -I/usr/src/sys/contrib/dev/ath -I/usr/src/sys/contrib/dev/ath/freebsd > -I/usr/src/sys/contrib/ngatm -I/usr/src/sys/dev/twa -D_KERNEL -include > opt_global.h -fno-common -finline-limit=8000 --param inline-unit-growth=100 > --param large-function-growth=1000 -fno-omit-frame-pointer -mcmodel=kernel > -mno-red-zone -mfpmath=387 -mno-sse -mno-sse2 -mno-mmx -mno-3dnow > -msoft-float -fno-asynchronous-unwind-tables -ffreestanding -Werror vers.c > > IMHO, the simplest solution is duplicate writing ${VERSION} like this, > but this would let kernel be 20-30bytes bigger. > > ------------------------------- > cat << EOF > vers.c > $COPYRIGHT > char sccs[] = "@(#)${VERSION} #${v}: ${t}"; > char version[] = "${VERSION} #${v}: ${t}\\n ${u}@${h}:${d}\\n"; > char ostype[] = "${TYPE}"; > char osrelease[] = "${RELEASE}"; > int osreldate = ${RELDATE}; > char kern_ident[] = "${i}"; > EOF > ------------------------------- Hmm, this is what I came up with when talking to bde@: --- newvers.sh 15 Jan 2005 13:25:41 -0000 1.68 +++ newvers.sh 22 Jun 2005 14:40:48 -0000 @@ -83,15 +83,15 @@ touch version v=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} t=`date` i=`${MAKE:-make} -V KERN_IDENT` +fullversion="${VERSION} #${v}: ${t}\n ${u}@${h}:${d}"; cat << EOF > vers.c $COPYRIGHT -char sccspad[32 - 4 /* sizeof(sccs) */] = { '\\0' }; -char sccs[4] = { '@', '(', '#', ')' }; -char version[] = "${VERSION} #${v}: ${t}\\n ${u}@${h}:${d}\\n"; -char ostype[] = "${TYPE}"; -char osrelease[] = "${RELEASE}"; -int osreldate = ${RELDATE}; -char kern_ident[] = "${i}"; +const char sccs[] = "@(#)${fullversion}"; +const char version[] = "${fullversion}"; +const char ostype[] = "${TYPE}"; +const char osrelease[] = "${RELEASE}"; +const int osreldate = ${RELDATE}; +const char kern_ident[] = "${i}"; EOF does sccs[] only need to include the version up to the first \n? bde@ noticed that what seemed to stop once it hit \n. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org