--- /usr/src/sys/amd64/include/asm.h 2007-12-30 13:49:11.000000000 +0000 +++ src/sys/amd64/include/asm.h 2007-12-30 22:09:37.000000000 +0000 @@ -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 */ --- /usr/src/sys/arm/include/asm.h 2007-12-30 13:49:12.000000000 +0000 +++ src/sys/arm/include/asm.h 2008-01-03 01:19:27.000000000 +0000 @@ -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 --- /usr/src/sys/i386/include/asm.h 2007-12-30 13:54:25.000000000 +0000 +++ src/sys/i386/include/asm.h 2007-12-30 22:09:38.000000000 +0000 @@ -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 */ --- /usr/src/sys/ia64/include/asm.h 2007-12-30 13:54:27.000000000 +0000 +++ src/sys/ia64/include/asm.h 2007-12-30 22:09:38.000000000 +0000 @@ -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 */ --- /usr/src/sys/powerpc/include/asm.h 2007-12-30 13:54:39.000000000 +0000 +++ src/sys/powerpc/include/asm.h 2007-12-30 22:09:42.000000000 +0000 @@ -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 */ --- /usr/src/sys/sparc64/include/asm.h 2007-12-30 13:54:40.000000000 +0000 +++ src/sys/sparc64/include/asm.h 2007-12-30 22:09:42.000000000 +0000 @@ -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 */ --- /usr/src/sys/sun4v/include/asm.h 2007-12-30 13:54:41.000000000 +0000 +++ src/sys/sun4v/include/asm.h 2007-12-30 22:09:42.000000000 +0000 @@ -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 */ --- /usr/src/sys/sys/cdefs.h 2007-12-30 13:54:41.000000000 +0000 +++ src/sys/sys/cdefs.h 2008-01-05 02:40:48.000000000 +0000 @@ -402,11 +402,52 @@ * __FBSDID("$FreeBSD: src/sys/sys/cdefs.h,v 1.94 2007/12/09 21:00:36 alc Exp $"); */ #ifndef __FBSDID -#if !defined(lint) && !defined(STRIP_FBSDID) +#if defined(lint) || defined(STRIP_FBSDID) +#define __FBSDID(s) struct __hack +#else +/* + * We want to have tags embedded. We let the user choose between the + * behaviour he wants to have. This can still be old, bare and boring + * FBSDID... Note that you won't get kern.srcids handling that way. + */ +#if defined(OLD_FBSDID) #define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) #else -#define __FBSDID(s) struct __hack +/* + * Smart user however prefers fully featured, brand new one FBSDID. + * This is the right choice to get kern.srcids working. DDB command + * "show srcids" included as well. + * + * ARM is a bit special. + */ +#ifdef __arm__ +#define FBSDID_SECTYPE "%progbits" +#else +#define FBSDID_SECTYPE "@progbits" +#endif + +/* + * i386, amd64 and ia64 are special too--instead of: .section "name", + * they want: .section name + */ +#if defined(__i386__) || defined(__amd64__) || defined(__ia64__) +#define FBSDID_SECTION() \ + __asm__(".section set_srcid,\"a\"," FBSDID_SECTYPE) +#else /* expect __sparc64__, __arm__, __powerpc__ and __sun4v */ +#define FBSDID_SECTION() \ + __asm__(".section \"set_srcid\",\"a\"," FBSDID_SECTYPE) #endif + +/* + * And finally + */ +#define __FBSDID(s) \ + FBSDID_SECTION(); \ + __asm__(".p2align 0"); \ + __asm__(".asciz " #s); \ + __asm__(".previous"); +#endif /* __FBSDID */ +#endif /* defined(STRIP_FBSDID) || defined(lint) */ #endif #ifndef __RCSID --- /usr/src/sys/kern/kern_mib.c 2007-12-30 13:54:27.000000000 +0000 +++ src/sys/kern/kern_mib.c 2007-12-30 22:09:39.000000000 +0000 @@ -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" @@ -308,6 +309,106 @@ CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl, "I", "Current secure level"); +/* + * If STRIP_FBSDID is defined it means we should save as much as + * possible in terms of the kernel size. Handle "kern.srcids" and "show + * srcids" DDB command only in !STRIP_FBSDID case. Otherwise, we'd need + * at least one thing lying in the srcid magic section so that we + * wouldn't be getting an error about __(start|stop)_set_srcid being + * undefined due to non-existent .srcid section; and it all would be + * just to get useless output.. + */ +#ifndef STRIP_FBSDID + +/* + * 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 +#endif /* STRIP_FBSDID */ + #ifdef INCLUDE_CONFIG_FILE /* Actual kernel configuration options. */ extern char kernconfstring[];