wcc: fix BFD section metadata on Ubuntu 26.04; wsh: globals tracing, kcontext, lsyscall, prototypes_c
WCC (wcc.c):
On Ubuntu 26.04 (GCC 15 / binutils 2.44+), BFD computes section
filepos values from program headers for PIE executables and produces
wildly incorrect results (e.g. 0x500000000 for a 775 KB file). The
newer linker (binutils PR 23657 / PR ld/33457) then correctly rejects
the resulting .o because sh_offset exceeds the file size.
Add fixup_bfd_sections_from_elf(): after load_binary(), detect whether
any BFD section has filepos >= actual file size; when it does, open the
ELF via libelf/GElf (already linked by WCC) and patch every asection's
filepos, vma and size from the real ELF section headers. The fixup is
a no-op on toolchains where BFD reports sane values.
Also add a bfd_get_section_contents() fallback in read_section() for
cases where BFD can still read section data through its own internal
mapping even when pread() against the corrected offset fails.
WSH (wsh.c, wsh.h, wsh_functions.h, wsh_help.h):
Globals tracing -- complete new subsystem for intercepting and logging
every read/write to global variables during a libcall():
- globalstrace() / unglobalstrace(): arm/disarm tracing; uses
mprotect(PROT_NONE) on data sections to trigger SIGSEGV on access,
logs the access, temporarily unprotects the page, sets TF for
single-step, and re-protects in the SIGTRAP handler
- globalspoison() / unglobalspoison(): fill data sections with a
poison pattern to surface uninitialised-read assumptions
- globals_reify(): return a Lua proxy table with __index/__newindex
metamethods for live read/write of any named global by symbol name
- globals_show(): display the access log
- globals_addr(): resolve a global name to its runtime address
- Three scope modes: GLOBALS_SCOPE_TARGET (loaded binary only),
GLOBALS_SCOPE_ALL, GLOBALS_SCOPE_NAMED (explicit section list)
- Supporting helpers: globals_protect/unprotect/poison_sections(),
globals_is_self(), globals_section_in_scope(), object_from_addr(),
object_by_name()
prototypes_c(): emit SAL-annotated C prototypes (_In_, _Out_, _Inout_,
_Exec_) from learned argument behaviour, with header guards and
standard includes.
lsyscall(): invoke raw Linux syscalls (up to 6 arguments) from Lua.
CPU register access: eflags_get() / eflags_set() (with TF masking),
fsbase_get() / gsbase_get() via arch_prctl.
kcontext(): dump the userland-visible kernel context (task_struct
projection) as a Lua table -- Tier 1 (syscalls: pid/tid/ppid,
uid/gid, capabilities via capget, cwd, signal mask, resource limits)
and Tier 2 (/proc/self: umask, per-fd target+offset+flags, signal
dispositions, namespace identities).
load_symtab_file() / load_target_symtab(): merge .symtab symbols from
on-disk ELF files into the runtime symbol table so file-local and
static globals get names (supplements .dynsym which only has exported
symbols).
Signal handler hardening: add in_fault re-entrancy guard to prevent
recursive faults; stack overflow detection via base_ptr comparison;
msync-based pointer validation before dereferencing the link_map chain.