what(1) on kernel binary

John Baldwin jhb at FreeBSD.org
Fri Jul 1 13:47:20 GMT 2005


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 at 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 <jhb at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org


More information about the freebsd-hackers mailing list