Page MenuHomeFreeBSD

Expose the buildid hash through sysctl
ClosedPublic

Authored by ali_mashtizadeh.com on May 20 2019, 8:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 20, 2:45 AM
Unknown Object (File)
Tue, Nov 12, 2:20 AM
Unknown Object (File)
Wed, Oct 30, 11:36 PM
Unknown Object (File)
Sat, Oct 26, 6:01 AM
Unknown Object (File)
Oct 22 2024, 10:13 PM
Unknown Object (File)
Oct 20 2024, 11:32 PM
Unknown Object (File)
Oct 18 2024, 8:50 AM
Unknown Object (File)
Oct 1 2024, 10:01 PM

Details

Summary

Exposes the buildid hash through sysctl and adds uname -b to display the buildid

Test Plan

check output using uname and sysctl

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 24337
Build 23159: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.May 20 2019, 9:04 PM
rpokala added inline comments.
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?

will also want a uname.3 update

sys/kern/kern_mib.c
519

let's make this kern.build_id, buildid parses as "buil did" for me

521

build-id

ali_mashtizadeh.com marked 2 inline comments as done.
  • Updates and linker scripts for other archs
This revision now requires review to proceed.May 20 2019, 9:19 PM
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.

ali_mashtizadeh.com added inline comments.
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

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

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.

  • Update man page and remove from -a
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)

I will pick up whitespace cleanup, .Dd bump etc. for commit

usr.bin/uname/uname.1
31 ↗(On Diff #57632)

will update .Dd upon commit

57 ↗(On Diff #57632)

maybe linker-generated kernel build-id? As is seems to suggest that this is some ID of the linker itself.

I will commit the uname changes separately

This revision was not accepted when it landed; it landed in state Needs Review.Jun 4 2019, 1:07 PM
This revision was automatically updated to reflect the committed changes.