Repository navigation
Conversation
A package source now builds into a package library on Win64, and programs
and packages link against it the way Delphi uses BPLs: classes, VMTs, RTTI,
unit initialization and the memory manager are shared across modules.
The package path existed in the compiler but no target enabled it. Every
missing piece was something the program path already did and the package
path did not: loading the system unit and the intern types, finishing the
module in the task scheduler, clearing used units, exporting
implementation symbols reached from inlined code, and resource strings of a
Unicode RTL.
- i_win: set tf_supports_packages for Win64. This is a target-wide ABI
switch: data that may live in another module is addressed through
$indirect slots, so the RTL and all packages are built in that mode.
- Package files are .fpl (library) and .fcp (symbols).
- {$DESIGNONLY}/{$RUNONLY} are stored in the .fcp and enforced (13030,
13031); the library exports PACKAGEFLAGS and a REGPROCS table.
- The internal linker drops an empty .reloc section and an empty import
directory, both of which made the loader reject small packages.
- A package does not take the product runtime prefix. The memory manager
and the monitor are process-wide and are installed by the host; the
prefix units were also queued without a wait point and exported while
still unloaded (access violation in export_unit).
- Taking the address of a routine of another unit is recorded as an
imported symbol, and an implementation-only routine whose address is
taken is marked for export. Address loads reached neither table, so a
program linking SysUtils statically against an RTL package failed on
TMarshal.UnfixString, and an automatically inlined SetMonitorManager on
SysMonitorGetObjectDataFunc.
- The GetTypes catalog of a module lists only the units linked into it.
- x86: the float abs mask and _FPC_TlsKey inside the system unit are read
directly; reading the $indirect slot as data returned wrong values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SysUtils gets LoadPackage, UnloadPackage, InitializePackage and FinalizePackage, driven by the INITFINAL table a package exports, plus module-unload hooks. Classes registers UnRegisterModuleClasses there, so classes, aliases and component-palette entries a leaving image registered are removed and GetClass stays safe after the image is unmapped, also when the package did not unregister them itself or when a dependency is unmapped with it. RegisterClassAlias keeps a private copy of the alias: the caller's constant lives in the package's data section and is gone after UnloadPackage. The same component class is registered on a palette page once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
qualification/dynamic-packages/run.ps1 builds and runs five stages: importing from a required package; inheritance, virtual dispatch and is/as across two packages; unit initialization in a load-time package; LoadPackage, GetClass and UnloadPackage with the unload hooks and a shared dependency unmapped with its last user; package kinds, PACKAGEFLAGS, design-time registration, and the two rejections (13030, 13031). doc/DYNAMIC_PACKAGES.md describes files, build order, kinds, run-time loading, the runtime prefix and the ABI; KNOWN_ISSUES.md lists the boundaries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The field class table of a class with published fields names the VMT of each field's class. It is data: no code reference records that VMT for the package import pass. When a class is used only as the type of a published field - the usual case for a form whose components are created from a form file - a program linked against the package that holds the class failed with VMT_$<unit>_$$_<class>$indirect undefined. The VMT is now registered as an external asm symbol when the class belongs to another module, so the import pass finds it in the package. qualification/dynamic-packages stage2/host_fields: a class with a published field of a package class and no other reference to it. Fails to link before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added 1579b48 Import the VMT of a published field's class from its package. A class used only as the type of a published field (a form whose components are created from a form file) left |
{$LIBSUFFIX} and {$LIBPREFIX} recompute the output file name through
setfilename(), which knows only the plain shared-library extension. In a
package the directives come after the package header, which had already
switched the extension to .fpl, so a versioned package (Delphi's
rtl290.bpl) came out as Base42.dll. A tool that tells installable
packages from plain DLLs by the extension no longer saw it.
After either directive, a package gets its extension back. Requiring
packages import from the versioned file name (Base42.fpl).
qualification/dynamic-packages stage5: a suffixed package and a prefixed
and suffixed package that requires it; the files are .fpl, no .dll, and a
host links the first and loads the second at run time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added d8b140d: Keep the package extension under A versioned package, as Delphi's Found while building a design-time host on top of these packages: an IDE loads several package versions side by side, so versioned names are needed.
|
Three faults of a package that requires an RTL package with Rtti and the generic collections, all found building an application platform on it: - Unit Rtti references FPC_RTTITYPETABLES, the catalog of discoverable types, which only a program got. A package linking Rtti did not link. The package path now emits the catalog of the units it contains. - Inlined System helpers reach implementation symbols of System: InlinedInitialize, an implementation inline routine expanded into the compilerproc fpc_Initialize, put InitializeRecord and the RTTIFlattenInitialize table into every consumer. Only references from interface routines were marked df_has_global_ref / vo_has_global_ref, so the RTL package did not export them and a package using a generic list or a managed record imported symbols nobody exported. References from inline routines are marked now. - A kernel32 routine that System also calls (GetCurrentProcessId) was imported from the RTL package: importlocalrefprocdefs imported every df_has_global_ref procdef of a required package's unit, DLL routines included, and findpackagewithsym accepted the import thunk name. The package does not export thunks, so the module did not load (STATUS_ENTRYPOINT_NOT_FOUND). DLL routines are imported from the DLL, and _$dll$ thunks are never looked up in packages. qualification/dynamic-packages stage6: an RTL package with rtti and generics.*, a package using TObjectList<T>, TList<record>, a managed record, Rtti and GetCurrentProcessId, and a host printing the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added aaae9fc Link Rtti and generics in packages, import DLL routines from the DLL. Building an application platform on an RTL package that contains
The new 🤖 Generated with Claude Code |
|
Sharing Pascal classes between a Win64 host and its plugins is useful. We tested
Please make stage 3 fail when the host reports |
What this adds
Delphi-style run-time packages on Win64. A
packagesource withrequiresandcontainsbuilds into a package library (.fpl, a PE DLL) plus a symbol file (.fcp). Programs and other packages link against it with-FP<name>. Classes, VMTs, RTTI, unit initialization and the memory manager are shared across modules.This is the structure of large Delphi applications that split into a common BPL (base forms, data-access components) and business BPLs that inherit from it and share its object instances. Without packages that structure can't be reproduced, because a shared component instance has to cross the module boundary.
Linux x86-64 is not covered here;
tf_supports_packagesis set for Win64 only.How
The package path already existed in the compiler (
pkgutil,fpcp, the$indirectmachinery the RTL-in-a-DLL route uses), but no target enabled it. Almost every missing piece was something the program path did and the package path did not:Three commits:
Systemof the RTL package. The prefix units were also queued without a wait point and exported while still unloaded, which caused an AV inexport_unit.@TMarshal.UnfixStringin a statically linked SysUtils@SysMonitorGetObjectDataFuncin an automatically inlinedSetMonitorManager$indirectslots read as data. Inside the system unit, the float abs mask and_FPC_TlsKeyare now read directly. Before, the code read the$indirectslot itself as data.SysUtils:LoadPackage/UnloadPackage/InitializePackage/FinalizePackageand module-unload hooks.Classes:UnRegisterModuleClassesremoves the classes, aliases and palette entries of a leaving image.qualification/dynamic-packages/run.ps1,doc/DYNAMIC_PACKAGES.md, and aKNOWN_ISSUES.mdsection.Package kinds:
{$DESIGNONLY}/{$RUNONLY}are stored in the.fcpand enforced (13030 for declaring both, 13031 for linking a design-only package into a program). The library exportsPACKAGEFLAGSand aREGPROCStable.ABI note — please review
tf_supports_packagesis a target-wide switch, not a project option. Data that may live in another module is addressed through$indirectslots, so the RTL and all packages are built in that mode, and so is every Win64 program, including those that use no packages.This needs your judgement. If you would rather keep the default profile unchanged, this could become a separate package-enabled profile instead.
Verification (Win64, this branch vs.
mainat 65c7061)qualification/dynamic-packages/run.ps1MOONBOT_BUILD_OKqualification/pinned-unit/run.ps1RTL-test/run.py(all sources, all modes)mainon the same machineThe two RTL-test failures are the same on
main:core_semanticdebugTStringStream datafails because the machine's ANSI code page is 949 and©is not in it, andwin64_trailing_call_semanticfails its executable gate. Devil chimera did not run (MoonORMot static objects not prepared on this machine).Pulse (indicative, not a qualification run)
pulse_full.pywith--keep-machine-settings --skip-preflight(no power-setting control on this machine), programs hot-rtl, managed, rtl-collections and heartbeat, 6 pairs, 224 cases with a metric:The largest single deltas (SameText family +20–40%,
interface-copy-call) are layout effects, not code changes:asm-sametext-*:asm_sametext_pair_contentis the same prebuilt.objin both binaries. It sits at offset 0 mod 64 in the baseline and 32 mod 64 in the candidate.CaseInterfaceCopy: its loop,FPC_INTF_ASSIGN,TInterfacedObject._AddRefand_Releasedisassemble to identical instruction sequences in both builds, shifted by 0x20. Repeated measurements of this case varied widely (+68% with 4 valid pairs, +155% with 1).A proper qualification run on one of your measurement machines would settle this.
Known boundaries
These are listed in
KNOWN_ISSUES.md:-FPends in IE 2013053103.GetTypesdoes not see types inside packages.🤖 Generated with Claude Code