diff -ru /usr/src/sys/amd64/include/asm.h sys/amd64/include/asm.h --- /usr/src/sys/amd64/include/asm.h Mon Oct 15 22:19:03 2007 +++ sys/amd64/include/asm.h Thu Dec 20 20:40:40 2007 @@ -83,7 +83,11 @@ #undef __FBSDID #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) .ident s +#define __FBSDID(s) \ + .section set_srcid, "a", @progbits; \ + .p2align 0; \ + .asciz s; \ + .previous; #else #define __FBSDID(s) /* nothing */ #endif /* not lint and not STRIP_FBSDID */ diff -ru /usr/src/sys/arm/compile/KB920X/machine/asm.h sys/arm/compile/KB920X/machine/asm.h --- /usr/src/sys/arm/compile/KB920X/machine/asm.h Mon Oct 15 22:19:06 2007 +++ sys/arm/compile/KB920X/machine/asm.h Thu Dec 20 20:42:31 2007 @@ -104,7 +104,11 @@ #undef __FBSDID #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) .ident s +#define __FBSDID(s) \ + .section set_srcid, "a", @progbits; \ + .p2align 0; \ + .asciz s; \ + .previous; #else #define __FBSDID(s) /* nothing */ #endif diff -ru /usr/src/sys/arm/include/asm.h sys/arm/include/asm.h --- /usr/src/sys/arm/include/asm.h Mon Oct 15 22:19:06 2007 +++ sys/arm/include/asm.h Thu Dec 20 20:42:31 2007 @@ -104,7 +104,11 @@ #undef __FBSDID #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) .ident s +#define __FBSDID(s) \ + .section set_srcid, "a", @progbits; \ + .p2align 0; \ + .asciz s; \ + .previous; #else #define __FBSDID(s) /* nothing */ #endif diff -ru /usr/src/sys/i386/include/asm.h sys/i386/include/asm.h --- /usr/src/sys/i386/include/asm.h Mon Oct 15 22:21:10 2007 +++ sys/i386/include/asm.h Thu Dec 20 20:23:12 2007 @@ -93,7 +93,11 @@ #undef __FBSDID #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) .ident s +#define __FBSDID(s) \ + .section set_srcid, "a", @progbits; \ + .p2align 0; \ + .asciz s; \ + .previous; #else #define __FBSDID(s) /* nothing */ #endif /* not lint and not STRIP_FBSDID */ diff -ru /usr/src/sys/ia64/include/asm.h sys/ia64/include/asm.h --- /usr/src/sys/ia64/include/asm.h Mon Jan 31 09:16:12 2005 +++ sys/ia64/include/asm.h Thu Dec 20 20:43:08 2007 @@ -182,7 +182,11 @@ * ID tag macros */ #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) .ident s +#define __FBSDID(s) \ + .section set_srcid, "a", @progbits; \ + .p2align 0; \ + .asciz s; \ + .previous; #else #define __FBSDID(s) /* nothing */ #endif /* not lint and not STRIP_FBSDID */ diff -ru /usr/src/sys/kern/kern_mib.c sys/kern/kern_mib.c --- /usr/src/sys/kern/kern_mib.c Wed Dec 5 12:00:30 2007 +++ sys/kern/kern_mib.c Thu Dec 20 20:55:58 2007 @@ -38,6 +38,7 @@ #include __FBSDID("$FreeBSD: src/sys/kern/kern_mib.c,v 1.85 2007/12/04 12:28:07 kib Exp $"); +#include "opt_ddb.h" #include "opt_posix.h" #include "opt_config.h" @@ -307,6 +308,93 @@ SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl, "I", "Current secure level"); + +/* + * Based on __FBSDID format, skip common parts that bring no valueable + * information in this context. + */ +static void __unused +srcid_fname(char *id, char **ret, int *retlen) +{ + char *p = NULL; + int l = 0; + + KASSERT(id != NULL, ("id == NULL")); + KASSERT(ret != NULL, ("p == NULL")); + KASSERT(retlen != NULL, ("len == NULL")); + + p = strstr(id, "$FreeBSD: "); + if (p != NULL) + id += strlen("$FreeBSD: "); + l = strlen(id); + p = strstr(id, " Exp $"); + if (p != NULL) + l = p - id; + *ret = id; + *retlen = l; +} + +/* + * Magic generated by the gcc(1) to mark the section ranges with special + * variable names. + */ +extern char __start_set_srcid[]; +extern char __stop_set_srcid[]; + +#define FBSDID_BEGIN (&__start_set_srcid[0]) +#define FBSDID_END (&__stop_set_srcid[0]) + +/* + * Return all __FBSDID tags. The output is huge. + */ +static int +sysctl_kern_srcids(SYSCTL_HANDLER_ARGS) +{ + char *bid = FBSDID_BEGIN; + char *eid = FBSDID_END; + char *s; + int idlen; + char *id; + int error = 0; + + for (s = bid; s < eid; s++) { + srcid_fname(s, &id, &idlen); + error = sysctl_handle_opaque(oidp, "\n", 1, req); + if (error) + break; + error = sysctl_handle_opaque(oidp, id, idlen, req); + if (error) + break; + s += strlen(s); + } + error = sysctl_handle_opaque(oidp, "\0", 1, req); + if (error) + return (error); + return (error); +} +SYSCTL_PROC(_kern, OID_AUTO, srcids, CTLTYPE_STRING|CTLFLAG_RD, 0, 0, + sysctl_kern_srcids, "A", "Revision control tags for kernel sources"); + +#ifdef DDB +#include + +DB_SHOW_COMMAND(srcids, db_srcid_list) +{ + char *bid = FBSDID_BEGIN; + char *eid = FBSDID_END; + char *s; + int slen; + int idlen; + char *id; + + for (s = bid; s < eid; s++) { + srcid_fname(s, &id, &idlen); + db_printf("%.*s\n", idlen, id); + slen = strlen(s); + s += slen; + } +} +#endif #ifdef INCLUDE_CONFIG_FILE /* Actual kernel configuration options. */ diff -ru /usr/src/sys/powerpc/include/asm.h sys/powerpc/include/asm.h --- /usr/src/sys/powerpc/include/asm.h Fri Jan 7 03:29:19 2005 +++ sys/powerpc/include/asm.h Thu Dec 20 20:42:16 2007 @@ -79,7 +79,11 @@ #undef __FBSDID #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) .ident s +#define __FBSDID(s) \ + .section set_srcid, "a", @progbits; \ + .p2align 0; \ + .asciz s; \ + .previous; #else #define __FBSDID(s) /* nothing */ #endif /* not lint and not STRIP_FBSDID */ diff -ru /usr/src/sys/sparc64/include/asm.h sys/sparc64/include/asm.h --- /usr/src/sys/sparc64/include/asm.h Wed Apr 7 07:00:00 2004 +++ sys/sparc64/include/asm.h Thu Dec 20 20:41:20 2007 @@ -101,7 +101,11 @@ #undef __FBSDID #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) .ident s +#define __FBSDID(s) \ + .section set_srcid, "a", @progbits; \ + .p2align 0; \ + .asciz s; \ + .previous; #else #define __FBSDID(s) /* nothing */ #endif /* not lint and not STRIP_FBSDID */ diff -ru /usr/src/sys/sun4v/include/asm.h sys/sun4v/include/asm.h --- /usr/src/sys/sun4v/include/asm.h Thu Nov 23 03:25:16 2006 +++ sys/sun4v/include/asm.h Thu Dec 20 20:41:47 2007 @@ -108,7 +108,11 @@ #undef __FBSDID #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) .ident s +#define __FBSDID(s) \ + .section set_srcid, "a", @progbits; \ + .p2align 0; \ + .asciz s; \ + .previous; #else #define __FBSDID(s) /* nothing */ #endif /* not lint and not STRIP_FBSDID */ diff -ru /usr/src/sys/sys/cdefs.h sys/sys/cdefs.h --- /usr/src/sys/sys/cdefs.h Wed Dec 5 12:00:35 2007 +++ sys/sys/cdefs.h Thu Dec 20 20:17:09 2007 @@ -403,8 +403,12 @@ */ #ifndef __FBSDID #if !defined(lint) && !defined(STRIP_FBSDID) -#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) -#else +#define __FBSDID(s) \ + __asm__(".section set_srcid, \"a\", @progbits"); \ + __asm__(".p2align 0"); \ + __asm__(".asciz " #s); \ + __asm__(".previous"); +#else /* defined(line) || defined(STRIP_FBSDID) */ #define __FBSDID(s) struct __hack #endif #endif