K 10 svn:author V 3 ian K 8 svn:date V 27 2020-01-17T15:55:14.876017Z K 7 svn:log V 3303 MFC r354709-r354710, r355069, r355439, r355780, r356273, r356472 r354709: Rewrite arm/stack_machdep.c for EABI; add stack(9) support to arm kernels. The old stack_machdep.c code was written for the APCS ABI (aka "oldabi"). When we switched to ARM EABI (back in freebsd 10) this file never got updated, and apparently nobody noticed that until now. The new implementation uses the same stack unwinder code used by the arm implemenation of the db_trace stuff. r354710: Compile in arm/unwind.c if options STACK is in effect; the new arm stack(9) code now uses unwind.c. r355069: When doing ARM stack unwinding as part of stack_save(9), do not search loaded modules (pass 0/false for the can_lock arg). Searching the unwind info in modules acquires an exclusive sxlock, and the stack(9) functions can be called in a context where unbounded sleeps are forbidden (such as from the witness checkorder code). Just ignoring the existence of modules in stack_save() is not ideal, so I'm looking for a better solution, but this commit will make it possible to boot an ARM kernel with WITNESS enabled again, until I get something better. PR: 242200 r355439: Declare the global kernel symbols created by ldscript.arm in arm's machdep.h, and remove a couple scattered local declarations. Most of these aren't referenced in C code (there are some references in asm code), and they also aren't documented anywhere. This helps a bit with the latter. r355780: Rewrite arm kernel stack unwind code to work when unwinding through modules. The arm kernel stack unwinder has apparently never been able to unwind when the path of execution leads through a kernel module. There was code that tried to handle modules by looking for the unwind data in them, but it did so by trying to find symbols which have never existed in arm kernel modules. That caused the unwind code to panic, and because part of panic handling calls into the unwind code, that just created a recursion loop. Locating the unwind data in a loaded module requires accessing the Elf section headers to find the SHT_ARM_EXIDX section. For preloaded modules those headers are present in a metadata blob. For dynamically loaded modules, the headers are present only while the loading is in progress; the memory is freed once the module is ready to use. For that reason, there is new code in kern/link_elf.c, wrapped in #ifdef __arm__, to extract the unwind info while the headers are loaded. The values are saved into new fields in the linker_file structure which are also conditional on __arm__. In arm/unwind.c there is new code to locally cache the per-module info needed to find the unwind tables. The local cache is crafted for lockless read access, because the unwind code often needs to run in context where sleeping is not allowed. A large comment block describes the local cache list, so I won't repeat it all here. r356273: Since arm/unwind.c s conditionally compiled, only call functions in it when one of those conditions is true. Fixes build failure on kernel configs with no debugging options active. r356472: Add #ifdef option-test wrappers around another call to an arm/unwind.c function which is only compiled-in with certain options. Why is it always the most trivial part of a big commit that takes 3 tries to get right? END