Placed.lean
Placed Libraries in Linked ELF Executables (Arm64.)
-
Layer / Role:
Arm64Trusted Computing Base (Role::Spec, definitions only, 0 theorems). -
Purpose & Key Exports: When a parsed static ELF executable contains a placed library (
Obj.img lib pl): the patched text and data bytes ofPlacedLib. InElf libunder placementplare mapped inimg'sPT_LOADsegments (text executable, data readable, writable data writable), and each exported function has exactly one.symtabentry, at its placed address.Obj.lib elfBytes pl says the raw ELF filePlacedLib. LinkedAt elfBytesparses to such an image for thePlaceableplacementpl, andObj.lib elfBytes (PlacedLib. LinkedIn ∃ pl, LinkedAt) is the satisfiability (non-vacuity) witness for a layout-generic library contract (Obj.) against a real linked binary.PlacedLib. subroutineOk InElfconstrainspl.ρonly through relocated text/data bytes and data-object placement: a spec mentioningpl.ρ xfor a symbol no relocation or data object uses is not tied to the ELF's.symtab. -
When to read: Read when auditing a library's precondition-satisfiability statement or when composing a library contract into a whole-binary ELF proof.
@[expose] public sectionnamespace Arm64.Objopen Arm64.Processdef ElfMaps
img maps bytes at [addr, addr + bytes. in its PT_LOAD segments: byte i is the byte at addr + i of the first segment containing that address (as in ElfImage.), with a permission satisfying ok.
def ElfMaps (img : ElfImage) (addr : BitVec 64) (bytes : List (BitVec 8)) (ok : Perm → Bool) :
Prop :=
∀ (i : Nat) (hi : i < bytes.length), ∃ p,
Snapshot.cellAt img.segments (addr + BitVec.ofNat 64 i) = some (some p, bytes[i]) ∧ ok p3 declarations not shown (lines 48–67): theorems, which Lean checks, or definitions that no headline statement uses
Arm64., Arm64., Arm64., Arm64., Arm64., Arm64.
structure MultiPlacedLib.
The parsed executable img contains multi-block library lib placed under mpl:
-
every block
i's patched text (lib.) is mapped executable (blocks[i].patched (lib. blockPlacement mpl i) r-x) atmpl.;base i -
each data object's initial bytes (
lib.) are mapped atpatchedData mpl d mpl.ρ d., readable ifsym d.and exactlyreadOnly rw-otherwise; -
each exported function
eoflibis defined in some blockiat offsetoffand its raw namelib.has exactly oneelfSym e .symtabentry, atmpl..base i + off
structure MultiPlacedLib.InElf (img : ElfImage) (lib : MultiPlacedLib) (mpl : MultiPlacement) :
Prop where
blocks : ∀ (i : Nat) (hi : i < lib.blocks.length),
ElfMaps img (mpl.base i) (lib.blocks[i].patched (lib.blockPlacement mpl i)) (· == Perm.rx)
data : ∀ d ∈ lib.data,
ElfMaps img (mpl.ρ d.sym) (lib.patchedData mpl d)
(fun p => if d.readOnly then p.r else p == Perm.rw)
exports : ∀ e ∈ lib.exports, ∃ i off,
lookupBlockSym e lib.blocks = some (i, off) ∧
lookupUnique (lib.elfSym e) img.symbols = some (mpl.base i + BitVec.ofNat 64 off)
def MultiPlacedLib.
The ELF executable elfBytes links multi-block library lib at multi-block placement mpl: it parses (ElfImage.) to an image containing lib under mpl, and lib is Placeable at mpl.
def MultiPlacedLib.LinkedAt (lib : MultiPlacedLib) (elfBytes : List (BitVec 8))
(mpl : MultiPlacement) : Prop :=
∃ img, ElfImage.parse elfBytes = .ok img ∧ lib.Placeable mpl ∧ lib.InElf img mpl
abbrev MultiPlacedLib.
The ELF executable elfBytes links multi-block library lib at some multi-block placement (MultiPlacedLib.).
abbrev MultiPlacedLib.LinkedIn (lib : MultiPlacedLib) (elfBytes : List (BitVec 8)) : Prop :=
∃ mpl, lib.LinkedAt elfBytes mplend Arm64.Obj