ww: rename toolchain to w-prefix + hare-style build/run/test driver
Plan 9-style w-prefix on the per-arch tools, disambiguating from the
real Plan 9 6c/6a/6l in ref/plan9front/:
cmd/wwc/ → cmd/wcc/ libwwc.a → libwcc.a
cmd/6{c,a,l} → cmd/w6{c,a,l} binary names too
test/wwc/ → test/wcc/ 6 test files w/ w6 prefix
selfhost/cmd mirror in lockstep
bootstrap/amd64/{w6c,w6a,w6l} snapshot binaries (gitignored)
WW_6{C,A,L} → WW_W6{C,A,L} env-var overrides
Plan 9 source-tree refs ("Plan 9 6c shape", ref/plan9front/, etc.)
preserved. Hare-style driver, both C and ww sides:
ww test [path] discover *_test.ww in a directory module, run
each; single-file mode for `ww test foo.ww`
Module-by-name `ww build foo` resolves to foo.ww or foo/foo.ww
via search path (cwd : -I dirs : $WW_LIB)
Default-to-cwd `ww build` / `ww test` build the cwd module
Run pass-through `ww run path arg1 arg2` reaches the program
lib/os: getcwd (79) and getdents64 (217) syscalls power `.` resolution
and directory enumeration on the ww side.
Makefile: wwstage tool deps now include lib/os/os.ww (+ lib/strconv
for wwdump_ww) so lib/* edits force their rebuild instead of leaving
stale binaries — surfaced when test 995 first failed against a stale
w6c_ww built before the lib/os additions.
Test 993 byte-identical parity gate (C-side ww vs ww-side ww_ww on a
build corpus) stays green; all 19 tests pass.
This commit is contained in:
101
selfhost/cmd/w6l/sym.ww
Normal file
101
selfhost/cmd/w6l/sym.ww
Normal file
@@ -0,0 +1,101 @@
|
||||
// selfhost/cmd/w6l/sym.ww — port of cmd/w6l/sym.c.
|
||||
//
|
||||
// Linker symbol table. Singly-linked list, usually a few hundred
|
||||
// entries; hashing isn't worth it yet.
|
||||
|
||||
use mem;
|
||||
|
||||
type lsym = struct {
|
||||
name: str,
|
||||
val: u64, // offset within combined .text once linked
|
||||
defined: i32, // 1 if some lobj defines this symbol
|
||||
owner: *lobj,
|
||||
idx_in_owner: i32,
|
||||
// Dynamic-linking fields. Set by l_resolve when an undefined sym
|
||||
// is provided by some loaded lso. plt_idx and dynsym_idx default
|
||||
// to -1 (set explicitly by l_resolve, not by amalloc-zeroing).
|
||||
is_dyn: i32,
|
||||
dyn_lib: *lso,
|
||||
dyn_version: str, // matched export's version; len 0 if none
|
||||
plt_idx: i32,
|
||||
dynsym_idx: i32,
|
||||
snext: *lsym,
|
||||
};
|
||||
|
||||
type lrel = struct {
|
||||
off: u64, // offset within combined .text
|
||||
kind: i32, // R_X86_64_*
|
||||
sym: *lsym,
|
||||
addend: i64,
|
||||
rnext: *lrel,
|
||||
};
|
||||
|
||||
type lobj = struct {
|
||||
path: str,
|
||||
buf: *u8, // object bytes
|
||||
len: u64,
|
||||
text_off: u64, // offset of .text in combined output
|
||||
text_size: u64,
|
||||
onext: *lobj,
|
||||
};
|
||||
|
||||
// lexport — one entry per GLOBAL/WEAK symbol exported by a loaded .so.
|
||||
// Stored as a chain in the order the .so's dynsym presents them, so
|
||||
// l_so_provides_v's first-match semantics agree with the C version.
|
||||
type lexport = struct {
|
||||
name: str,
|
||||
version: str, // len 0 for unversioned globals
|
||||
enext: *lexport,
|
||||
};
|
||||
|
||||
type lso = struct {
|
||||
path: str, // full filesystem path used to load
|
||||
soname: str, // DT_SONAME, or basename if missing
|
||||
exports: *lexport, // dynsym-order chain of exported names
|
||||
sonext: *lso,
|
||||
};
|
||||
|
||||
type lnk = struct {
|
||||
a: *arena,
|
||||
objs: *lobj,
|
||||
sos: *lso,
|
||||
syms: *lsym,
|
||||
rels: *lrel,
|
||||
text: *u8, // combined .text
|
||||
textcap: u64,
|
||||
textlen: u64,
|
||||
errs: i32,
|
||||
dyn_n: i32, // number of syms routed through PLT
|
||||
};
|
||||
|
||||
fn streq(a: str, b: str) bool = {
|
||||
if (a.len != b.len) { return false; };
|
||||
let i: i32 = 0;
|
||||
for (i < a.len) {
|
||||
if (a[i] != b[i]) { return false; };
|
||||
i += 1;
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
export fn l_intern(l: *lnk, name: str) *lsym = {
|
||||
let s: *lsym = l.syms;
|
||||
for (s != nil) {
|
||||
if (streq(s.name, name)) { return s; };
|
||||
s = s.snext;
|
||||
};
|
||||
let n: *lsym = amalloc(l.a, 96u64): *lsym;
|
||||
n.name = name;
|
||||
n.snext = l.syms;
|
||||
l.syms = n;
|
||||
return n;
|
||||
};
|
||||
|
||||
export fn l_lookup(l: *lnk, name: str) *lsym = {
|
||||
let s: *lsym = l.syms;
|
||||
for (s != nil) {
|
||||
if (streq(s.name, name)) { return s; };
|
||||
s = s.snext;
|
||||
};
|
||||
return nil;
|
||||
};
|
||||
Reference in New Issue
Block a user