Recent

Author Topic: FPC 3.2.2 + NASM Windows 64-Bit Pro + how to: create DLL and EXE of .o files ?  (Read 2459 times)

paule32

  • Hero Member
  • *****
  • Posts: 516
  • One in all. But, not all in one.
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][+][-]
  1. @echo off
  2. fpc -dDLLEXPORT -dLANGDEU -n -B -O3 -Os -CD RTLLib.pas
  3. dlltool --input-def rtllib_dll.def --dllname rtllib.dll --output-lib librtllib_dll.a
  4. fpc -dDLLIMPORT -dLANGDEU -n -B -O3 -Os test.pas
  5. cp test.exe test1.exe
  6. strip test1.exe
  7. strip rtllib.dll
  8.  
  9. set "filelist=test"
  10. for %%f in (%filelist%) do (
  11.     echo "fpc : %%f.pas -> %%f.s"
  12.     fpc -dDLLEXPORT -dLANGDEU -dCPU64 -n -B -O3 -Xe -Os -Cg -a -al -Anasmwin64 %%f.pas
  13.     echo ---
  14. )
  15. for %%f in (%filelist%) do (
  16.     echo "sed : %%f.s (debug)"
  17.     sed -i '/; Begin asmlist al_dwarf_frame/,/; End asmlist al_dwarf_frame/d' %%f.s
  18.     echo "sed : %%f.s (line )"
  19.     sed -i '/^%%LINE/d' %%f.s
  20.     echo "nasm: %%f.s  -> %%f.o"
  21.     nasm.exe -f win64 -o "%%f.o" -w-orphan-labels "%%f.s"
  22.     echo ---
  23. )
  24.  
  25. ld -nostdlib -Map test.map -o test3.exe -T link.ld
  26. strip test3.exe
  27.  
  28. ld --shared -nostdlib -Map test.map -o test3.dll -T link.ld
  29. :end
  30.  
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

paule32

  • Hero Member
  • *****
  • Posts: 516
  • One in all. But, not all in one.
a new Problem:

when I compile a new project with the following line:
Code: Bash  [Select][+][-]
  1. fpc -dDLLEXPORT -dLANGDEU -n -B -O2 -Os -CD -Cg -a -al -Aas -st RTLLib.pas
I get gnu as sembler Files (.s)
The Option -st create a RTLLib_ppas.bat:
Code: Bash  [Select][+][-]
  1. @echo off
  2. SET THEFILE=xmm
  3. echo Assembling %THEFILE%
  4. as.exe --64 -o xmm.o   xmm.s
  5. if errorlevel 1 goto asmend
  6. SET THEFILE=system
  7. echo Assembling %THEFILE%
  8. as.exe --64 -o system.o   system.s
  9. if errorlevel 1 goto asmend
  10. SET THEFILE=global
  11. echo Assembling %THEFILE%
  12. as.exe --64 -o global.o   global.s
  13. if errorlevel 1 goto asmend
  14. SET THEFILE=windows
  15. echo Assembling %THEFILE%
  16. as.exe --64 -o windows.o   windows.s
  17. if errorlevel 1 goto asmend
  18. SET THEFILE=exceptions
  19. echo Assembling %THEFILE%
  20. as.exe --64 -o exceptions.o   exceptions.s
  21. if errorlevel 1 goto asmend
  22. SET THEFILE=locales
  23. echo Assembling %THEFILE%
  24. as.exe --64 -o Locales.o   Locales.s
  25. if errorlevel 1 goto asmend
  26. SET THEFILE=sysutils
  27. echo Assembling %THEFILE%
  28. as.exe --64 -o SysUtils.o   SysUtils.s
  29. if errorlevel 1 goto asmend
  30. SET THEFILE=qapplicationpascal
  31. echo Assembling %THEFILE%
  32. as.exe --64 -o QApplicationPascal.o   QApplicationPascal.s
  33. if errorlevel 1 goto asmend
  34. SET THEFILE=rtlunit
  35. echo Assembling %THEFILE%
  36. as.exe --64 -o RTLUnit.o   RTLUnit.s
  37. if errorlevel 1 goto asmend
  38. SET THEFILE=sysinitpas
  39. echo Assembling %THEFILE%
  40. as.exe --64 -o sysinitpas.o   sysinitpas.s
  41. if errorlevel 1 goto asmend
  42. SET THEFILE=rtllib
  43. echo Assembling %THEFILE%
  44. as.exe --64 -o RTLLib.o   RTLLib.s
  45. if errorlevel 1 goto asmend
  46. SET THEFILE=RTLLib.dll
  47. echo Linking %THEFILE%
  48. ld.exe -b pei-x86-64  --gc-sections  -s --dll  --entry _DLLMainCRTStartup   --base-file base.$$$ -o RTLLib.dll RTLLib_link.res
  49. if errorlevel 1 goto linkend
  50. dlltool.exe -S as.exe -D RTLLib.dll -e exp.$$$ --base-file base.$$$
  51. if errorlevel 1 goto linkend
  52. ld.exe -b pei-x86-64  -s --dll  --entry _DLLMainCRTStartup   -o RTLLib.dll RTLLib_link.res exp.$$$
  53. if errorlevel 1 goto linkend
  54. goto end
  55. :asmend
  56. echo An error occurred while assembling %THEFILE%
  57. goto end
  58. :linkend
  59. echo An error occurred while linking %THEFILE%
  60. :end
I 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][+][-]
  1. echo Linking %THEFILE%
  2. ld.exe -b pei-x86-64  --gc-sections  -s --dll  --entry _DLLMainCRTStartup   --base-file base.$$$ -o RTLLib.dll -T RTLLib_link.res
  3. if errorlevel 1 goto linkend
  4. dlltool.exe -S as.exe -D RTLLib.dll -e exp.$$$ --base-file base.$$$
  5. if errorlevel 1 goto linkend
  6. ld.exe -b pei-x86-64  -s --dll  --entry _DLLMainCRTStartup   -o RTLLib.dll -T RTLLib_link.res exp.$$$
  7. if errorlevel 1 goto linkend
  8. goto end
I 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+0x14): 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_$__$$_create$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$$twidgetset+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_qapplicationpascal$_$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_qapplicationpascal$_$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     
« Last Edit: May 16, 2025, 07:50:16 am by paule32 »
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

munair

  • Hero Member
  • *****
  • Posts: 884
  • compiler developer @SharpBASIC
    • SharpBASIC
I think you should stop this madness.
It's only logical.

paule32

  • Hero Member
  • *****
  • Posts: 516
  • One in all. But, not all in one.
now, I compile with 3.3.1 stable thrunk:

Code: Bash  [Select][+][-]
  1. fpc -n -us -dDLLEXPORT -dLANGDEU -Px86_64 -Twin64 -B -O2 -Os -CD -Cg -a -al -Aas -st RTLLib.pas
  2. ::----
  3.  
  4. fpc -n -us -dDLLEXPORT -XX -CX -Xs -B -al -O2 -Twin64 -Px86_64 ^
  5.   -oRTLLib.dll  ^
  6.   -k-Trtlld ^
  7.   -k--dll ^
  8.   -k-eDllEntryPoint ^
  9.   RTLLib.pas
  10.  
  11. strip rtllib.dll
  12.  
  13. fpc -n -us -dDLLEXPORT -dDLANGDEU -O2 -Os -Cg -a -al -Aas -st main.pas
  14. dir main*.*
  15. as.exe --64 -o main.o main.s
  16.  
  17. 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]
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

 

TinyPortal © 2005-2018