I know this topic has come up so many times. I too had issues finding
out why static symbols appear when you use the loader instead of boot2
directly. I scanned through the posts to see the true details as to
why this was happening. Everyone seems to point that there are some
smarts in the loader that allows ddb to see static symbols. (Bruce
knows a way of not using the loader, but it's beyond the point of this
This info is based on my knowledge of the 4.x tree.
I want to make things clear for new hackers. From what I can tell, the
loader does exactly what boot2 does in loading the kernel image. The
only major difference is appending module metadata at the end of the
kernel space (see sys/boot/i386/libi386/bootinfo.c:bi_copymodules()).
The metadata is basically:
1. the kernel name without directory prefix, eg "kernel"
2. the string "elf kernel" as the type
3. any arguments passed to the kernel, eg "-d" (not required)
4. the first address of the kernel space (load_addr)
5. the size of the kernel space (load_addr -> esym)
6. the elfheader
7. esym (sizeof(int))
8. ssym (sizeof(int))
the bootinfo.bi_modulep points to the start of this metadata
information and is then stored in the kernel as preload_metadata.
These variables are picked up by the kernel linker and used in
kern/link_elf.c and kern/subr_module.c. So really there isn't that
much smart inside the loader.
Hopes this information does good to those who need it.