Page MenuHomeFreeBSD

POC: Add build-id and gdb_index support.
Needs ReviewPublic

Authored by jhb on Mar 26 2020, 7:02 PM.

Details

Reviewers
emaste
Summary

This is still a POC, and would be split into multiple commits if it
goes in.

This adds build-id support in userland that defaults to off but can
be enabled with WITH_BUILD_ID.

This also adds a "gdb_index" linker feature that is enabled for lld
8.0+. (I know it caused lld to crash in 6. I haven't tested on 7,
but I did bootstrap head from older VMs that had 8.0.1. I've been using
it with 9.0.1 on stable/12 to build GDB binaries where it works well).
The kernel just enables it unconditionally. Userland uses a
WITH_GDB_INDEX that defaults to off. This requires several diffs to
disable it when used with -r since lld complains.

Test Plan
  • built and booted amd64 kernel + world
  • built i386 world, still doing a clean build from scratch and will then do kernel and boot test

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 30120
Build 27927: arc lint + arc unit

Event Timeline

jhb created this revision.Mar 26 2020, 7:02 PM
jhb added inline comments.Mar 26 2020, 7:06 PM
share/mk/bsd.lib.mk
88

The empty test is because stand/i386/Makefile.inc has a 'build-id=none' for LDFLAGS_BIN. Another approach might be to instead support a BUILD_ID variable that gets set to the type of ID to use and let the stand/i386 Makefiles set that to none and have it default to sha1. This would permit changing it to something else more easily if desired. Not quite sure where that would live though. In that case we would always add the flag when the linker supported it, and the control knobs would just be to set it to "none" vs something else. I think it is probably fairly low risk to have build_id always enabled anyway if the linker supports it.

emaste added inline comments.Mar 27 2020, 4:24 PM
lib/csu/i386/Makefile
34

IMO these :N changes can be committed separately now for anyone who might want to experiment with adding --gdb-index to LDFLAGS.

share/mk/bsd.linker.mk
18

Do we have / need to support linkers that don't support this? IMO it's not worth adding support for e.g. lld versions that are not relevant to contemporary FreeBSD.

jhb added inline comments.Apr 6 2020, 11:39 PM
lib/csu/i386/Makefile
34

It's kind of gross to have to do them all over the place. I wish there was a way to make them less gross, but I don't have a better idea. We could maybe have _LDRFLAGS and LDRFLAGS for use with LD -r? That only seems slightly better.

share/mk/bsd.linker.mk
18

I don't know that bfd supports it (it's not listed in --help for current bfd). I also am not sure if gdb_index will go away eventually as I think DWARF 5 might be defining its own version of the same thing?

bdrewery added inline comments.Apr 7 2020, 1:36 AM
lib/csu/i386/Makefile
34

Or a function for compiling and linking would be nice.

LDRFLAGS+= --gdb-index
...
_LDFLAGSFILT= ${_LDFLAGS:${LDRFLAGS:S,^,N,:ts:}}
`

Then you can use ${_LDFLAGSFILT}

I don't know offhand why some of these are LDFLAGS and others are _LDFLAGS.

share/mk/bsd.lib.mk
89

I think this should be something like ${BUILD_ID_METHOD:Usha1} instead of hardcoded.

share/mk/bsd.prog.mk
61

Same here with a variable method.

jhb added inline comments.Apr 7 2020, 11:38 PM
lib/csu/i386/Makefile
34

LDFLAGS is for use with CC (so has -Wl, prefixes, or CC-specific flags like -fuse-ld or -mabi for mips) whereas _LDFLAGS is for direct invocations of LD. In this case, you still would only want to apply the filter for LD invocations that use -r (not all do). Perhaps just having a single _LDRFLAGSFILT would be ok though. Could just assign to it directly.

share/mk/bsd.lib.mk
89

I only did that because we already hardcode it in the kernel build. See my comment above about having some kind of variable to set the method, and perhaps setting it to 'none' in the various boot Makefiles.