pclnpost

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package pclnpost implements the P1/P2 prototype of link-phase ftab/findfunctab generation (doc/design/pclntab-linkphase.md). It parses a linked LLGo binary's funcinfo site section, deduplicates LTO inline copies against the symbol table, sorts the entries, builds the Go-layout findfunctab via internal/pclntab, and transactionally replaces the linked image. Isolated LTO carriers in embedded Mach-O executables are physically compacted; shared carriers in other Mach-O build modes retain their file layout.

Index

Constants

View Source
const (
	// ExternalFormatELF and ExternalFormatMachO are the values returned in
	// ExternalAnalysis.Format.
	ExternalFormatELF   = "elf"
	ExternalFormatMachO = "macho"
)

Variables

This section is empty.

Functions

func DetachExternal

func DetachExternal(path string, identity [sha256.Size]byte) error

DetachExternal verifies that identity still names the unmodified binary, writes it into the dedicated 32-byte identity section, and clears all link-only entry and PC-line site sections. Mach-O chained fixups in those ranges are removed before the bytes are cleared. A signed Mach-O is ad-hoc re-signed once, after all mutations, before the replacement is published atomically.

Types

type ExternalAnalysis

type ExternalAnalysis struct {
	Format      string
	PointerSize int
	ImageBase   uint64
	TextStart   uint64
	TextEnd     uint64
	Identity    [sha256.Size]byte

	EntrySites  []ExternalSite
	PCLineSites []ExternalSite

	EntryRecords  int
	PCLineRecords int
	InlineCopies  int
	NoSymbol      int
}

ExternalAnalysis is the immutable input for an external pclntab sidecar. TextStart and TextEnd are link-time virtual addresses; sites are expressed relative to ImageBase after LTO-copy deduplication against the final symbol table. Identity is SHA-256 of the complete, unmodified linked binary.

func AnalyzeExternal

func AnalyzeExternal(path string) (ExternalAnalysis, error)

AnalyzeExternal reads a linked ELF or Mach-O executable without modifying it. It resolves Mach-O chained pointer slots, deduplicates function records against final text symbols, and returns deterministic image-base- relative site lists suitable for an external sidecar.

type ExternalSite

type ExternalSite struct {
	PCOffset    uint64
	ID          uint64
	OwnerSymbol string
}

ExternalSite is one final linked site. PCOffset is relative to the image base, so it remains valid after ASLR. ID is a funcinfo symbol ID for an entry site and a pcline record ID for a PC-line site. PC-line sites also carry the final linked owner in OwnerSymbol; it is a post-link join key and is not serialized into the sidecar.

type Stats

type Stats struct {
	Format       string
	EntryRecords int
	Kept         int
	InlineCopies int
	NoSymbol     int
	FtabEntries  int
	Buckets      int
	// CarrierBytesRemoved is the number of bytes cut from the metadata carrier
	// before an existing Mach-O code signature is regenerated. It is not the
	// signed output file's net size change.
	CarrierBytesRemoved uint64
}

Stats summarizes one rewrite.

func Rewrite

func Rewrite(path string) (Stats, error)

Rewrite parses the linked binary's funcinfo site sections, deduplicates LTO inline copies against the symbol table, builds the Go-layout prebuilt table, stages a compact executable image, and atomically replaces the input. The runtime adopts the table when it sees the magic header and falls back to first-use construction otherwise, so failures here leave a fully functional and byte-for-byte unchanged binary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL