FPC 3.2.2 + NASM Windows 64-Bit Pro + how to: create DLL and EXE of .o files ? lazarus / 21-General ---------------------------------------------------------------------- paule32 · 2025-05-10 14:27 Now, I have .s and .o Files in the File System. .s was created by FPC .o was created by ppas.bat with nasm.exe ppas.bat runs without errors. How can I create a DLL or EXE with the .o files ? because, I have some .a Files, too, and I don't know what to do with. ---------------------------------------------------------------------- paule32 · 2025-05-10 15:14 Now, I get the following Output by gcc.exe: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i C:\fpcupdeluxe\fpc\bin\x86_64-win64\gcc -nostdlib -o test.exe  xmm.o system.o windows.o  ^global.o locales.o  exceptions.o QApplicationPascal.o rtllibimport.o sysutils.o strutils.o sysinitpas.o ^rtlunit.o rtllib.o QObjectPascalexport.o dialogs.o ^-L.\ -limpwindows -lrtllib_dll -limpsystem -limpDialogs -limpQApplicationPascal -limplocales -limprtllibimport ^-limprtlunit -limpstrutils -limpsysutils -limpexceptions -limpsystem -limpgloballd: error: 0-bit reloc in dllld: error: 0-bit reloc in dllld: error: 0-bit reloc in dllld: error: 0-bit reloc in dllld: error: 0-bit reloc in dllld: error: 0-bit reloc in dllld: error: 0-bit reloc in dllld: xmm.o:xmm.s:(.text+0x3d1): undefined reference to `_$dll$ntdll$RtlCompareMemory'ld: xmm.o:xmm.s:(.text+0x3e6): undefined reference to `_$dll$ntdll$RtlCompareMemory'ld: xmm.o:xmm.s:(.text+0x4a5): undefined reference to `_$dll$kernel32$RtlFillMemory' ---------------------------------------------------------------------- marcov · 2025-05-10 19:04 gcc in the FPC/Lazarus distribution is an empty stub for preprocessing resource files only (and hopefully one of these days that won't even be necessary anymore) ---------------------------------------------------------------------- paule32 · 2025-05-11 10:00 okay. After compile a pas files to .s files with -fPIC Option, I could create DLL and EXE. But, I don't want to use gcc or ld to link .o files. When I drop the command on the CLI: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -otest.exe test.o I get the message: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i test.o(1,2) Fatal: Syntax error, "BEGIN" expected but "identifier D" foundFatal: Compilation aborted So, how can I create a EXE from .o File per FPC ? ---------------------------------------------------------------------- PascalDragon · 2025-05-11 13:42 Quote from: paule32 on May 11, 2025, 12:00:51 pmSo, how can I create a EXE from .o File per FPC ? For FPC at least the main project needs to be Pascal source. Other object files can then be added using {$L objfile.o}. Anything else is not supported and you must use manual linking using the link script instead. ---------------------------------------------------------------------- paule32 · 2025-05-11 13:51 I use this command: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -dDLLEXPORT -dLANGDEU -Cn -a -al -Anasmwin64 -sh test_unit.pas this will create a .S File. I did then Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i dir *.resdir *.ld but with no results. Then I tried the following: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -dDLLEXPORT -dLANGDEU -Cn -a -al -Anasmwin64 -sh test_unit.pasnasm.exe -f win64 -o test_unit.o -w-orphan-labels  test_unit.sfpc -dDLLIMPORT -dLANGDEU -n -B -O3 -Os test.pas with this code (test.pas): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test;{$L test_unit.o} begin  PASCALMAIN;end. and this (test_unit.pas): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit test_unit;interfaceprocedure PASCALMAIN;implementationprocedure PASCALMAIN;begin{ some code }end;end. The Message comes then: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc.exe -dDLLIMPORT -dLANGDEU -n -B -O3 -Os test.pastest.pas(10,3) Error: Identifier not found "PASCALMAIN"test.pas(12) Fatal: There were 1 errors compiling module, stoppingFatal: Compilation abortedError: C:\fpcupdeluxe\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode ---------------------------------------------------------------------- PascalDragon · 2025-05-11 14:17 You need to make the PASCALMAIN identifier known to the parser: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure PASCALMAIN; external name 'PASCALMAIN'; (though you'll likely need to use the proper mangled name for your PASCALMAIN unless you provide a public alias) ---------------------------------------------------------------------- paule32 · 2025-05-11 14:37 Thank you. It works. But I get this errors: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i test.pas(18,1) Error: Undefined symbol: STRUTILS_::=::\_STRINGREPLACE$ ANSISTRING$ANSISTRING$ANSISTRING$TREPLACEFLAGS::=::\ANSISTRINGtest.pas (18,1) Error: Undefined symbol: DIALOGS_::=::\_SHOWMESSAGE$PCHARtest.pas(18,1) Fatal: There were 2 errors compiling module, stopping ---------------------------------------------------------------------- PascalDragon · 2025-05-11 14:40 Quote from: paule32 on May 11, 2025, 04:37:18 pmBut I get this errors: Then some of your code uses these functions. You need to make sure that the corresponding object files are linked in as well. That's why you shouldn't try to do such nonsense, because you're basically reinventing what the compiler already does for you. ---------------------------------------------------------------------- paule32 · 2025-05-11 14:50 okay. I get it. Thank you for your help. I add this Code to the test_unit.pas: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string; external RTLDLL;procedure ShowMessage(msg: PChar); stdcall; external RTLDLL; but I used the Code again in my StrUtils.pas: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit test_unit;interfaceuses  Windows, Dialogs, StrUtils; procedure PASCALMAIN implementation function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string; external RTLDLL;procedure ShowMessage(msg: PChar); stdcall; external RTLDLL; procedure PASCALMAIN;begin{ some code }end; end. But I have already Code for in StrUtils.pas: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit StrUtils;interface {$ifdef DLLEXPORT}function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string; stdcall; export;{$endif DLLEXPORT} {$ifdef DLLIMPORT}function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string; external RTLDLL;{$endif DLLIMPORT} implementation...end. And I compile with: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -dDLLEXPORT -dLANGDEU -Cn -a -al -Anasmwin64 -sh test_unit.pasnasm.exe -f win64 -o test_unit.o -w-orphan-labels  test_unit.sfpc -dDLLIMPORT -dLANGDEU -n -B -O3 -Os test.pas something magican goes on there - I don't know why ?  :'( ---------------------------------------------------------------------- paule32 · 2025-05-11 18:19 when I use the Code below: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test;{$L test_unit.o} uses  Windows, Dialogs, SysUtils, StrUtils, Exceptions,  Locales, global,  RtlLibImport, QApplicationPascal; procedure PASCALMAINE; external name 'PASCALMAINE'; begin  PASCALMAINE;end. I get: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -dDLLIMPORT -dLANGDEU -n -B -O3 -Os test.pastest.pas(18,1) Error: Undefined symbol: PASCALMAINEtest.pas(18,1) Fatal: There were 1 errors compiling module, stoppingFatal: Compilation abortedError: C:\fpcupdeluxe\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode But when I use: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test;{$L test_unit.o} uses  Windows, Dialogs, SysUtils, StrUtils, Exceptions,  Locales, global,  RtlLibImport, QApplicationPascal; procedure PASCALMAIN; external name 'PASCALMAIN'; begin  PASCALMAIN;end. The Compilation works. ---------------------------------------------------------------------- munair · 2025-05-11 22:42 When using mixed languages like FPC and NASM to compile into one program, you really should know what you're doing. Obviously, when you get errors like UNDEFINED SYMBOL and you don't know why, then you don't know what you're doing. And what's wrong with LD? I use NASM+LD all the time and it works great linking multiple object files. ---------------------------------------------------------------------- paule32 · 2025-05-12 06:19 the Problem is not understanding asm + nasm + ld. the Problem is, what FPC does internally with the magic things like compilerproc or mangked names. I wrote: - when using PASCALMAIN, all is okay - when using PASCALMAINE, the Problems pop out so, my conclution is, that magic things goes on there. ---------------------------------------------------------------------- paule32 · 2025-05-12 10:27 okay. I solved the Problem. The Problem was on me, that I don't assemble the .pas and .s file. All okay. ---------------------------------------------------------------------- paule32 · 2025-05-13 10:52 @munair how do you doing NASM + LD ? what is the command line ? what do you link (.o and .a files) ? ---------------------------------------------------------------------- paule32 · 2025-05-13 11:53 now, no error pointed to multiple or undefined references by using ld.exe But I get a very long list of: ld: error: 0-bit reloc in dll ... under the Windows Console. I fpc compile with -fPIC ---------------------------------------------------------------------- munair · 2025-05-13 21:49 Quote from: paule32 on May 13, 2025, 12:52:57 pm@munair how do you doing NASM + LD ? what is the command line ? what do you link (.o and .a files) ? I use it to compile the SharpBASIC runtime library and compiler, e.g. i386 code: Code: FreeBasic  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ' assembleprint "assembling: " + afile.pathbuf = "nasm -f elf32 " + afile.path  ' + " -Ox" ' optimizationprint bufshell buf ' linkprint "linking: " + afile.specbuf = "ld -m elf_i386 " + afile.spec + ".o " + "lib/sys.o " + "lib/io.o " + "-o " + afile.specprint bufshell buf  There is plenty online documentation for nasm and ld. I suggest you look it up for your specific needs. ---------------------------------------------------------------------- paule32 · 2025-05-14 13:18 thanks for the replies. I get it working... But an other Question about linking: The CLI command option -B can be used, to force a compile run to compile all Pascal Files and Resource Files. So, when I not use the -B Option explicit, the .s and .o bject Files will be not touched again in a new compile - only if they modified and/or the date is different from the source File (like Makefile's works) ? ---------------------------------------------------------------------- marcov · 2025-05-14 14:25 Quote from: paule32 on May 14, 2025, 03:18:18 pmthanks for the replies. I get it working... But an other Question about linking: The CLI command option -B can be used, to force a compile run to compile all Pascal Files and Resource Files. So, when I not use the -B Option explicit, the .s and .o bject Files will be not touched again in a new compile - only if they modified and/or the date is different from the source File (like Makefile's works) ? No. The recompilation is based on the ppu and sources I think, not the .o or .s ---------------------------------------------------------------------- paule32 · 2025-05-14 14:46 okay, indeed. FPC seems to work with a checksum hash for each compiled unit (.ppu and .o). But, when I compile with: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -dDLLEXPORT -dLANGDEU -n -B -O3 -Os -fPIC -CD RTLLib.pasI get a working DLL But, when I compile with: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -dDLLIMPORT -dLANGDEU -n -B -O3 -Os test.pasI get a working EXE which can call the Functions out of the DLL above. But. when I link with existing .o files: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ld --disable-runtime-pseudo-reloc -nostdlib --allow-shlib-undefined ^-Map test.map --gc-sections -o test2.exe -T link.ldI get only many error's in the style of: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ld: error: 0-bit reloc in dllld: error: 0-bit reloc in dllld: error: 0-bit reloc in dll...by using this link.ld script: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SEARCH_DIR( ".")INPUT(RTLLib.osystem.oxmm.owindows.oglobal.oRTLunit.odialogs.osysu tils.ostrutils.oexceptions.olocales.osysinitpas.o)GROUP(libimpsystem.a libimpxmm.alibimpwindows.alibimpRTLunit.alibimpsysutils.alibimpexcepti ons.a)OUTPUT_FORMAT(pei-x86-64)ENTRY(PASCALMAIN)SECTIONS{  . = SIZEOF_HEADERS;  . = ALIGN(__section_alignment__);  .text  __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :  {    __text_start__ = . ;    *(.init)    *(.text .stub .text.* .gnu.linkonce.t.*)    *(SORT(.text$*))    *(.glue_7t)    *(.glue_7)    . = ALIGN(8);     ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;    LONG (-1);    LONG (-1);    *(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0);    LONG (0);     ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;    LONG (-1);    LONG (-1);  *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0);    LONG (0);     *(.fini)    PROVIDE (etext = .);    *(.gcc_except_table)  }  .data BLOCK(__section_alignment__) :  {    __data_start__ = . ;    *(.data .data.* .gnu.linkonce.d.* .fpc*)    *(.data2)    *(SORT(.data$*))    *(.jcr)    PROVIDE (_tls_index = .);    LONG (0);    __data_end__ = . ;    *(.data_cygwin_nocopy)  }  .rdata BLOCK(__section_alignment__) :  {    *(.rdata)    *(.rdata.*)    *(.rodata .rodata.* .gnu.linkonce.r.*)    *(SORT(.rdata$*))    *(.eh_frame)    ___RUNTIME_PSEUDO_RELOC_LIST__ = .;    __RUNTIME_PSEUDO_RELOC_LIST__ = .;    *(.rdata_runtime_pseudo_reloc)    ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;    __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;  }  .pdata BLOCK(__section_alignment__) : { *(.pdata) }  .bss BLOCK(__section_alignment__) :  {    __bss_start__ = . ;    *(.bss .bss.* .gnu.linkonce.b.*)    *(SORT(.bss$*))    *(COMMON)    __bss_end__ = . ;  }  .edata BLOCK(__section_alignment__) : { *(.edata) }  .idata BLOCK(__section_alignment__) :  {    SORT(*)(.idata$2)    SORT(*)(.idata$3)    /* These zeroes mark the end of the import list.  */    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);    SORT(*)(.idata$4)    SORT(*)(.idata$5)    SORT(*)(.idata$6)    SORT(*)(.idata$7)  }  .CRT BLOCK(__section_alignment__) :  {    ___crt_xc_start__ = . ;    *(SORT(.CRT$XC*))  /* C initialization */    ___crt_xc_end__ = . ;    ___crt_xi_start__ = . ;    *(SORT(.CRT$XI*))  /* C++ initialization */    ___crt_xi_end__ = . ;    ___crt_xl_start__ = . ;    *(SORT(.CRT$XL*))  /* TLS callbacks */    /* ___crt_xl_end__ is defined in the TLS Directory support code */    PROVIDE (___crt_xl_end__ = .);    ___crt_xp_start__ = . ;    *(SORT(.CRT$XP*))  /* Pre-termination */    ___crt_xp_end__ = . ;    ___crt_xt_start__ = . ;    *(SORT(.CRT$XT*))  /* Termination */    ___crt_xt_end__ = . ;  }  .tls BLOCK(__section_alignment__) :  {    ___tls_start__ = . ;    *(.tls .tls.*)    *(.tls$)    *(SORT(.tls$*))    ___tls_end__ = . ;  }  .rsrc BLOCK(__section_alignment__) :  {    *(.rsrc)    *(SORT(.rsrc$*))  }  .reloc BLOCK(__section_alignment__) : { *(.reloc) }  .stab BLOCK(__section_alignment__) (NOLOAD) : { *(.stab) }  .stabstr BLOCK(__section_alignment__) (NOLOAD) : { *(.stabstr) }} No DLL or EXE with the last LD step isn't produced. ---------------------------------------------------------------------- marcov · 2025-05-14 17:39 The Windows version of LD has a lot of limitations, and in general it is NOT used.  We stuck with the last versions before the msys introduction, which means that is probably a 2005(!) version. The increased use of the internal linker since 2007-2008 and finally the deprecation of the final usage, the textmode IDE with mingw GDB integrated in 2020. In short, the disassociation of FPC windows targets from mingw/msys is nearly complete, and by sticking with it, you are entering unknown territory. You could try newer LD's, but YMMV. The last linker I tested must have been somewhere in 2009 when I changed from cygwin to mingw and created the helper tools page ---------------------------------------------------------------------- paule32 · 2025-05-15 06:25 for versioning is proberly not the Problem: as --version GNU assembler (GNU Binutils) 2.42 Copyright (C) 2024 Free Software Foundation, Inc. ld --version GNU ld (GNU Binutils) 2.42 Copyright (C) 2024 Free Software Foundation, Inc. gcc --version gcc.exe (Rev3, Built by MSYS2 project) 14.1.0 Copyright (C) 2024 Free Software Foundation, Inc. ---------------------------------------------------------------------- munair · 2025-05-15 08:05 The ld man page (e.g., on man7.org or manpages.ubuntu.com) offers a concise reference for command-line options and basic usage. The OSDev Wiki provides insights into linker scripts for operating system development, particularly relevant for custom binary layouts. Blogs like "The most thoroughly commented linker script" by Thea Flowers offer practical, annotated examples of linker scripts for embedded systems. The LLVM project's lld documentation compares ld with alternatives, providing context on its features. https://lld.llvm.org/ Run ld --help or man ld on a system with Binutils installed for quick reference. Use ld --verbose to display the default linker script for your system, which is useful for understanding platform-specific behavior. https://mcyoung.xyz/2021/06/01/linker-script/ The GNU linker (ld) is primarily designed for Unix-like systems but can be used on Windows with some considerations. Its suitability depends on your use case, as it has both strengths and limitations in a Windows environment: + Cross-Platform Availability: ld is included in toolchains like MinGW (Minimalist GNU for Windows) and MSYS2, which provide GNU Binutils for Windows. These environments allow ld to link object files into executables or libraries compatible with Windows. For example, MinGW uses ld to produce PE/COFF binaries, the native Windows executable format. + Cross-Compilation: ld is widely used for cross-compiling Windows binaries from Linux or other platforms. For instance, you can configure ld with a Windows target (e.g., i686-w64-mingw32-ld) to generate Windows executables. This is common in embedded development or open-source projects. + Support for Windows-Specific Formats: ld supports the PE/COFF format (used for Windows .exe and .dll files) through the BFD (Binary File Descriptor) libraries. It can handle Windows-specific features like DLL imports/exports and debug information, though with some quirks. + Linker Scripts for Customization: ld's linker script language allows fine-grained control over binary layout, which is useful for specialized Windows applications (e.g., embedded systems or custom loaders). + Integration with GCC: When used with gcc on Windows (via MinGW or MSYS2), ld is invoked indirectly through the compiler driver, simplifying the linking process for C/C++ programs. - Native Windows Toolchain Preference: Windows typically uses Microsoft’s linker (link.exe), part of the Visual Studio toolchain, which is optimized for the Windows ecosystem. ld is less common in native Windows development and may not integrate as seamlessly with Windows-specific tools like MSVC. - PE/COFF Support Quirks: While ld supports PE/COFF, its implementation is not as robust as Microsoft’s linker for certain Windows-specific features. For example: DLL Handling: ld can struggle with complex DLL scenarios, such as auto-importing data symbols, leading to errors like "variable '' can't be auto-imported." The --enable-auto-import option helps but may not resolve all issues. Debug Information: ld supports Windows debug info (PDB) but may produce non-standard output when using long section names for Dwarf-2 debug info, which can confuse non-GNU tools. Performance: For large Windows projects, ld may be slower than Microsoft’s linker or LLVM’s lld, which is optimized for PE/COFF. - Environment Setup: Using ld on Windows requires setting up a Unix-like environment (e.g., MSYS2, Cygwin, or WSL), which adds complexity compared to native Windows tools. Cygwin, for instance, introduces a dependency on its runtime (cygwin1.dll), which may not be desirable for standalone Windows applications. -> Alternative Linkers: LLVM’s lld is a drop-in replacement for ld and offers better performance and native PE/COFF support on Windows. It’s often recommended over ld for Windows development due to its speed (more than twice as fast as GNU gold in some cases) and compatibility with Windows debug info. Microsoft’s link.exe is the standard for Windows-native development, especially for projects using MSVC or Windows SDKs. - Dynamic Linking Challenges: Windows’ dynamic linking model (DLLs) differs from Unix’s shared libraries (.so). ld handles DLLs but may require additional configuration (e.g., --dll-search-prefix or --enable-stdcall-fixup) to resolve symbol mismatches or calling convention issues. For most Windows projects, consider alternatives like LLVM’s lld or Microsoft’s link.exe unless ld’s specific features (e.g., linker scripts) are required. I hope this helps. ---------------------------------------------------------------------- marcov · 2025-05-15 08:15 munair: sounds like a low grade AI summary. ---------------------------------------------------------------------- munair · 2025-05-15 08:23 Quote from: marcov on May 15, 2025, 10:15:15 ammunair: sounds like a low grade AI summary. These are basic considerations when choosing LD on Windows. ---------------------------------------------------------------------- marcov · 2025-05-15 08:59 Quote from: munair on May 15, 2025, 10:23:04 amQuote from: marcov on May 15, 2025, 10:15:15 ammunair: sounds like a low grade AI summary. These are basic considerations when choosing LD on Windows. I can't imagine recommending LLD over LD.  LLD basically has no error handling, and simply silently generates defunct binaries. And since this is the FPC channel, it must work with FPC generated object files (which are generated by FPC directly), and a dll generated by the internal linker.  The FPC internal parts replaced an AS/AR/LD combo, so the formats and style it generates are close to it (like COFF, and not OMF). I don't know the commercial linkers that well, but that might be a problem.  . As for Paule32: you might want try to use a development version of FPC and see if that contains fixes to the object writer/internal linker. ---------------------------------------------------------------------- munair · 2025-05-15 09:26 Quote from: marcov on May 15, 2025, 10:59:20 amI can't imagine recommending LLD over LD.  LLD basically has no error handling, and simply silently generates defunct binaries. LLD has matured over the years and according to development status is used to link production builds such as Chromium and Firefox. https://lld.llvm.org/windows_support.html It might be a better choice than LD. However, it remains tricky what the OP tries to do and I agree with PascalDragon. ---------------------------------------------------------------------- marcov · 2025-05-15 11:01 Quote from: munair on May 15, 2025, 11:26:30 amQuote from: marcov on May 15, 2025, 10:59:20 amI can't imagine recommending LLD over LD.  LLD basically has no error handling, and simply silently generates defunct binaries. LLD has matured over the years and according to development status is used to link production builds such as Chromium and Firefox. That is the problem. LLD is only verified as far as clang uses it. We are talking here about blending object files from various sources. That is not the same kind of usage, and errorhandling for unsupported features are important. My experiences were afaik with LLVM 14 on FreeBSD 14. ---------------------------------------------------------------------- paule32 · 2025-05-15 11:17 now, I get 7 reloc errors. A step wider because before the count was over 20 reloc error's. Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ld --shared --disable-runtime-pseudo-reloc -nostdlib --allow-shlib-undefined -Map test.map --image-base=0x409000 -o test2.dll -T link.ldT:\msys64\mingw64\bin\ld.exe: error: 0-bit reloc in dllT:\msys64\mingw64\bin\ld.exe: error: 0-bit reloc in dllT:\msys64\mingw64\bin\ld.exe: error: 0-bit reloc in dllT:\msys64\mingw64\bin\ld.exe: error: 0-bit reloc in dllT:\msys64\mingw64\bin\ld.exe: error: 0-bit reloc in dllT:\msys64\mingw64\bin\ld.exe: error: 0-bit reloc in dllT:\msys64\mingw64\bin\ld.exe: error: 0-bit reloc in dll ---------------------------------------------------------------------- paule32 · 2025-05-15 11:52 okay... I am nearly the Goal... with: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -dDLLEXPORT -dLANGDEU -n -B -O3 -Os -CD RTLLib.pasdlltool --input-def rtllib_dll.def --dllname rtllib.dll --output-lib librtllib_dll.afpc -dDLLIMPORT -dLANGDEU -n -B -O3 -Os test.passtrip test.exestrip rtllib.dll fpc -dDLLEXPORT -dLANGDEU -dCPU64 -n -B -O3 -Xe -Os -Cg -a -al -Anasmwin64 test.pasnasm.exe -f win64 -o test.o -w-orphan-labels test.s ld -nostdlib -Map test.map -o test2.exe -T link.ldI get a working executable. ---------------------------------------------------------------------- paule32 · 2025-05-15 15:08 now, I can create exe + dll in two ways. the magic option was a linker script + --shared by a second run. - The first run with -B (to force an "all compile") - The second run to sed not used stuff, and assembly the .s Files: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i @echo offfpc -dDLLEXPORT -dLANGDEU -n -B -O3 -Os -CD RTLLib.pasdlltool --input-def rtllib_dll.def --dllname rtllib.dll --output-lib librtllib_dll.afpc -dDLLIMPORT -dLANGDEU -n -B -O3 -Os test.pascp test.exe test1.exestrip test1.exestrip rtllib.dll set "filelist=test"for %%f in (%filelist%) do (    echo "fpc : %%f.pas -> %%f.s"    fpc -dDLLEXPORT -dLANGDEU -dCPU64 -n -B -O3 -Xe -Os -Cg -a -al -Anasmwin64 %%f.pas    echo ---)for %%f in (%filelist%) do (    echo "sed : %%f.s (debug)"    sed -i '/; Begin asmlist al_dwarf_frame/,/; End asmlist al_dwarf_frame/d' %%f.s    echo "sed : %%f.s (line )"    sed -i '/^%%LINE/d' %%f.s    echo "nasm: %%f.s  -> %%f.o"    nasm.exe -f win64 -o "%%f.o" -w-orphan-labels "%%f.s"    echo ---) ld -nostdlib -Map test.map -o test3.exe -T link.ldstrip test3.exe ld --shared -nostdlib -Map test.map -o test3.dll -T link.ld:end ---------------------------------------------------------------------- paule32 · 2025-05-16 05:27 a new Problem: when I compile a new project with the following line: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -dDLLEXPORT -dLANGDEU -n -B -O2 -Os -CD -Cg -a -al -Aas -st RTLLib.pasI get gnu as sembler Files (.s) The Option -st create a RTLLib_ppas.bat: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i @echo offSET THEFILE=xmmecho Assembling %THEFILE%as.exe --64 -o xmm.o   xmm.sif errorlevel 1 goto asmendSET THEFILE=systemecho Assembling %THEFILE%as.exe --64 -o system.o   system.sif errorlevel 1 goto asmendSET THEFILE=globalecho Assembling %THEFILE%as.exe --64 -o global.o   global.sif errorlevel 1 goto asmendSET THEFILE=windowsecho Assembling %THEFILE%as.exe --64 -o windows.o   windows.sif errorlevel 1 goto asmendSET THEFILE=exceptionsecho Assembling %THEFILE%as.exe --64 -o exceptions.o   exceptions.sif errorlevel 1 goto asmendSET THEFILE=localesecho Assembling %THEFILE%as.exe --64 -o Locales.o   Locales.sif errorlevel 1 goto asmendSET THEFILE=sysutilsecho Assembling %THEFILE%as.exe --64 -o SysUtils.o   SysUtils.sif errorlevel 1 goto asmendSET THEFILE=qapplicationpascalecho Assembling %THEFILE%as.exe --64 -o QApplicationPascal.o   QApplicationPascal.sif errorlevel 1 goto asmendSET THEFILE=rtlunitecho Assembling %THEFILE%as.exe --64 -o RTLUnit.o   RTLUnit.sif errorlevel 1 goto asmendSET THEFILE=sysinitpasecho Assembling %THEFILE%as.exe --64 -o sysinitpas.o   sysinitpas.sif errorlevel 1 goto asmendSET THEFILE=rtllibecho Assembling %THEFILE%as.exe --64 -o RTLLib.o   RTLLib.sif errorlevel 1 goto asmendSET THEFILE=RTLLib.dllecho Linking %THEFILE%ld.exe -b pei-x86-64  --gc-sections  -s --dll  --entry _DLLMainCRTStartup   --base-file base.$$$ -o RTLLib.dll RTLLib_link.resif errorlevel 1 goto linkenddlltool.exe -S as.exe -D RTLLib.dll -e exp.$$$ --base-file base.$$$ if errorlevel 1 goto linkendld.exe -b pei-x86-64  -s --dll  --entry _DLLMainCRTStartup   -o RTLLib.dll RTLLib_link.res exp.$$$if errorlevel 1 goto linkendgoto end:asmendecho An error occurred while assembling %THEFILE%goto end:linkendecho An error occurred while linking %THEFILE%:endI get Error: ld.exe: warning: RTLLib_link.res contains output sections; did you forget -T? ld.exe: section .text LMA [0000000180001000,000000018000101f] overlaps section .text LMA 0000000180001000,0000000180006abf] An error occurred while linking RTLLib.dll when I use: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i echo Linking %THEFILE%ld.exe -b pei-x86-64  --gc-sections  -s --dll  --entry _DLLMainCRTStartup   --base-file base.$$$ -o RTLLib.dll -T RTLLib_link.resif errorlevel 1 goto linkenddlltool.exe -S as.exe -D RTLLib.dll -e exp.$$$ --base-file base.$$$ if errorlevel 1 goto linkendld.exe -b pei-x86-64  -s --dll  --entry _DLLMainCRTStartup   -o RTLLib.dll -T RTLLib_link.res exp.$$$if errorlevel 1 goto linkendgoto endI stuck into: RTLLib_ppas.bat Assembling xmm Assembling system Assembling global Assembling windows Assembling exceptions Assembling locales Assembling sysutils Assembling qapplicationpascal Assembling rtlunit Assembling sysinitpas Assembling rtllib Linking RTLLib.dll exceptions.o:exceptions.pas (.xdata.n_exceptions_$$_translate_windows_error$longint$$ansistring+0x 14): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32NB against symbol `__FPC_specific_handler' defined in *UND* section in ld.exe generated exceptions.o:exceptions.pas:(.xdata.n_exceptions$_$exception_$__$$_cre ate$ansistring$longint$$exception+0x8): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32NB against symbol `__FPC_specific_handler' defined in *UND* section in ld.exe generated RTLUnit.o:RTLUnit.pas:(.xdata.n_rtlunit$_$twidgetset_$__$$_create$$twi dgetset+0x8): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32NB against symbol `__FPC_specific_handler' defined in *UND* section in ld.exe generated RTLUnit.o:RTLUnit.pas: (.xdata.n_rtlunit$_$trtl_$__$$_create$$trtl+0x8): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32NB against symbol `__FPC_specific_handler' defined in *UND* section in ld.exe generated QApplicationPascal.o:QApplicationPascal.pas:(.xdata.n_qapplicationpasc al$_$tapplication_$__$$_create$$tapplication+0xc): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32NB against symbol `__FPC_specific_handler' defined in *UND* section in ld.exe generated QApplicationPascal.o:QApplicationPascal.pas:(.xdata.n_qapplicationpasc al$_$tapplication_$__$$_create$longint$ppchar$$tapplication+0x8): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32NB against symbol `__FPC_specific_handler' defined in *UND* section in ld.exe generated An error occurred while linking RTLLib.dll ---------------------------------------------------------------------- munair · 2025-05-16 07:23 I think you should stop this madness. ---------------------------------------------------------------------- paule32 · 2025-05-16 13:29 now, I compile with 3.3.1 stable thrunk: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -n -us -dDLLEXPORT -dLANGDEU -Px86_64 -Twin64 -B -O2 -Os -CD -Cg -a -al -Aas -st RTLLib.pas::---- fpc -n -us -dDLLEXPORT -XX -CX -Xs -B -al -O2 -Twin64 -Px86_64 ^  -oRTLLib.dll  ^  -k-Trtlld ^  -k--dll ^  -k-eDllEntryPoint ^  RTLLib.pas strip rtllib.dll fpc -n -us -dDLLEXPORT -dDLANGDEU -O2 -Os -Cg -a -al -Aas -st main.pasdir main*.*as.exe --64 -o main.o main.s fpc -n -us -dDLLIMPORT -O2 -Xi test.pas and get this output: fpc -n -us -dDLLEXPORT -dLANGDEU -Px86_64 -Twin64 -B -O2 -Os -CD -Cg -a -al -Aas -st RTLLib.pas RTLLib.pas(7,16) Fatal: Internal error 2006012304 Fatal: Compilation aborted Error: C:\FPC\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode T:\a>fpc -n -us -dDLLEXPORT -XX -CX -Xs -B -al -O2 -Twin64 -Px86_64   -oRTLLib.dll    -k-Trtlld   -k--dll   -k-eDllEntryPoint   RTLLib.pas RTLLib.pas(7,16) Fatal: Internal error 2006012304 Fatal: Compilation aborted Error: C:\FPC\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode T:\a>strip rtllib.dll T:\a>fpc -n -us -dDLLEXPORT -dDLANGDEU -O2 -Os -Cg -a -al -Aas -st main.pas main.pas(4,10) Fatal: Internal error 2006012304 Fatal: Compilation aborted Error: C:\FPC\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode T:\a>dir main*.*  Datenträger in Laufwerk T: ist Volume  Volumeseriennummer: 76E3-B1D8  Verzeichnis von T:\a 16.05.2025  15:10             2.199 main.o 16.05.2025  12:02               328 main.pas 16.05.2025  12:00               301 main.pas.bak 16.05.2025  13:59             1.146 main.ppu 16.05.2025  13:59             2.492 main.s 16.05.2025  13:59               364 main_ppas.bat                6 Datei(en),          6.830 Bytes                0 Verzeichnis(se), 450.954.182.656 Bytes frei T:\a>as.exe --64 -o main.o main.s T:\a>fpc -n -us -dDLLIMPORT -O2 -Xi test.pas test.pas(4,14) Fatal: Internal error 2006012304 Fatal: Compilation aborted Error: C:\FPC\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode[/code]