Link-time symbol alternate selection
Andy Ross
This change is a little experimental. Comments requested.
The last patch in the series has the clearest explanation of the justification: we have two printf() formatters in the code base, one for printk() with a minimal implementation and one in minimal libc which is more standards compliant. But many/most projects that use the latter end up including both versions, which is a few hundred bytes of waste. Wouldn't it be nice if we could use printk() as it stands in drivers, etc..., but if some OTHER code happened to suck libc printf into the mix "fall forward" to use the bigger version automatically? Now we can. This series introduces a FUNC_ALIAS_PRIORITY mechanism which allows exactly this behavior -- priority-based selection among symbols referenced (not just included!) in the link. Basically this leverage the pre-existing two phase link we were already doing on x86. The first pass includes all versions of the aliased symbols and some metadata emitted by that macro, then the second pass gets some linker script output that tells it which ones to junk and which to include. Longer term, it would be fun to use this mechanism for other tricks. How about automagic "stub reduction" which can detect at link time when only one instance of an API type (one network device, one block storage driver, etc...) exists and eliminate the... return device->api_struct->this_function_callback(my, repeated, arguments); ...style of indirection entirely? The preliminary patch series is here, early patches are cleanup and refactoring, then the switch to a "generic" two phase link, then the printk hack. https://gerrit.zephyrproject.org/r/4427 Makefile: Don't hide the "prebuilt" kernel https://gerrit.zephyrproject.org/r/4428 Makefile: Clean up x86 second stage linker pass https://gerrit.zephyrproject.org/r/4429 Makefile: unify linker behavior, all architectures use two-pass linking https://gerrit.zephyrproject.org/r/4430 Link-time symbol priority-based replacement https://gerrit.zephyrproject.org/r/4431 printk: Use link-time aliasing to share implementation with printf These are just for comment right now, things still missing: + I need to turn my hacky test rig into a proper test + Only x86 works right now. The linker scripts are 100% segregated by architecture (which seems like a bug worth fixing) and I need to paste the same code in to the other platforms.
|
|