Changeset View
Standalone View
sys/kern/kern_mib.c
Show First 20 Lines • Show All 475 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* NOTICE: The *userland* release date is available in | * NOTICE: The *userland* release date is available in | ||||
* /usr/include/osreldate.h | * /usr/include/osreldate.h | ||||
*/ | */ | ||||
SYSCTL_PROC(_kern, KERN_OSRELDATE, osreldate, | SYSCTL_PROC(_kern, KERN_OSRELDATE, osreldate, | ||||
CTLTYPE_INT | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE, | CTLTYPE_INT | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE, | ||||
NULL, 0, sysctl_osreldate, "I", "Kernel release date"); | NULL, 0, sysctl_osreldate, "I", "Kernel release date"); | ||||
/* | |||||
* The build-id is copied from the ELF section .note.gnu.build-id. The linker | |||||
* script defines two variables to expose the beginning and end. LLVM | |||||
* currently uses a SHA-1 hash, but other formats can be supported by checking | |||||
* the length of the section. | |||||
*/ | |||||
extern char __build_id_start[]; | |||||
jhb: Does this link if you don't have build-id support in the linker? | |||||
Done Inline ActionsIn the updated diff I fix all linker scripts. This will show up as an empty section. ali_mashtizadeh.com: In the updated diff I fix all linker scripts. This will show up as an empty section. | |||||
extern char __build_id_end[]; | |||||
static int | |||||
Not Done Inline ActionsMay I suggest that you move the comment about the header here, where the value is defined? i.e. /* The ELF note section has a four byte length for the vendor name, * four byte length for the value, and a four byte vendor specific * type. The name for the build id is "GNU\0". We skip the first 16 * bytes to read the build hash. */ rpokala: May I suggest that you move the comment about the header here, where the value is defined? i.e. | |||||
sysctl_build_id(SYSCTL_HANDLER_ARGS) | |||||
Not Done Inline ActionsAnd similarly, move the length comment here as well: /* 20 (SHA-1) hash size */ rpokala: And similarly, move the length comment here as well:
```
/* 20 (SHA-1) hash size */
``` | |||||
{ | |||||
uintptr_t sectionlen = (uintptr_t)(__build_id_end - __build_id_start); | |||||
int hashlen; | |||||
char buf[41]; | |||||
/* | |||||
Done Inline ActionsPlease explain the magic number. Or, better still, #define it and put the explanation there. rpokala: Please explain the magic number. Or, better still, #define it and put the explanation there. | |||||
Done Inline Actionstrying strange build-id sizes - % cc -Wl,--build-id=0x1234 hello.c file does not report the build-id at all: % file a.out a.out: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 12.0 (1200085), FreeBSD-style, with debug_info, not stripped but readelf shows that it's there: % readelf -n a.out Notes at offset 0x000002c0 with length 0x00000048: Owner Data size Description FreeBSD 0x00000004 NT_FREEBSD_ABI_TAG FreeBSD 0x00000004 NT_FREEBSD_FEATURE_CTL FreeBSD 0x00000004 NT_FREEBSD_NOINIT_TAG Notes at offset 0x00000310 with length 0x00000012: Owner Data size Description GNU 0x00000002 NT_GNU_BUILD_ID (Build id set by ld(1)) my lld defaults to 8-byte xxHash: % cc -Wl,--build-id hello.c % file a.out a.out: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 12.0 (1200085), FreeBSD-style, BuildID[xxHash]=7bda57f23f3db219, with debug_info, not stripped I think we can assume it will be one of 8, 16, or 20 bytes long though. emaste: trying strange build-id sizes - `% cc -Wl,--build-id=0x1234 hello.c`
file does not report the… | |||||
* The ELF note section has a four byte length for the vendor name, | |||||
* four byte length for the value, and a four byte vendor specific | |||||
* type. The name for the build id is "GNU\0". We skip the first 16 | |||||
* bytes to read the build hash. We will return the remaining bytes up | |||||
* to 20 (SHA-1) hash size. If the hash happens to be a custom number | |||||
* of bytes we will pad the value with zeros, as the section should be | |||||
* four byte aligned. | |||||
*/ | |||||
Not Done Inline ActionsIf you move the comments to the definitions as I suggest above, this becomes /* Return the remaining bytes up to the hash size. If the hash * happens to be a custom number of bytes, we will pad the * value with zeros, as the section should be four-byte aligned. */ (with whatever appropriate wrapping, of course) rpokala: If you move the comments to the definitions as I suggest above, this becomes
```
/* Return the… | |||||
if (sectionlen <= 0x10 || sectionlen > 0x24) { | |||||
return (ENOENT); | |||||
} | |||||
hashlen = sectionlen - 0x10; | |||||
for (int i = 0; i < hashlen; i++) { | |||||
uint8_t c = __build_id_start[i+0x10]; | |||||
snprintf(&buf[2*i], 3, "%02x", c); | |||||
} | |||||
Done Inline Actionslet's make this kern.build_id, buildid parses as "buil did" for me emaste: let's make this `kern.build_id`, buildid parses as "buil did" for me | |||||
return (SYSCTL_OUT(req, buf, strlen(buf) + 1)); | |||||
Done Inline Actionsbuild-id emaste: build-id | |||||
} | |||||
SYSCTL_PROC(_kern, OID_AUTO, build_id, | |||||
CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE, | |||||
NULL, 0, sysctl_build_id, "A", "Operating system build-id"); | |||||
SYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD, 0, "Kernel Features"); | SYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD, 0, "Kernel Features"); | ||||
#ifdef COMPAT_FREEBSD4 | #ifdef COMPAT_FREEBSD4 | ||||
FEATURE(compat_freebsd4, "Compatible with FreeBSD 4"); | FEATURE(compat_freebsd4, "Compatible with FreeBSD 4"); | ||||
#endif | #endif | ||||
#ifdef COMPAT_FREEBSD5 | #ifdef COMPAT_FREEBSD5 | ||||
FEATURE(compat_freebsd5, "Compatible with FreeBSD 5"); | FEATURE(compat_freebsd5, "Compatible with FreeBSD 5"); | ||||
▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines |
Does this link if you don't have build-id support in the linker?