Recent

Author Topic: FPC-LLVM installer ?  (Read 2309 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 2989
    • StrumPract is the musicians best friend
FPC-LLVM installer ?
« on: October 30, 2022, 12:55:58 pm »
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
« Last Edit: October 30, 2022, 01:24:17 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1038
Re: FPC-LLVM installer ?
« Reply #1 on: October 30, 2022, 02:40:26 pm »
Does 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

  • Hero Member
  • *****
  • Posts: 2989
    • StrumPract is the musicians best friend
Re: FPC-LLVM installer ?
« Reply #2 on: October 30, 2022, 04:36:47 pm »
Does 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
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1038
Re: FPC-LLVM installer ?
« Reply #3 on: October 30, 2022, 05:53:05 pm »
To compile-try fpc-llvm, are the infos from there ok?
https://wiki.freepascal.org/LLVM
Yes.

Fred vS

  • Hero Member
  • *****
  • Posts: 2989
    • StrumPract is the musicians best friend
Re: FPC-LLVM installer ?
« Reply #4 on: October 30, 2022, 08:02:34 pm »
To 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
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 2989
    • StrumPract is the musicians best friend
Re: FPC-LLVM installer ?
« Reply #5 on: October 30, 2022, 10:27:29 pm »
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][+][-]
  1. $ sudo apt install llvm

- Install CLang from Debian package:
 
Code: Bash  [Select][+][-]
  1. $ 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][+][-]
  1.  -Fl/usr/lib/gcc/x86_64-linux-gnu/10/

- Script to build fpc (buildfpcllvm.sh):
Code: Bash  [Select][+][-]
  1.   #!/bin/sh
  2.  COMPILER=/usr/lib/fpc/3.2.2/ppcx64
  3.  make clean
  4.  make all FPC=$COMPILER OPT="-Fl/usr/local/lib" OPTNEW="-Clv11.0" FPCMAKEOPT="-Clv11.0" LLVM=1
  5.  make FPC=$COMPILER install INSTALL_PREFIX=/usr/
  6.  
- Run the script in fpc root source:
Code: Bash  [Select][+][-]
  1.  $ sudo buildfpcllvm.sh

- Cross your fingers.

- Yes, it is done.

Compilation and installation went out-of-the-box.  ;D

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:
Quote
Use 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
« Last Edit: October 31, 2022, 03:46:37 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1038
Re: FPC-LLVM installer ?
« Reply #6 on: October 31, 2022, 12:11:12 pm »
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:
Quote
Use 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

  • Hero Member
  • *****
  • Posts: 2989
    • StrumPract is the musicians best friend
Re: FPC-LLVM installer ?
« Reply #7 on: October 31, 2022, 12:32:07 pm »
Can 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

Can you post the full compilation log?
With pleasure (if  you tell me where is the compilation log  :-[  )
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 2989
    • StrumPract is the musicians best friend
Re: FPC-LLVM installer ?
« Reply #8 on: October 31, 2022, 01:17:02 pm »
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
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10584
  • FPC developer.
Re: FPC-LLVM installer ?
« Reply #9 on: October 31, 2022, 01:32:25 pm »
Maybe normal linker selected instead of llvm linker?

Fred vS

  • Hero Member
  • *****
  • Posts: 2989
    • StrumPract is the musicians best friend
Re: FPC-LLVM installer ?
« Reply #10 on: October 31, 2022, 01:37:40 pm »
Maybe 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?  ::)
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 2989
    • StrumPract is the musicians best friend
Re: FPC-LLVM installer ?
« Reply #11 on: October 31, 2022, 03:14:03 pm »
Hello.

I did try changing linker to ld.gold and llvm-link:

Script:
Code: Pascal  [Select][+][-]
  1. #!/bin/sh
  2. COMPILER=/usr/lib/fpc/3.2.2/ppcx64
  3. make clean
  4. make 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) ?
« Last Edit: October 31, 2022, 03:40:14 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1038
Re: FPC-LLVM installer ?
« Reply #12 on: October 31, 2022, 08:27:50 pm »
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

  • Hero Member
  • *****
  • Posts: 2989
    • StrumPract is the musicians best friend
Re: FPC-LLVM installer ?
« Reply #13 on: November 01, 2022, 01:00:17 am »
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.

Note that with or without parameter -Clflto the link fails.

OK, so first find the package for Debian 11.
Code: Bash  [Select][+][-]
  1. fred@fred-pc ~> apt search llvmgold
  2. Sorting... Done
  3. Full Text Search... Done
  4. llvm-13-linker-tools/stable,now 1:13.0.1-6~deb11u1 amd64
  5.   Modular compiler and toolchain technologies - Plugins

Because there is only a package for llvm-13, let's install llvm13:
Code: Bash  [Select][+][-]
  1. fred@fred-pc ~>  sudo apt install llvm-13

And install also clang-13:
Code: Bash  [Select][+][-]
  1. 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][+][-]
  1. 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][+][-]
  1. 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...

Quote
make[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][+][-]
  1. fred@fred-pc ~/D/source-main>
  2. /home/fred/Downloads/source-main/compiler/ppc1 -il
  3.  

The result:
Quote
7.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][+][-]
  1. fred@fred-pc ~> /home/fred/Downloads/source-main/compiler/ppc2 -il
  2. fish: “/home/fred/Downloads/source-mai…” terminated by signal SIGSEGV (Address boundary error)
  3.  

Fre;D
« Last Edit: November 01, 2022, 03:08:33 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1038
Re: FPC-LLVM installer ?
« Reply #14 on: November 01, 2022, 01:00:35 pm »
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.so
In 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).

 

TinyPortal © 2005-2018