Exposes the buildid hash through sysctl and adds uname -b to display the buildid
Details
- Reviewers
emaste imp - Commits
- rS348611: Expose the kernel's build-ID through sysctl
check output using uname and sysctl
Diff Detail
- Lint
Lint Passed - Unit
No Test Coverage - Build Status
Buildable 24359 Build 23181: arc lint + arc unit
Event Timeline
sys/kern/kern_mib.c | ||
---|---|---|
501 | Please explain the magic number. Or, better still, #define it and put the explanation there. |
Just to be clear, this doesn't compile yet on !amd64? Also, does uname -a still work for a kernel built without build-id?
sys/kern/kern_mib.c | ||
---|---|---|
491 | Does this link if you don't have build-id support in the linker? |
sys/kern/kern_mib.c | ||
---|---|---|
501 | trying 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. |
sys/kern/kern_mib.c | ||
---|---|---|
491 | In the updated diff I fix all linker scripts. This will show up as an empty section. |
- Addresses Ed Maste's feedback. This change allows the sysctl to return any build-id between 1 and 20 bytes.
Sample output:
root@skylake8:~ # uname -a
FreeBSD skylake8.rcs.uwaterloo.ca 13.0-CURRENT FreeBSD 13.0-CURRENT #9 da147860ca7(master)-dirty: Mon May 20 17:32:20 EDT 2019 ali@strange.rcs.uwaterloo.ca:/build/ali/obj/working/freebsd-dev/amd64.amd64/sys/GENERIC amd64 42e907d740dd9560a2dfd7187eee20e41e9fbd9f
root@skylake8:~ # uname -b
42e907d740dd9560a2dfd7187eee20e41e9fbd9f
I worry that there are tools parsing uname -a and will be confused by the extra output. Maybe we should commit the kernel changes first and ask for an exp-run (and broader user testing) on the uname changes.
sys/kern/kern_mib.c | ||
---|---|---|
494 | May 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. */ | |
495 | And similarly, move the length comment here as well: /* 20 (SHA-1) hash size */ | |
509 | If 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) |