Centralize the kernel and module metadata types
Currently, the way we get the kernel metadata pointer is by calling preload_search_by_type with one of the following three: "elf kernel", "elf32 kernel" and "elf64 kernel". Which one(s) we use isn't consistent though. Sometimes we would only try "elf kernel", and other times we would try one of the latter two if the first failed. However, the loader only ever sets "elf kernel" as the kernel type. See: https://github.com/freebsd/freebsd-src/blob/8afae0caf4c4816eb56b732fcd1a4b185e86098a/stand/common/load_elf.c#L92
Instead, make the kmdp a global, preload_kmdp, and initialize it using preload_initkmdp in machdep.c (or machdep_boot.c on arm/64). preload_initkmdp takes a single boolean argument that tells us whether not finding kmdp is fatal or not.
Also, feel free to critique my commit message. I feel like it's not great, but that's the best I could word it.
Fixed some style warnings
I'll take a look. @kostikbel and @kevans91 should take a look too.
My opinion is that this is an enormous churn.
Regardless of it, I think even the approach is not taken to the logical completion. All "elf kernel" literals must be replaced by the global const string which is used by reference, both in loader and in kernel.
Ideally, we would have some enumeration value used to identify type, instead of free-typed string, but for this change at least replacing all individual strings with the same reference to constant string is the least required step.
My opinion is that this is an enormous churn.
Yes, but it centralizes where we get the metadata at least. It also removes a bunch of unnecessary checks where kmdp can't be NULL. IMO most of the changes are trivial.
Regardless of it, I think even the approach is not taken to the logical completion. All "elf kernel" literals must be replaced by the global const string which is used by reference, both in loader and in kernel.
You're right, they should be. But for the kernel, after this patch, I believe the only reference to "elf kernel" would be in preload_initkmdp.
I'll take a closer look at this. It's basically OK, but I think I have some misgivings I need to put into an actionable form.
Looking more into what @kostikbel said, I've decided to move "elf kernel" and friends to sys/linker.h as macros. The reason they're macros an no longer globals is so that they can be easily shared across both the loader and kernel code.
Other preload_search_by_type calls either use macros or use a single free-typed string (i.e it only has one reference), so I think this is better.
Also, I noticed that we also check for "elfN module" and "elfN obj module", so I removed those too.
Alright, settled on modinfo.c at the end
Also, needed to make file_loadraw accept a const char * for the type string instead of a plain char *
Update and rebase after b538d4911004ca541507166b8ec9689d2e87d1aa
landed.
Thanks!