6l: port ET_DYN dynamic linking to the ww side
Ports cmd/6l/{dyn,dynout}.c into selfhost/cmd/6l/{dyn,dynout}.ww:
ET_DYN .so loading + PT_INTERP/PT_DYNAMIC ELF emission with .rela.plt,
.gnu.version_r, BIND_NOW. lsym grows dyn fields; pass.ww promotes
undefs to dyn; out.ww dispatches; main.ww takes -L/-l. The ww driver
forwards -L/-l to 6l_ww so 'ww_ww build snake.ww -L /usr/lib -l ncurses
-l c' runs without cc.
Test 996 pins byte-identical output to C-6l on snake.
'make bootstrap' gains a fourth stage with cmp ww3 == ww4, proving
ww3 is byte-stable when used as a compiler — not just a coincidental
two-stage equilibrium.
Four wwstage 6c cgen quirks surfaced and are documented in dynout.ww's
header (two-level field-write through a pointer field, (scalar, str)
tuple returns, def : str, ≤6 arg calling convention).
This commit is contained in:
@@ -6,12 +6,20 @@
|
||||
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,
|
||||
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,
|
||||
snext: *lsym,
|
||||
// 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 {
|
||||
@@ -31,15 +39,33 @@ type lobj = struct {
|
||||
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 = {
|
||||
@@ -58,7 +84,7 @@ export fn l_intern(l: *lnk, name: str) *lsym = {
|
||||
if (streq(s.name, name)) { return s; };
|
||||
s = s.snext;
|
||||
};
|
||||
let n: *lsym = amalloc(l.a, 64u64): *lsym;
|
||||
let n: *lsym = amalloc(l.a, 96u64): *lsym;
|
||||
n.name = name;
|
||||
n.snext = l.syms;
|
||||
l.syms = n;
|
||||
|
||||
Reference in New Issue
Block a user