what(1) on kernel binary
R. Imura
imura at ryu16.org
Fri Jul 1 05:39:40 GMT 2005
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
-------------------------------
Regards,
- R. Imura
More information about the freebsd-hackers
mailing list