x-lang

← Index

x/tool/link

Sections, symbols and relocations: lay objects out as one program, resolve and patch every name, and read and write object files.

The names a link of OBJECTS would be missing: what a runtime object has to define, or a library has to supply, before link.

Returns: LIST — The names the objects’ relocations take that no object defines, each once, in order of first use

Examples:

(import x/tool/link link-undefined) (link-undefined (list (list () () (list (list 'text 0 'abs "puts" 0))))) => ("puts")
(import x/tool/link link-undefined) (link-undefined (list (list (list (list 'text 1 2 "ab")) (list (list "main" 'text 0 'global)) (list (list 'text 0 'abs "main" 0) (list 'text 1 'abs "exit" 0))))) => ("exit")

Link OBJECTS: lay their sections out, resolve every name, and patch every place that takes one. A name no object defines, or one defined twice, refuses.

Returns: LIST — (SECTIONS SYMBOLS): the output sections, each (NAME ADDRESS SIZE BYTES), and a Dict from each global’s name to (SECTION OFFSET ADDRESS)

Examples:

(import x/tool/link link) (first (first (link (list (list (list (list 'text 1 2 "ab")) (list (list "main" 'text 0 'global)) ())) (fn (_ ss) (List map (fn (_ s) (pair (first s) 4096)) ss)) (fn (_ p o k v s) ())))) => ('text 4096 2 "ab")
(import x/tool/link link) ((first (rest (link (list (list (list (list 'text 1 2 "ab")) (list (list "main" 'text 0 'global)) ()) (list (list (list 'text 4 3 "cde")) (list (list "f" 'text 0 'global)) ())) (fn (_ ss) (List map (fn (_ s) (pair (first s) 4096)) ss)) (fn (_ p o k v s) ())))) get "f") => ('text 4 4100)
(import x/tool/link link) (let ((seen ())) (link (list (list (list (list 'text 1 4 "abcd")) (list (list "main" 'text 0 'global)) (list (list 'text 2 'abs "main" 1)))) (fn (_ ss) (List map (fn (_ s) (pair (first s) 4096)) ss)) (fn (_ p o k v s) (set! seen (list o k v s)))) seen) => (2 'abs 4097 4098)

Write OBJECT as an object file at PATH. Its records are binary, which link-read takes in a fraction of the time text takes, unless FORM is text or a name, a relocation kind or a scope has no binary form (a byte past 127, a scope that is neither global nor local): then they are text.

Returns: NIL

Read the object file at PATH, its records binary or text. From binary records the relocations come grouped by the name each takes, the names in the order they were written and each name’s relocations in theirs; link resolves a name once for the group.

Returns: LIST — The object, (SECTIONS SYMBOLS RELOCS)