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 ¶
const ( // ExternalFormatELF and ExternalFormatMachO are the values returned in // ExternalAnalysis.Format. ExternalFormatELF = "elf" ExternalFormatMachO = "macho" )
const SymbolEntryCarrierMagic uint64 = 0x314d59534f474c4c // LLGOSYM1
SymbolEntryCarrierMagic identifies reserved storage whose entries must be collected from the final native symbol table, without references in IR.
Variables ¶
This section is empty.
Functions ¶
func DetachExternal ¶
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.
func SymbolEntryReserveSize ¶ added in v1.0.10
func SymbolEntryReserveSize(analysis ExternalAnalysis) (uint64, error)
SymbolEntryReserveSize bounds the encoded table, including its sentinel and buckets spanning foreign text between Go functions. The extra bucket covers an unaligned first PC; entry and text offsets use the runtime's uint32 format.
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 ¶
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 source-level name of 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 ¶
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. Raw-site carriers support first-use construction; symbol-only carriers require a successful rewrite. Any failure leaves the input byte-for-byte unchanged.