1-
21{ ===============================================================================
32 _ _ _ _ _ __ ____ __ ™
43 | (_) |__| | | |\ \ / / \/ |
3938 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4039
4140 ------------------------------------------------------------------------------
42-
41+
4342 This library uses the following open-source libraries:
44- * LLVM - https://github.com/llvm/llvm-project
45-
43+ * Dlluminator - https://github.com/tinyBigGAMES/Dlluminator
44+ * LLVM - https://github.com/llvm/llvm-project
45+
4646===============================================================================}
4747
4848unit libLLVM.API;
@@ -2426,111 +2426,7 @@ LLVMOrcCLookupSetElement = record
24262426 LLVMPassBuilderOptionsSetMergeFunctions: procedure(Options: LLVMPassBuilderOptionsRef; MergeFunctions: LLVMBool); cdecl;
24272427 LLVMPassBuilderOptionsSetInlinerThreshold: procedure(Options: LLVMPassBuilderOptionsRef; Threshold: Integer); cdecl;
24282428 LLVMDisposePassBuilderOptions: procedure(Options: LLVMPassBuilderOptionsRef); cdecl;
2429-
2430-
2431- // / <summary>
2432- // / Invokes the LLD linker (via the combined LLVM-C + LLD DLL) with the given command-line
2433- // / arguments and linker <c>AFlavor</c>, returning LLD’s process-style exit code and whether
2434- // / the linker may be safely called again within the same process.
2435- // / </summary>
2436- // /
2437- // / <param name="AArgs">
2438- // / Command-line tokens to forward to LLD as <c>argv</c>. This should mirror what you would
2439- // / pass to the command-line tools (e.g., <c>lld-link</c>, <c>ld.lld</c>, <c>ld64.lld</c>, <c>wasm-ld</c>).
2440- // / <para>
2441- // / If the first element is missing or starts with <c>-</c>/<c>/</c>, the wrapper inserts a suitable
2442- // / tool token for <c>AFlavor</c> as <c>argv[0]</c>. Valid defaults are:
2443- // / <list type="bullet">
2444- // / <item><description><c>coff</c> → <c>lld-link</c></description></item>
2445- // / <item><description><c>elf</c> → <c>ld.lld</c></description></item>
2446- // / <item><description><c>macho</c>/<c>darwin</c> → <c>ld64.lld</c></description></item>
2447- // / <item><description><c>wasm</c> → <c>wasm-ld</c></description></item>
2448- // / <item><description><c>mingw</c> → <c>ld.lld</c></description></item>
2449- // / </list>
2450- // / </para>
2451- // / <para>
2452- // / All tokens are marshaled as UTF-8 and passed verbatim to LLD. Include your object files,
2453- // / libraries, and options (e.g., <c>/out:app.exe</c>, <c>/subsystem:console</c>,
2454- // / <c>/libpath:...</c>, <c>kernel32.lib</c>, <c>ucrt.lib</c>, <c>vcruntime.lib</c>,
2455- // / <c>legacy_stdio_definitions.lib</c>, etc.).
2456- // / </para>
2457- // / </param>
2458- // /
2459- // / <param name="AFlavor">
2460- // / Linker “driver” to invoke: <c>coff</c>, <c>elf</c>, <c>macho</c>, <c>wasm</c>, or <c>mingw</c>
2461- // / (case-insensitive). If empty, LLD auto-detects based on <c>argv[0]</c> and inputs.
2462- // / </param>
2463- // /
2464- // / <param name="ACanRunAgain">
2465- // / <c>True</c> if LLD reports it is safe to call again in the same process; <c>False</c> if a
2466- // / fatal/unsafe condition was detected (e.g., crash-recovery scenario). If <c>False</c>,
2467- // / do not invoke LLD again in this process—restart a helper process instead.
2468- // / </param>
2469- // /
2470- // / <returns>
2471- // / LLD’s exit code (0 = success; non-zero = failure). Typical link errors return 1 with
2472- // / diagnostics emitted by LLD (enable <c>/verbose</c> to increase detail).
2473- // / </returns>
2474- // /
2475- // / <remarks>
2476- // / <para><b>Requirements:</b> The combined DLL must export <c>LLD_Link</c> and the relevant LLD drivers
2477- // / must be linked in (e.g., <c>lldCOFF</c>, <c>lldELF</c>, <c>lldMachO</c>, <c>lldWasm</c>, <c>lldMinGW</c>, plus <c>lldCommon</c>).</para>
2478- // / <para><b>CRT/SDK:</b> For COFF, ensure the correct CRT set is provided:
2479- // / <list type="bullet">
2480- // / <item><description><b>Dynamic (/MD)</b>: <c>ucrt.lib</c>, <c>vcruntime.lib</c>, <c>legacy_stdio_definitions.lib</c>, <c>kernel32.lib</c></description></item>
2481- // / <item><description><b>Static (/MT)</b>: <c>libucrt.lib</c>, <c>libvcruntime.lib</c>, <c>libcmt.lib</c>, <c>legacy_stdio_definitions.lib</c>, <c>kernel32.lib</c></description></item>
2482- // / </list>
2483- // / Add appropriate <c>/libpath:</c> entries (VC Tools, UCRT, WinSDK) if the libs aren’t in the working directory.
2484- // / </para>
2485- // / <para><b>argv[0] and flavor:</b> LLD uses either <c>AFlavor</c> or the tool name in <c>argv[0]</c> to select a driver. This
2486- // / wrapper guarantees a valid <c>argv[0]</c> when missing.</para>
2487- // / <para><b>Thread-safety:</b> Treat calls as serialized with respect to LLD. If you need concurrency,
2488- // / isolate each link in a separate process.</para>
2489- // / <para><b>Diagnostics:</b> This wrapper does not intercept stdout/stderr. LLD prints errors/warnings
2490- // / to the process streams. Use <c>/verbose</c> (COFF) or the equivalent flags for other drivers to
2491- // / diagnose missing libs/symbols and path issues.</para>
2492- // / </remarks>
2493- // /
2494- // / <example>
2495- // / <code lang="delphi">
2496- // / // COFF (dynamic CRT)
2497- // / var Can: Boolean; RC: Integer;
2498- // / RC := LLDLink([
2499- // / 'lld-link',
2500- // / '/nologo',
2501- // / '/subsystem:console',
2502- // / '/entry:mainCRTStartup',
2503- // / '/out:C:\temp\hello.exe',
2504- // / '/libpath:C:\VS\VC\Tools\MSVC\14.3x\lib\x64',
2505- // / '/libpath:C:\Windows Kits\10\Lib\10.0.x\um\x64',
2506- // / '/libpath:C:\Windows Kits\10\Lib\10.0.x\ucrt\x64',
2507- // / 'C:\temp\hello.obj',
2508- // / 'kernel32.lib','ucrt.lib','vcruntime.lib','legacy_stdio_definitions.lib',
2509- // / '/verbose'
2510- // / ], 'coff', Can);
2511- // / </code>
2512- // / </example>
2513- // /
2514- // / <example>
2515- // / <code lang="delphi">
2516- // / // COFF (static CRT, /MT)
2517- // / var Can: Boolean; RC: Integer;
2518- // / RC := LLDLink([
2519- // / 'lld-link','/nologo','/subsystem:console','/entry:mainCRTStartup',
2520- // / '/out:C:\temp\hello.exe','C:\temp\hello.obj',
2521- // / 'kernel32.lib','libucrt.lib','libvcruntime.lib','libcmt.lib','legacy_stdio_definitions.lib'
2522- // / ], 'coff', Can);
2523- // / </code>
2524- // / </example>
2525- // /
2526- // / <example>
2527- // / <code lang="delphi">
2528- // / // ELF
2529- // / var Can: Boolean; RC: Integer;
2530- // / RC := LLDLink(['ld.lld','-o','/tmp/hello','/tmp/hello.o','--fatal-warnings'], 'elf', Can);
2531- // / </code>
2532- // / </example>
2533- function LLDLink (const AArgs: array of string; const AFlavor: string; out ACanRunAgain: Boolean): Integer;
2429+ LLD_Link: function(argc: Integer; argv: PPUTF8Char; const flavor: PUTF8Char; canRunAgain: PInteger): Integer; cdecl;
25342430
25352431procedure GetExports (const aDLLHandle: THandle);
25362432
@@ -2539,6 +2435,7 @@ implementation
25392435procedure GetExports (const aDLLHandle: THandle);
25402436begin
25412437 if aDllHandle = 0 then Exit;
2438+ LLD_Link := GetProcAddress(aDLLHandle, ' LLD_Link' );
25422439 LLVMABIAlignmentOfType := GetProcAddress(aDLLHandle, ' LLVMABIAlignmentOfType' );
25432440 LLVMABISizeOfType := GetProcAddress(aDLLHandle, ' LLVMABISizeOfType' );
25442441 LLVMAddAlias2 := GetProcAddress(aDLLHandle, ' LLVMAddAlias2' );
@@ -3831,66 +3728,6 @@ procedure GetExports(const aDLLHandle: THandle);
38313728
38323729var
38333730 DepsDLLHandle: THandle = 0 ;
3834- LLD_Link: function(argc: Integer; argv: PPUTF8Char; const flavor: PUTF8Char; canRunAgain: PInteger): Integer; cdecl;
3835-
3836- function LLDLink (const AArgs: array of string; const AFlavor: string; out ACanRunAgain: Boolean): Integer;
3837- var
3838- LUTF8Args: TArray<UTF8String>;
3839- LArgv: TArray<PUTF8Char>;
3840- LFlavorUTF8: UTF8String;
3841- LCan: Integer;
3842- LIdx: Integer;
3843- LArg0: UTF8String;
3844- begin
3845- ACanRunAgain := False;
3846-
3847- if Length(AArgs) > 0 then
3848- begin
3849- // Allocate arrays: UTF8 strings for storage, pointers for argv
3850- SetLength(LUTF8Args, Length(AArgs));
3851- SetLength(LArgv, Length(AArgs) + 1 ); // +1 for null terminator
3852-
3853- // Convert each argument and store both string and pointer
3854- for LIdx := 0 to High(AArgs) do
3855- begin
3856- LUTF8Args[LIdx] := UTF8String(AArgs[LIdx]);
3857- LArgv[LIdx] := PUTF8Char(LUTF8Args[LIdx]);
3858- end ;
3859-
3860- // Null-terminate the argv array
3861- LArgv[High(LArgv)] := nil ;
3862- end
3863- else
3864- begin
3865- // Handle empty args case with default tool names
3866- if SameText(AFlavor, ' elf' ) then
3867- LArg0 := UTF8String(' ld.lld' )
3868- else if SameText(AFlavor, ' macho' ) or SameText(AFlavor, ' darwin' ) then
3869- LArg0 := UTF8String(' ld64.lld' )
3870- else if SameText(AFlavor, ' wasm' ) then
3871- LArg0 := UTF8String(' wasm-ld' )
3872- else
3873- LArg0 := UTF8String(' lld-link' );
3874-
3875- SetLength(LUTF8Args, 1 );
3876- SetLength(LArgv, 2 ); // 1 arg + null terminator
3877- LUTF8Args[0 ] := LArg0;
3878- LArgv[0 ] := PUTF8Char(LUTF8Args[0 ]);
3879- LArgv[1 ] := nil ; // Null terminator
3880- end ;
3881-
3882- // Convert flavor string
3883- if AFlavor <> ' ' then
3884- LFlavorUTF8 := UTF8String(AFlavor)
3885- else
3886- LFlavorUTF8 := UTF8String(' ' );
3887-
3888- LCan := 0 ;
3889-
3890- // Call with proper argc count (excludes null terminator)
3891- Result := LLD_Link(Length(LUTF8Args), @LArgv[0 ], PUTF8Char(LFlavorUTF8), @LCan);
3892- ACanRunAgain := LCan <> 0 ;
3893- end ;
38943731
38953732procedure LoadDLL ();
38963733var
@@ -3922,7 +3759,6 @@ procedure LoadDLL();
39223759 LResStream.Free();
39233760 end ;
39243761 GetExports(DepsDLLHandle);
3925- LLD_Link := GetProcAddress(DepsDLLHandle, ' LLD_Link' );
39263762end ;
39273763
39283764procedure UnloadDLL ();
0 commit comments