FPC-LLVM installer ? lazarus / 64-FPC development ---------------------------------------------------------------------- Fred vS · 2022-10-30 11:55 Hello. Does it exist a binary installer of fpc-llvm, the same as the "classical" fpc for Linux amd64, but with fpc compiled for llvm? If yes, from where can I download it? Thanks. Fre;D ---------------------------------------------------------------------- Jonas Maebe · 2022-10-30 13:40 Quote from: Fred vS on October 30, 2022, 12:55:58 pmDoes it exist a binary installer of fpc-llvm, the same as the "classical" fpc for Linux amd64, but with fpc compiled for llvm? No, there is none. Keep in mind that right now, you also have to install it in a different prefix, because otherwise it overwrites the files of the regular FPC installation. ---------------------------------------------------------------------- Fred vS · 2022-10-30 15:36 Quote from: Jonas Maebe on October 30, 2022, 02:40:26 pmQuote from: Fred vS on October 30, 2022, 12:55:58 pmDoes it exist a binary installer of fpc-llvm, the same as the "classical" fpc for Linux amd64, but with fpc compiled for llvm? No, there is none. Keep in mind that right now, you also have to install it in a different prefix, because otherwise it overwrites the files of the regular FPC installation. Ha, ok. To compile-try fpc-llvm, are the infos from there ok? https://wiki.freepascal.org/LLVM Thanks. Fre;D ---------------------------------------------------------------------- Jonas Maebe · 2022-10-30 16:53 Quote from: Fred vS on October 30, 2022, 04:36:47 pmTo compile-try fpc-llvm, are the infos from there ok? https://wiki.freepascal.org/LLVM Yes. ---------------------------------------------------------------------- Fred vS · 2022-10-30 19:02 Quote from: Jonas Maebe on October 30, 2022, 05:53:05 pmQuote from: Fred vS on October 30, 2022, 04:36:47 pmTo compile-try fpc-llvm, are the infos from there ok? https://wiki.freepascal.org/LLVM Yes. OK, first check the coffee stock, then jump. Write you ( I hope not too ) later. Thanks. Fre;D ---------------------------------------------------------------------- Fred vS · 2022-10-30 21:27 Ooops, I did not yet finish the first cup of coffee anf fpc-llvm is alreaded compiled + installed! So, on Debian 11 64 bit, following this https://wiki.freepascal.org/LLVM - Install LLVM from Debian package (it will install llvm 11):   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 $ sudo apt install llvm - Install CLang from Debian package:   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 $ sudo apt install clang - Download fpc main source and unzip it. - Edit /etc/fpc.cfg and add this line (it is gcc 10 on Debian 11) :  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  -Fl/usr/lib/gcc/x86_64-linux-gnu/10/ - Script to build fpc (buildfpcllvm.sh): 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   #!/bin/sh  COMPILER=/usr/lib/fpc/3.2.2/ppcx64 make clean make all FPC=$COMPILER OPT="-Fl/usr/local/lib" OPTNEW="-Clv11.0" FPCMAKEOPT="-Clv11.0" LLVM=1 make FPC=$COMPILER install INSTALL_PREFIX=/usr/ - Run the script in fpc root source: 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  $ sudo buildfpcllvm.sh - Cross your fingers. - Yes, it is done. Compilation and installation went out-of-the-box.  There is the compiler in /usr/lib/fpc/3.3.1/ppcx64. But now I have some doubt. Do I really have a fpc-llvm version? In doc, it is said: QuoteUse FPC's -il command line parameter to list all supported LLVM and Xcode versions. These can be selected using the -Clv command line parameter. But if I add those -il or -Clv parameter to usr/lib/fpc/3.3.1/ppcx64 there is a error message "Illegal parameter". How to know if that ppcx64 has llvm feature? [EDIT M]aybe I miss something but after compilation of some test- source, I dont see any .ll assembly bitcode produced and the binary seems the same as compiled with "normal" fpc. Fre;D ---------------------------------------------------------------------- Jonas Maebe · 2022-10-31 11:11 Quote from: Fred vS on October 30, 2022, 10:27:29 pmThere is the compiler in /usr/lib/fpc/3.3.1/ppcx64. But now I have some doubt. Do I really have a fpc-llvm version? In doc, it is said: QuoteUse FPC's -il command line parameter to list all supported LLVM and Xcode versions. These can be selected using the -Clv command line parameter. But if I add those -il or -Clv parameter to usr/lib/fpc/3.3.1/ppcx64 there is a error message "Illegal parameter". How to know if that ppcx64 has llvm feature? If the above command lines return errors, it's not an LLVM-based compiler. Can you try the same with the compiler/ppcx64 binary in your source tree? If that one also returns an error, it was indeed not built with LLVM support. Can you post the full compilation log? ---------------------------------------------------------------------- Fred vS · 2022-10-31 11:32 Quote from: Jonas Maebe on October 31, 2022, 12:11:12 pmCan you try the same with the compiler/ppcx64 binary in your source tree? Not sure to understand. The source are in  /home/fred/Downloads/source-main/ After compilation, ppcx64 is created in /compiler: Code: [Select]fred@fred-pc ~> /home/fred/Downloads/source- main/compiler/ppcx64 -il Error: Illegal parameter: -il Quote from: Jonas Maebe on October 31, 2022, 12:11:12 pmCan you post the full compilation log? With pleasure (if  you tell me where is the compilation log    ) ---------------------------------------------------------------------- Fred vS · 2022-10-31 12:17 Re-hello Jonas. Maybe one cup of coffee was not enough. Because I did not find the log.txt file, I decided to recompile fpc- llvm with the same script of my previous post. And to copy the messages from console to have the log of messages. But this time, the compilation fails with that message (why not yesterday, mystery): Quote/home/fred/Downloads/source-main/compiler/ppc1 -Ur -Xs -O2 -n -Fux86_64 -Fusystems -Fu/home/fred/Downloads/source- main/rtl/units/x86_64-linux -Fix86_64 -FEx86_64/bin/x86_64-linux -FUx86_64/units/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-linux-gnu/10 -dRELEASE -Fl/usr/local/lib -Clv11.0 -Clflto -dx86_64 -dGDB -dllvm -Fullvm -Fux86 -Fix86 -Sew -o/home/fred/Downloads/source- main/compiler/ppc2 pp.pas /home/fred/Downloads/source-main/rtl/units/x86_64-linux/si_c.bc: file not recognized: file format not recognized pp.pas(302,1) Error: Error while linking pp.pas(302,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted make[5]: *** [Makefile:5119: ppcx64] Error 1 make[5]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[4]: *** [Makefile:5171: next] Error 2 make[4]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[3]: *** [Makefile:5177: ppc2] Error 2 make[3]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[2]: *** [Makefile:5187: cycle] Error 2 make[2]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[1]: *** [Makefile:3184: compiler_cycle] Error 2 make[1]: Leaving directory '/home/fred/Downloads/source-main' make: *** [Makefile:3216: build-stamp.x86_64-linux] Error 2 fred@fred-pc ~/D/source-main [2]> So this time it seems that the fpc-llvm was trying to compile but without luck. How can I fix this ? : Quote/home/fred/Downloads/source-main/rtl/units/x86_64-linux/si_c.bc: file not recognized: file format not recognized Fre;D ---------------------------------------------------------------------- marcov · 2022-10-31 12:32 Maybe normal linker selected instead of llvm linker? ---------------------------------------------------------------------- Fred vS · 2022-10-31 12:37 Quote from: marcov on October 31, 2022, 01:32:25 pmMaybe normal linker selected instead of llvm linker? Yep, it must be this. Hum, do you have some tips how to do to assign llvm linker vs normal? ---------------------------------------------------------------------- Fred vS · 2022-10-31 14:14 Hello. I did try changing linker to ld.gold and llvm-link: Script: 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 #!/bin/sh COMPILER=/usr/lib/fpc/3.2.2/ppcx64make cleanmake all FPC=$COMPILER OPT="-Fl/usr/local/lib -FL/usr/bin/llvm-link" OPTNEW="-Clv11.0 -Clflto -FL/usr/bin/llvm-link" FPCMAKEOPT="-Clv11.0" LLVM=1 But in both case there is that result: Quote/home/fred/Downloads/source-main/compiler/ppc1 -Ur -Xs -O2 -n -Fux86_64 -Fusystems -Fu/home/fred/Downloads/source- main/rtl/units/x86_64-linux -Fix86_64 -FEx86_64/bin/x86_64-linux -FUx86_64/units/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-linux-gnu/10 -dRELEASE -Fl/usr/local/lib -FL/usr/bin/llvm-link -Clv11.0 -Clflto -FL/usr/bin/llvm-link -dx86_64 -dGDB -dllvm -Fullvm -Fux86 -Fix86 -Sew -o/home/fred/Downloads/source-main/compiler/ppc2 pp.pas /home/fred/Downloads/source-main/rtl/units/x86_64-linux/si_c.bc: file not recognized: file format not recognized pp.pas(302,1) Error: Error while linking pp.pas(302,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted make[5]: *** [Makefile:5119: ppcx64] Error 1 make[5]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[4]: *** [Makefile:5171: next] Error 2 make[4]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[3]: *** [Makefile:5177: ppc2] Error 2 make[3]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[2]: *** [Makefile:5187: cycle] Error 2 make[2]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[1]: *** [Makefile:3184: compiler_cycle] Error 2 make[1]: Leaving directory '/home/fred/Downloads/source-main' make: *** [Makefile:3216: build-stamp.x86_64-linux] Error 2 What linker should be used (or maybe there is something else wrong) ? ---------------------------------------------------------------------- Jonas Maebe · 2022-10-31 19:27 If you want to use LLVM LTO on Linux, you need the llvmgold.so linker plugin. On Debian 11, this one is apparently packaged separately in https://packages.debian.org/unstable/llvm-11-linker-tools After installing that package, you should be able to use the regular system linker. ---------------------------------------------------------------------- Fred vS · 2022-11-01 00:00 Quote from: Jonas Maebe on October 31, 2022, 08:27:50 pmIf you want to use LLVM LTO on Linux, you need the llvmgold.so linker plugin. On Debian 11, this one is apparently packaged separately in https://packages.debian.org/unstable/llvm-11-linker-tools After installing that package, you should be able to use the regular system linker. Note that with or without parameter -Clflto the link fails. OK, so first find the package for Debian 11. 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 fred@fred- pc ~> apt search llvmgoldSorting... DoneFull Text Search... Donellvm-13-linker-tools/stable,now 1:13.0.1-6~deb11u1 amd64  Modular compiler and toolchain technologies - Plugins Because there is only a package for llvm-13, let's install llvm13: 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 fred@fred- pc ~>  sudo apt install llvm-13 And install also clang-13: 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 fred@fred- pc ~>  sudo apt install clang-13 In /usr/bin/ remove symlink clang (that has clang-11 as target ) and create a new symlink clang with target clang-13 OK, now install llvm-13-linker-tools: 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 fred@fred- pc ~>  sudo apt install llvm-13-linker-tools OK, plug-in installed, I did a reboot in case of. Time to re-compile + link fpc-llvm with the 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 make all FPC=$COMPILER OPT="-Fl/usr/local/lib -FL/usr/bin/ld.gold" OPTNEW="-Clv13.0 -FL/usr/bin/ld.gold" FPCMAKEOPT="-Clv13.0" LLVM=1 Yep,the link of ppc2 succeed but there is a error message when ppc2 try to compile /rtl/system.pp with a segmentation fault... Quotemake[5]: Entering directory '/home/fred/Downloads/source- main/compiler' make -C /home/fred/Downloads/source-main/rtl 'OPT=-Fl/usr/local/lib -FL/usr/bin/ld.gold -Clv13.0 -FL/usr/bin/ld.gold' all make[6]: Entering directory '/home/fred/Downloads/source-main/rtl' make -C linux all make[7]: Entering directory '/home/fred/Downloads/source- main/rtl/linux' make /home/fred/Downloads/source-main/rtl/units/x86_64-linux make[8]: Entering directory '/home/fred/Downloads/source- main/rtl/linux' make[8]: '/home/fred/Downloads/source-main/rtl/units/x86_64-linux' is up to date. make[8]: Leaving directory '/home/fred/Downloads/source- main/rtl/linux' as --64 -o /home/fred/Downloads/source- main/rtl/units/x86_64-linux/abitag.o x86_64/abitag.as /home/fred/Downloads/source-main/compiler/ppc2 -Ur -Ur -Xs -O2 -n -Fi../inc -Fi../x86_64 -Fi../unix -Fix86_64 -FE. -FU/home/fred/Downloads/source-main/rtl/units/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-linux-gnu/10 -Fl/usr/local/lib -FL/usr/bin/ld.gold -Clv13.0 -FL/usr/bin/ld.gold -dx86_64 -dRELEASE  -Us -Sg system.pp make[7]: *** [Makefile:4509: system.ppu] Segmentation fault make[7]: Leaving directory '/home/fred/Downloads/source- main/rtl/linux' make[6]: *** [Makefile:2322: linux_all] Error 2 make[6]: Leaving directory '/home/fred/Downloads/source-main/rtl' make[5]: *** [Makefile:5336: rtl] Error 2 make[5]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[4]: *** [Makefile:5169: next] Error 2 make[4]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[3]: *** [Makefile:5179: ppc3] Error 2 make[3]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[2]: *** [Makefile:5187: cycle] Error 2 make[2]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[1]: *** [Makefile:3184: compiler_cycle] Error 2 make[1]: Leaving directory '/home/fred/Downloads/source-main' make: *** [Makefile:3216: build-stamp.x86_64-linux] Error 2 Sadly the stock of coffee is empty now, I have to stop. If you have a idea how to fix this, you are welcome. Thanks. [EDIT] There are good news. If doing this (testing ppc1): 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 fred@fred- pc ~/D/source-main> /home/fred/Downloads/source-main/compiler/ppc1 -il  The result: Quote7.0 7.1 8.0 Xcode-11.0 9.0 Xcode-11.4 10.0 Xcode-12.0 11.0 11.1 Xcode-12.5 12.0 Xcode-13.0 13.0 Xcode-13.3 14.0 15.0 So, it is on the good way, already ppc1 has llvm feature.  But ppc2 has less luck: 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 fred@fred- pc ~> /home/fred/Downloads/source-main/compiler/ppc2 -ilfish: “/home/fred/Downloads/source-mai…” terminated by signal SIGSEGV (Address boundary error)  Fre;D ---------------------------------------------------------------------- Jonas Maebe · 2022-11-01 12:00 It's normal that your compiler crashes if you use -FL/usr/bin/ld.gold. That means "use ld.gold as the dynamic linker". ld.gold is not a dynamic linker, it's a static linker. Simply remove that parameter and it will work fine (since you are not using LTO any more). Although I also had to pass -XlS-13 so the compiler could find the clang-13 binary. There's no need to read the following, because LTO on Linux/x86-64 is currently broken due to a change unrelated to the LLVM code generator. But for completeness sake, regarding LTO and the gold linker: The way to tell the linker to use gold is to use its -fuse-ld=gold parameter.While FPC has some logic to detect where to find LLVMgold.so and pass its location to the linker, it can't find the system- installed one on Debian. The linker parameter to use there is -plugin=/usr/lib/llvm-13/lib/LLVMgold.soIn FPC, the way to pass options to the linker is to use the "-k" command line parameter, so that would become -k-fuse-ld=gold -k-plugin=/usr/lib/llvm-13/lib/LLVMgold.so. However, unfortunately the changes that were made to the FPC Linux x86-64 RTL to fix the issues with the "__libc_csu_init" symbol contain an error (they first define the symbols as global and then as weak, which is invalid). As a result, clang can't parse the inline assembly related to that and emits it directly. In case of LTO, this results in duplicate assembler labels. Fixing this will require adding functionality to FPC to enable defining weak symbols (currently we only have support to create weak references to symbols). ---------------------------------------------------------------------- Fred vS · 2022-11-01 15:19 Hello Jonas. You are still the All-Round World Champion!  With this: 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 make all FPC=$COMPILER OPT="-Fl/usr/local/lib" OPTNEW="-Clv13.0" FPCMAKEOPT="-Clv13.0" LLVM=1 I get this: 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 fred@fred- pc ~> /home/fred/Downloads/source-main/compiler/ppcx64 -il7.07.18.0Xco de-11.09.0Xcode-11.410.0Xcode-12.011.011.1Xcode-12.512.0Xcode- 13.013.0Xcode-13.314.015.0 So the entire process to compile fpc-llvm for Debian 11 is this: - First find the stable package where llvmgold is inside. This is needed for linking bc bitcode 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 fred@fred- pc ~> apt search llvmgoldSorting... DoneFull Text Search... Donellvm-13-linker-tools/stable,now 1:13.0.1-6~deb11u1 amd64  Modular compiler and toolchain technologies - Plugins Because there is only a package for llvm-13, let's install llvm13: 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 fred@fred- pc ~>  sudo apt install llvm-13 And install also clang-13: 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 fred@fred- pc ~>  sudo apt install clang-13 In /usr/bin/ remove symlink clang (that has clang-11 as target ) and create a new symlink clang with target clang-13 Then install llvm-13-linker-tools: 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 fred@fred- pc ~>  sudo apt install llvm-13-linker-tools OK, plug-in installed, I did a reboot in case of. - Download fpc main source and unzip it. - Edit /etc/fpc.cfg and add this line (it is gcc 10 on Debian 11) :  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  -Fl/usr/lib/gcc/x86_64-linux-gnu/10/ - Script to build fpc (buildfpcllvm.sh) : 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   #!/bin/sh  COMPILER=/usr/lib/fpc/3.2.2/ppcx64 make clean make all FPC=$COMPILER OPT="-Fl/usr/local/lib" OPTNEW="-Clv13.0" FPCMAKEOPT="-Clv13.0" LLVM=1 - Run the script in fpc root source directory: 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  $ sudo buildfpcllvm.sh - Cross your fingers and do something fun. (compilation of fpc-llvm takes much more time than "classical" fpc.) - When all is done, you may try fpc-llvm with this: 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 fred@fred- pc]> /directory_of_source-main/compiler/ppcx64 -il If you get this the compilation was OK: Quote7.0 7.1 8.0 Xcode-11.0 9.0 Xcode-11.4 10.0 Xcode-12.0 11.0 11.1 Xcode-12.5 12.0 Xcode-13.0 13.0 Xcode-13.3 14.0 15.0 - Installation of fpc-llvm (warning it will remove all previous install of fpc 3.3.1., so make a backup or change the directory target):   Here I need some more help from Jonas. Using this script: 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 #!/bin/sh COMPILER=fpcmake FPC=$COMPILER install INSTALL_PREFIX=/usr/ I get this: Quote[/usr/bin/install -m 755 -d /usr//lib/fpc/3.3.1 /usr/bin/install -m 755 -d /usr//bin make compiler_distinstall FPC=/home/fred/Downloads/source- main/compiler/ppcx64 ZIPDESTDIR=/home/fred/Downloads/source-main FPCMAKE=/home/fred/Downloads/source- main/utils/fpcm/bin/x86_64-linux/fpcmake make[2]: Entering directory '/home/fred/Downloads/source-main' make -C compiler distinstall make[3]: Entering directory '/home/fred/Downloads/source- main/compiler' make quickinstall auxfilesinstall make[4]: Entering directory '/home/fred/Downloads/source- main/compiler' make -C utils install make[5]: Entering directory '/home/fred/Downloads/source- main/compiler/utils' /home/fred/Downloads/source-main/compiler/ppcx64 -Ur -Xs -O2 -n -Fu.. -Fu/home/fred/Downloads/source-main/rtl/units/x86_64-linux -FE. -FUunits/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-linux-gnu/10 -dx86_64 -dRELEASE msg2inc.pp units/x86_64-linux/msg2inc.ll:654:71: error: expected '('         invoke  void (i8**, i8*, i64, i64) @"\01fpc_ansistr_copy" (i8** sret %reg.1_267, i8* %reg.1_266, i64 %reg.1_265, i64 %reg.1_261) to label %.Lj88 unwind label %.Lj9                                                                            ^ 1 error generated. Error: Error while assembling exitcode 1 Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted make[5]: *** [Makefile:3028: msg2inc] Error 1 make[5]: Leaving directory '/home/fred/Downloads/source- main/compiler/utils' make[4]: *** [Makefile:4759: utils_install] Error 2 make[4]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[3]: *** [Makefile:5325: install] Error 2 make[3]: Leaving directory '/home/fred/Downloads/source-main/compiler' make[2]: *** [Makefile:2948: compiler_distinstall] Error 2 make[2]: Leaving directory '/home/fred/Downloads/source-main' make[1]: *** [Makefile:3250: installbase] Error 2 make[1]: Leaving directory '/home/fred/Downloads/source-main' make: *** [Makefile:3265: installall] Error 2One more for Jonas: QuoteAlthough I also had to pass -XlS-13 so the compiler could find the clang-13 binary.This one I did not catch, if I pass -XlS-13 as fpc compiler option I get "Illegal Parameter". Many, many thanks Jonas for your great work and patience. Fre;D [/td][/tr][/table] ---------------------------------------------------------------------- Jonas Maebe · 2022-11-01 19:07 Quote from: Fred vS on November 01, 2022, 04:19:50 pmSo the entire process to compile fpc-llvm for Debian 11 is this: - First find the stable package where llvmgold is inside. This is needed for linking bc bitcode 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 fred@fred- pc ~> apt search llvmgoldSorting... DoneFull Text Search... Donellvm-13-linker-tools/stable,now 1:13.0.1-6~deb11u1 amd64  Modular compiler and toolchain technologies - PluginsNote that this part is only necessary if you use LTO. Since it currently doesn't work, that does not matter. QuoteIn /usr/bin/ remove symlink clang (that has clang-11 as target ) and create a new symlink clang with target clang-13 You can use the -XlS-13 parameter for this instead (note: the character between X and S is a lowercase "L" (from LLVM), not an uppercase "i"). QuoteThen install llvm-13-linker-tools: 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 fred@fred- pc ~>  sudo apt install llvm-13-linker-toolsNote that this part is only necessary if you use LTO. Since it currently doesn't work, that does not matter. If you don't use LTO, FPC generates plain object files when compiling with LLVM. Quote- Cross your fingers and do something fun. (compilation of fpc- llvm takes much more time than "classical" fpc.) LLVM is indeed much slower than FPC's internal code generator. Note that you can add -j X FPMAKEOPT="-T X" to your make command line to speed it up (replace X with the number of cpu cores you have). That also works without LLVM, of course. QuoteUsing this script: 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 #!/bin/sh COMPILER=fpcmake FPC=$COMPILER install INSTALL_PREFIX=/usr/ Add OPT="-Clv13.0 -Xls13.0" so that in case this compiles extra programs, it generates code for the correct LLVM version. The error you got is because msg2inc was compiled for LLVM 7.0 (the default if you don't use a -Clv parameter) instead of 13.0 (your installed version). It's also safer to specify FPC=$PWD/compiler/ppcx64 when installing (i.e., specify the new compiler). QuoteOne more for Jonas: QuoteAlthough I also had to pass -XlS-13 so the compiler could find the clang-13 binary.This one I did not catch, if I pass -XlS-13 as fpc compiler option I get "Illegal Parameter". I cannot explain this, except that maybe you used -XS instead of -XS, or perhaps used it with a non-LLVM compiler. ---------------------------------------------------------------------- Fred vS · 2022-11-01 19:55 Hello Jonas. You are the Greatest. 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 fred-pc > /usr/lib/fpc/3.3.1/ppcx64 -ilQuote7.0 7.1 8.0 Xcode-11.0 9.0 Xcode-11.4 10.0 Xcode-12.0 11.0 11.1 Xcode-12.5 12.0 Xcode-13.0 13.0 Xcode-13.3 14.0 15.0 I used this script and the installation was ok: 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 #!/bin/sh COMPILER=/home/fred/Downloads/source-main/compiler/ppcx64make FPC=$COMPILER install OPT="-Clv13.0 -Xls13.0" INSTALL_PREFIX=/usr/ I was not able to make work the script adding -Xls13.0 parameter, I dont know why but I get a "invalid parameter". But without it and only OPT="-Clv13.0" the installation was ok. [EDIT] It works, no problems, sorry for disturb  QuoteThen install llvm-13-linker-tools: ... Note that this part is only necessary if you use LTO. Since it currently doesn't work, that does not matter. If you don't use LTO, FPC generates plain object files when compiling with LLVM. Hum, I did try to compile fpc-llvm without -Clflto parameter and it refused to link bc files. It is only after installing llvm-13-linker-tools that the link was ok. But maybe it was something else that enabled link of bc files, it is possible, I did lot of tuning-change-installation. Many, many thanks Jonas for your precious work and patience to explain all this. Now, beginning of a new chapter: "Using and testing fpc-llvm"  Fre;D ---------------------------------------------------------------------- Jonas Maebe · 2022-11-01 20:23 Quote from: Fred vS on November 01, 2022, 08:55:31 pmI used this script and the installation was ok: 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 #!/bin/sh COMPILER=/home/fred/Downloads/source-main/compiler/ppcx64make FPC=$COMPILER install OPT="-Clv13.0 -Xls13.0" INSTALL_PREFIX=/usr/"-Xls13.0" should not work: The parameter is -XlS, not -XlsThe name of the clang binary is clang-13 (-> -XlS-13), not clang13.0 (which is what -XlS13.0 would result in) QuoteHum, I did try to compile fpc-llvm without -Clflto parameter and it refused to link bc files. Your first post with an error about failing to link .bc files did use -flto: https://forum.lazarus.freepascal.org/index.php/topic,61069.msg4 58562.html#msg458562 FPC does not tell clang to generate .bc files except if you use -flto. QuoteNow, beginning of a new chapter: "Using and testing fpc-llvm"  Looking forward to it! ---------------------------------------------------------------------- Fred vS · 2022-11-01 20:28 Quotebecause msg2inc was compiled for LLVM 7.0 (the default if you don't use a -Clv parameter) instead of 13.0 (your installed version).Is it the same as libc.so, is it better, if you want that a release can be run on a maximum of distros, to compile it with a old LLVM version? Or that does not matter a app compiled with LLVM 13 can run on a system with only LLVM 7 installed? ---------------------------------------------------------------------- Fred vS · 2022-11-01 20:36 Quote from: Jonas Maebe on November 01, 2022, 09:23:24 pmQuote from: Fred vS on November 01, 2022, 08:55:31 pmI used this script and the installation was ok: 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 #!/bin/sh COMPILER=/home/fred/Downloads/source-main/compiler/ppcx64make FPC=$COMPILER install OPT="-Clv13.0 -Xls13.0" INSTALL_PREFIX=/usr/"-Xls13.0" should not work: The parameter is -XlS, not -XlsThe name of the clang binary is clang-13 (-> -XlS-13), not clang13.0 (which is what -XlS13.0 would result in) QuoteHum, I did try to compile fpc-llvm without -Clflto parameter and it refused to link bc files. Your first post with an error about failing to link .bc files did use -flto: https://forum.lazarus.freepascal.org/index.php/topic,61069.msg4 58562.html#msg458562 FPC does not tell clang to generate .bc files except if you use -flto. QuoteNow, beginning of a new chapter: "Using and testing fpc-llvm"  Looking forward to it! Thanks Jonas for that clear explanation. I am very excited to test your fpc-llvm, write you later. <3 Fre;D ---------------------------------------------------------------------- Jonas Maebe · 2022-11-01 20:43 Quote from: Fred vS on November 01, 2022, 09:28:55 pmQuotebecause msg2inc was compiled for LLVM 7.0 (the default if you don't use a -Clv parameter) instead of 13.0 (your installed version).Is it the same as libc.so, is it better, if you want that a release can be run on a maximum of distros, to compile it with a old LLVM version? Or that does not matter a app compiled with LLVM 13 can run on a system with only LLVM 7 installed? It does not matter. It's the same as compiling a program with gcc 10/fpc 3.3.1 for running on a system without any gcc/fpc or with an older gcc/fpc installed. The final program does not need the compiler to be installed. ---------------------------------------------------------------------- Fred vS · 2022-11-01 22:20 Hello. Some news from the front... Chapter 2: Using the fpc-llvm compiler. I decided to directly attack a big project, graphic, using MSEgui widgetset, with thousands of lines of code, bridges of classes, sound, animations, DSP's, and much more other complicated things. First (and only) thing to do is to add -Clv13.0 -XlS-13 parameters in the big list of parameters used by the project. Do compilation ( I removed all optimizations for this first test ). And big, big, WoW, compilation succeed and run was ok too. Animations and sound DSP's are very fluids. And all this totally out-of-the-box. Jonas and your partners, you did a impressing work. Mountains of congratulations. Pascal should not worry, his future is bright.  Fre;D ---------------------------------------------------------------------- Fred vS · 2022-11-02 19:22 Hello. Continuation...  Chapter 3: Speed of FPC-LLVM in float calculation.  Using the code of BobDog from here: https://forum.lazarus.freepascal.org/index.php/topic,57039.msg424048.h tml#msg424048 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 testarray;     uses    sysutils;    type    aos=array of single;     var    arr0, arr1, arr2, arr3 : array of single;    ratio : single = 0.123;    ratio1 : single = 0.345;    ratio2 : single = 0.567;    ratio3 : single = 0.890;              procedure CalculArrays() ; // add and multiply     var      i : int64;      begin       // all arrays have the same size        for i := 0 to length(arr0) -1 do      begin          arr0[i]:=0;          arr0[i] := ratio * ( (ratio1 * arr1[i]) + (ratio2 * arr2[i]) + (ratio3 * arr3[i]) ); // here ratio multiply        end;      end;          procedure CalculArrays2(var arr0:aos;arr1:aos;arr2:aos;arr3:aos); // add and multiply       var      i : int64;      begin      // all arrays have the same size      for i := 0 to length(arr0) -1 do        begin         arr0[i]:=0;       arr0[i] := ratio * ( (ratio1 * arr1[i]) + (ratio2 * arr2[i]) + (ratio3 * arr3[i]) ); // here ratio multiply        end;      end;   procedure CalculArrays3(const arr0,arr1,arr2,arr3:aos); //      var      i : int64;      begin      // all arrays have the same size      for i := 0 to length(arr0) -1 do        begin         arr0[i]:=0;       arr0[i] := ratio * ( (ratio1 * arr1[i]) + (ratio2 * arr2[i]) + (ratio3 * arr3[i]) ); // here ratio multiply        end;      end;      procedure CalculArrays4(arr0,arr1,arr2,arr3:aos); //      var      i : int64;      begin      // all arrays have the same size        for i := 0 to length(arr0) -1 do        begin         arr0[i]:=0;       arr0[i] := ratio * ( (ratio1 * arr1[i]) + (ratio2 * arr2[i]) + (ratio3 * arr3[i]) ); // here ratio multiply        end;      end;      var      lim:int64=200000000;      i,k,t,t2,totg,totp, totp2, totp3 :int64;         begin      writeln('Filling arrays, please wait a second or so . . .');      setlength(arr0,lim);      setlength(arr1,lim);      setlength(arr2,lim);      setlength(arr3,lim);      for i:=0 to lim-1 do      begin      arr1[i]:=i;      arr2[i]:=i;      arr3[i]:=i;      end;      totp:=0;      totp2:=0;      totp3:=0;      totg:=0;       writeln('OK arrays filled, START the race . . .');     for k:=1 to 5 do     begin      writeln('Pass ',k);      t:=gettickcount64;      CalculArrays();      t2:=gettickcount64-t;      totg:=totg+t2;      t:=gettickcount64;    CalculArrays2(arr0,arr1,arr2,arr3);      t2:=gettickcount64-t;      totp:=totp+t2;      t:=gettickcount64;      CalculArrays3(arr0,arr1,arr2,arr3);      t2:=gettickcount64-t;      totp2:=totp2+t2;      t:=gettickcount64;      CalculArrays4(arr0,arr1,arr2,arr3);      t2:=gettickcount64-t;      totp3:=totp3+t2;    end;     writeln('Time with globals ',totg);     writeln('Time with params var ',totp);     writeln('Time with params const ',totp2);     writeln('Time with params nil ',totp3);     writeln('Press return to end');     readln;    end.   The result on my (slow) Celeron with 4 gigas ram: FPC 3.2.2 with -O2: QuoteTime with globals 12536 Time with params var 12537 Time with params const 12023 Time with params nil 12535 FPC-LLVM 3.3.1 with -O2 QuoteTime with globals 12794 Time with params var 12595 Time with params const 12267 Time with params nil 12277 Hum FPC 3.2.2 wins using params const: 12023 But with -O4 all change: FPC 3.2.2 with -O4: QuoteTime with globals 12546 Time with params var 12557 Time with params const 12030 Time with params nil 12546 FPC-LLVM 3.3.1 with -O4 QuoteTime with globals 11931 Time with params var 12065 Time with params const 3651 Time with params nil 3651 With -O4 and using params const or params nil it is nearly 10 times faster with fpc-llvm vs fpc. Also strange that big difference between using params var vs const. ---------------------------------------------------------------------- Jonas Maebe · 2022-11-02 19:29 -O4 enables fast math. Without fast math, FPC uses special LLVM intrinsics for floating point math that respect floating point exceptions. These prevent constant propagation and generally cannot be optimised well by LLVM. With fast math, FPC uses the regular LLVM floating point operations and then LLVM can perform constant propagation. It probably calculates most of the loop's contents at compile-time in that case. ---------------------------------------------------------------------- Fred vS · 2022-11-02 19:33 Quote from: Jonas Maebe on November 02, 2022, 08:29:33 pm-O4 enables fast math. Without fast math, FPC uses special LLVM intrinsics for floating point math that respect floating point exceptions. These prevent constant propagation and generally cannot be optimised well by LLVM. With fast math, FPC uses the regular LLVM floating point operations and then LLVM can perform constant propagation. It probably calculates most of the loop's contents at compile-time in that case. OK but what about the huge difference if using the same procedure but with var parameter vs const parameter with fpc-llvm (see code) ? ---------------------------------------------------------------------- Jonas Maebe · 2022-11-02 19:41 Quote from: Fred vS on November 02, 2022, 08:33:43 pmQuote from: Jonas Maebe on November 02, 2022, 08:29:33 pm-O4 enables fast math. Without fast math, FPC uses special LLVM intrinsics for floating point math that respect floating point exceptions. These prevent constant propagation and generally cannot be optimised well by LLVM. With fast math, FPC uses the regular LLVM floating point operations and then LLVM can perform constant propagation. It probably calculates most of the loop's contents at compile-time in that case. OK but what about the huge difference if using the same procedure but with var parameter vs const parameter with fpc-llvm (see code) ? Maybe it cannot prove that none of the dynamic array parameters change during the loop when you use var. Memory alias analysis is very hard. ---------------------------------------------------------------------- Fred vS · 2022-11-02 19:50 Quote from: Jonas Maebe on November 02, 2022, 08:41:51 pmQuote from: Fred vS on November 02, 2022, 08:33:43 pmQuote from: Jonas Maebe on November 02, 2022, 08:29:33 pm-O4 enables fast math. Without fast math, FPC uses special LLVM intrinsics for floating point math that respect floating point exceptions. These prevent constant propagation and generally cannot be optimised well by LLVM. With fast math, FPC uses the regular LLVM floating point operations and then LLVM can perform constant propagation. It probably calculates most of the loop's contents at compile-time in that case. OK but what about the huge difference if using the same procedure but with var parameter vs const parameter with fpc-llvm (see code) ? Maybe it cannot prove that none of the dynamic array parameters change during the loop when you use var. Memory alias analysis is very hard. Yes, maybe ( but what is sure is that it encourages me to use "const" vs "var" or even simpler no "const" or "var" at all ( like in code procedure CalculArrays4(arr0,arr1,arr2,arr3:aos) because if the result is real, 10 x faster is WoW ) But surely I miss something, so forgive me. ---------------------------------------------------------------------- Jonas Maebe · 2022-11-02 19:51 Quote from: Fred vS on November 02, 2022, 08:50:31 pmQuote from: Jonas Maebe on November 02, 2022, 08:41:51 pmQuote from: Fred vS on November 02, 2022, 08:33:43 pmQuote from: Jonas Maebe on November 02, 2022, 08:29:33 pm-O4 enables fast math. Without fast math, FPC uses special LLVM intrinsics for floating point math that respect floating point exceptions. These prevent constant propagation and generally cannot be optimised well by LLVM. With fast math, FPC uses the regular LLVM floating point operations and then LLVM can perform constant propagation. It probably calculates most of the loop's contents at compile-time in that case. OK but what about the huge difference if using the same procedure but with var parameter vs const parameter with fpc-llvm (see code) ? Maybe it cannot prove that none of the dynamic array parameters change during the loop when you use var. Memory alias analysis is very hard. Yes, maybe ( but what is sure is that it encourages me to use "const" vs "var" or even simpler no "const" or "var" at all ( like in code procedure CalculArrays4(arr0,arr1,arr2,arr3:aos) because if the result is real, 10 faster is WoW ) In a real-world program the differences won't be that big. It's only in artificial programs where the output can be completely calculated at compile time from the input, or where the compiler can prove that the calculated values are not even used. ---------------------------------------------------------------------- Fred vS · 2022-11-02 19:59 Quote from: Jonas Maebe on November 02, 2022, 08:51:57 pmQuote from: Fred vS on November 02, 2022, 08:50:31 pmQuote from: Jonas Maebe on November 02, 2022, 08:41:51 pmQuote from: Fred vS on November 02, 2022, 08:33:43 pmQuote from: Jonas Maebe on November 02, 2022, 08:29:33 pm-O4 enables fast math. Without fast math, FPC uses special LLVM intrinsics for floating point math that respect floating point exceptions. These prevent constant propagation and generally cannot be optimised well by LLVM. With fast math, FPC uses the regular LLVM floating point operations and then LLVM can perform constant propagation. It probably calculates most of the loop's contents at compile-time in that case. OK but what about the huge difference if using the same procedure but with var parameter vs const parameter with fpc-llvm (see code) ? Maybe it cannot prove that none of the dynamic array parameters change during the loop when you use var. Memory alias analysis is very hard. Yes, maybe ( but what is sure is that it encourages me to use "const" vs "var" or even simpler no "const" or "var" at all ( like in code procedure CalculArrays4(arr0,arr1,arr2,arr3:aos) because if the result is real, 10 faster is WoW ) In a real-world program the differences won't be that big. It's only in artificial programs where the output can be completely calculated at compile time from the input, or where the compiler can prove that the calculated values are not even used. What is sure is that in the real world fpc-llvm works very well (even gives vertigo on some test). Well done Jonas.  Fre;D ---------------------------------------------------------------------- Fred vS · 2022-11-07 13:34 Hello everybody. Coming back to the initial title of the topic and following all the advices from previous posts, here all the steps to compile fpc-llvm on Debian 11 64 bit. Those steps should be the same for all Debian childs like Ubuntu, Mint, ... -1) Install last stable LLVM version (with Debian 11 it is LLVM 13): 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  ~>  sudo apt install llvm-13 -2) Install clang-13: 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  ~>  sudo apt install clang-13 -3) Download fpc main source and unzip it.     https://gitlab.com/freepascal.org/fpc/source/-/archive/main/source- main.zip -4) Edit your /etc/fpc.cfg and add this line (it is gcc 10 on Debian 11) : 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 -Fl/usr/lib/gcc/x86_64-linux-gnu/10/ -5) Script to build fpc (buildfpcllvm.sh) : 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   #!/bin/sh  COMPILER=/usr/lib/fpc/3.2.2/ppcx64 make clean make all FPC=$COMPILER OPT="-Fl/usr/local/lib" OPTNEW="-Clv13.0 -XlS-13" FPCMAKEOPT="-Clv13.0 -XlS-13" LLVM=1 -6) Run the script in fpc root source directory: 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  > buildfpcllvm.sh -7) Cross your fingers and do something fun. (compilation of fpc-llvm takes much more time than "classical" fpc.) -8) When all is done, you may try fpc-llvm with this: 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  > /directory_of_fpc_source-main/compiler/ppcx64 -il If you get this the compilation was OK: Quote7.0 7.1 8.0 Xcode-11.0 9.0 Xcode-11.4 10.0 Xcode-12.0 11.0 11.1 Xcode-12.5 12.0 Xcode-13.0 13.0 Xcode-13.3 14.0 15.0 -9) Installation of fpc-llvm (warning it will remove all previous install of fpc 3.3.1., so make a backup or change the directory target): The install script (installfpcllvm.sh)  ( Note: it uses the new compiler ): 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 #!/bin/sh COMPILER=/directory_of_fp_source-main/compiler/ppcx64make FPC=$COMPILER install OPT="-Clv13.0 -XlS-13" INSTALL_PREFIX=/usr/  Run the script with root permission: 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  > sudo installfpcllvm.sh  -10) Test fpc-llvm: 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 > /usr/lib/fpc/3.3.1/ppcx64 -il If all was ok, you should have the same result as step 8 ). -11) Using fpc-llvm for your application:        Just add those fpc parameters: -Clv13.0 -XlS-13 for compilation. -12) Enjoy. Fre;D