Recent

Author Topic: linking errors compiling on aarch64  (Read 2455 times)

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
linking errors compiling on aarch64
« on: March 27, 2022, 07:01:15 pm »
Hi
I am trying to compile lazarus for my pinebook pro (KDE on Manjaro on aarch64).

I used this file
Code: [Select]
wget https://gitlab.com/freepascal.org/lazarus/lazarus/-/archive/main/lazarus-main.zip

This is what I got (the last bit)
Code: [Select]
make --assume-new=lazres.pp lazres
make[2]: Entering directory '/home/philip/fpc/source/lazarus-main/tools'
Makefile:2956: warning: overriding recipe for target '.'
Makefile:2954: warning: ignoring old recipe for target '.'
/usr/local/bin/ppca64 -gl -Fu. -Fu../components/lazutils/lib/aarch64-linux -Fu../lcl/units/aarch64-linux -Fu../lcl/units/aarch64-linux/nogui -Fu/usr/local/lib/fpc/3.2.2/units/aarch64-linux/rtl -FE. -FU. -Flinclude -Fl/etc/ld.so.conf.d/*.conf -daarch64 lazres.pp
Free Pascal Compiler version 3.2.2 [2021/05/23] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for AArch64
Compiling lazres.pp
lazres.pp(65,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(81,3) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(95,11) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(98,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(109,11) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(112,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(121,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(124,3) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(261,3) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(275,3) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(257,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(231,7) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(233,7) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(208,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(180,11) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(306,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(308,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(321,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(348,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(361,7) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
Assembling lazres
Linking ./lazres
lazres.pp(395) Warning: "crtbegin.o" not found, this will probably cause a linking failure
lazres.pp(395) Warning: "crtend.o" not found, this will probably cause a linking failure
/bin/ld: /usr/local/lib/fpc/3.2.2/units/aarch64-linux/rtl/cprt0.o: in function `_start':
(.text+0x54): undefined reference to `__libc_csu_init'
/bin/ld: (.text+0x58): undefined reference to `__libc_csu_init'
/bin/ld: (.text+0x5c): undefined reference to `__libc_csu_fini'
/bin/ld: (.text+0x60): undefined reference to `__libc_csu_fini'
lazres.pp(395) Error: Error while linking
lazres.pp(395) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
make[2]: *** [Makefile:2964: lazres] Error 1
make[2]: Leaving directory '/home/philip/fpc/source/lazarus-main/tools'
make[1]: *** [Makefile:3394: all] Error 2
make[1]: Leaving directory '/home/philip/fpc/source/lazarus-main/tools'
make: *** [Makefile:3803: lazbuild] Error 2

any help would be appreciated

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: linking errors compiling on aarch64
« Reply #1 on: March 28, 2022, 12:34:55 am »

1) Locate the missing object files (I'm assuming they exist in your file system)
2) Add -va as an option for details of where FPC is looking for the missing object files
3) Add the location of the missing object files -or- link them to where FPC is looking.

If the missing object files do not exist, I'm told installing libgcc should resolve that one.

dbannon

  • Hero Member
  • *****
  • Posts: 2791
    • tomboy-ng, a rewrite of the classic Tomboy
Re: linking errors compiling on aarch64
« Reply #2 on: March 28, 2022, 01:25:54 am »
These files exist (assuming you have gcc installed, its a dependency of fpc, along with binutils, make) in places like

Code: Text  [Select][+][-]
  1. /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o
But the '9' depends on the version of gcc you have and the "x86_64-linux-gnu" depends on your cpu and the "/usr/lib" depends on your distribution! Sigh ...

So, find out where your (eg) crtbegin.o really is

Code: Bash  [Select][+][-]
  1. find / -name "crtbegin.o" 2> /dev/null <enter>

and either edit your fpc.cfg file or (better IMHO) add a symlink.  I have a line in my fpc.cfg that looks like this -

Code: Bash  [Select][+][-]
  1. -Fl/usr/lib/gcc/x86_64-linux-gnu/9

You should have something vaguely similar.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
Re: linking errors compiling on aarch64
« Reply #3 on: March 28, 2022, 01:13:26 pm »
These files exist (assuming you have gcc installed, its a dependency of fpc, along with binutils, make) in places like

Code: Text  [Select][+][-]
  1. /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o
But the '9' depends on the version of gcc you have and the "x86_64-linux-gnu" depends on your cpu and the "/usr/lib" depends on your distribution! Sigh ...

So, find out where your (eg) crtbegin.o really is

Code: Bash  [Select][+][-]
  1. find / -name "crtbegin.o" 2> /dev/null <enter>

and either edit your fpc.cfg file or (better IMHO) add a symlink.  I have a line in my fpc.cfg that looks like this -

Code: Bash  [Select][+][-]
  1. -Fl/usr/lib/gcc/x86_64-linux-gnu/9

You should have something vaguely similar.

Davo

Thanks.  Your answer got rid of some of the errors.
Specifically, I added this line in /etc/fpc.cfg
Code: [Select]
# path to the gcclib
-Fl/usr/lib/gcc/aarch64-unknown-linux-gnu/11.2.0

However I still have this:-
Code: [Select]
Free Pascal Compiler version 3.2.2 [2022/01/24] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for AArch64
Compiling lazres.pp
lazres.pp(65,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(81,3) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(95,11) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(98,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(109,11) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(112,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(121,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(124,3) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(261,3) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(275,3) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(257,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(231,7) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(233,7) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(208,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(180,11) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(306,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(308,5) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(321,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(348,9) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
lazres.pp(361,7) Note: Call to subroutine "function GetDebugLogger:TLazLogger;" marked as inline is not inlined
Assembling lazres
Linking ./lazres
/bin/ld: /usr/local/lib/fpc/3.2.2/units/aarch64-linux/rtl/cprt0.o: in function `_start':
(.text+0x54): undefined reference to `__libc_csu_init'
/bin/ld: (.text+0x58): undefined reference to `__libc_csu_init'
/bin/ld: (.text+0x5c): undefined reference to `__libc_csu_fini'
/bin/ld: (.text+0x60): undefined reference to `__libc_csu_fini'
lazres.pp(395) Error: Error while linking
lazres.pp(395) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
make[2]: *** [Makefile:2964: lazres] Error 1
make[2]: Leaving directory '/home/philip/fpc/source/lazarus-main/tools'
make[1]: *** [Makefile:3394: all] Error 2
make[1]: Leaving directory '/home/philip/fpc/source/lazarus-main/tools'
make: *** [Makefile:3803: lazbuild] Error 2

I have since discovered that lazarus and freepascal can now be installed from pacman.  When I first got my pinebook pro this wasn't the case and so I had to compile from source.

So now I have two installations of fpc, one in /usr/local/bin which I installed using the install.sh from direct download of fpc, and one in /usr/bin which pacman put there.

If there was an uninstall.sh I would probably run it....

dbannon

  • Hero Member
  • *****
  • Posts: 2791
    • tomboy-ng, a rewrite of the classic Tomboy
Re: linking errors compiling on aarch64
« Reply #4 on: March 29, 2022, 01:01:03 am »
...
However I still have this:-
Code: [Select]

/bin/ld: /usr/local/lib/fpc/3.2.2/units/aarch64-linux/rtl/cprt0.o: in function `_start':
(.text+0x54): undefined reference to `__libc_csu_init'
...
Just to be sure, you have installed the dependencies listed on, eg, https://wiki.freepascal.org/Installing_the_Free_Pascal_Compiler#FPC_Tar_Balls  ?
Quote
If there was an uninstall.sh I would probably run it....

Bit late to tell you now but when you install from the FPC Tarball, you do not have to install into /usr/ - I install into a dir in my home dir, set it all up in there and can easily blow it away when ever I feel like it. Thats what the example on the wiki shows ...

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: linking errors compiling on aarch64
« Reply #5 on: March 29, 2022, 10:21:45 am »
any help would be appreciated

This is a known problem. To solve it you need the source code for FPC 3.2.2 if you don't have it already. There you navigate to rtl/linux/aarch64 and edit the file cprt0.as (around line 40):

Code: ASM  [Select][+][-]
  1.         /* __libc_start_main(main, argc, argv,
  2.                              init, fini, rtld_fini, stack_end) */
  3.         adrp    x0,:got:PASCALMAIN
  4.         ldr     x0,[x0,#:got_lo12:PASCALMAIN]
  5.         adrp    x3,:got:__libc_csu_init
  6.         ldr     x3,[x3,#:got_lo12:__libc_csu_init]
  7.         adrp    x4,:got:__libc_csu_fini
  8.         ldr     x4,[x4,#:got_lo12:__libc_csu_fini]
  9.         bl      __libc_start_main
  10.  

Replace this with the following:

Code: ASM  [Select][+][-]
  1.         /* __libc_start_main(main, argc, argv,
  2.                              init, fini, rtld_fini, stack_end) */
  3.         adrp    x0,:got:PASCALMAIN
  4.         ldr     x0,[x0,#:got_lo12:PASCALMAIN]
  5.         mov     x3,xzr
  6.         mov     x4,xzr
  7.         bl      __libc_start_main
  8.  

And then go one directory up (to rtl/linux) and execute

Code: [Select]
make CPU_TARGET=aarch64 OS_TARGET=linux cprt0.o
Finally copy the file rtl/units/aarch64-linux/cport0.o to /usr/local/lib/fpc/3.2.2/units/aarch64-linux/rtl/cprt0.o, replacing the original file there.

dbannon

  • Hero Member
  • *****
  • Posts: 2791
    • tomboy-ng, a rewrite of the classic Tomboy
Re: linking errors compiling on aarch64
« Reply #6 on: March 30, 2022, 12:58:51 am »
Wow, so that means that as the new glibc is rolled out, we can expect FPC to stop working on  aarch64, ppc64le and even poor old i386 ?

Thats going to be interesting ....

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: linking errors compiling on aarch64
« Reply #7 on: March 30, 2022, 08:54:42 am »
Wow, so that means that as the new glibc is rolled out, we can expect FPC to stop working on  aarch64, ppc64le and even poor old i386 ?

FPC itself will continue to work, cause it doesn't link to the C library on Linux. However anything that links in the C library will trigger this. This is something we'll have to fix before 3.2.4 is released.

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
Re: linking errors compiling on aarch64
« Reply #8 on: March 30, 2022, 05:32:50 pm »
any help would be appreciated

This is a known problem. To solve it you need the source code for FPC 3.2.2 if you don't have it already. There you navigate to rtl/linux/aarch64 and edit the file cprt0.as (around line 40):

Code: ASM  [Select][+][-]
  1.         /* __libc_start_main(main, argc, argv,
  2.                              init, fini, rtld_fini, stack_end) */
  3.         adrp    x0,:got:PASCALMAIN
  4.         ldr     x0,[x0,#:got_lo12:PASCALMAIN]
  5.         adrp    x3,:got:__libc_csu_init
  6.         ldr     x3,[x3,#:got_lo12:__libc_csu_init]
  7.         adrp    x4,:got:__libc_csu_fini
  8.         ldr     x4,[x4,#:got_lo12:__libc_csu_fini]
  9.         bl      __libc_start_main
  10.  

Replace this with the following:

Code: ASM  [Select][+][-]
  1.         /* __libc_start_main(main, argc, argv,
  2.                              init, fini, rtld_fini, stack_end) */
  3.         adrp    x0,:got:PASCALMAIN
  4.         ldr     x0,[x0,#:got_lo12:PASCALMAIN]
  5.         mov     x3,xzr
  6.         mov     x4,xzr
  7.         bl      __libc_start_main
  8.  

And then go one directory up (to rtl/linux) and execute

Code: [Select]
make CPU_TARGET=aarch64 OS_TARGET=linux cprt0.o
Finally copy the file rtl/units/aarch64-linux/cport0.o to /usr/local/lib/fpc/3.2.2/units/aarch64-linux/rtl/cprt0.o, replacing the original file there.

this worked thanks.
The only note I would add for future victims is that in Manjaro that the source is in /usr/lib/fpc/src and that once the new cprt is compiled the command to actually install it is then (if you installed fpc, fpc-src and lazarus using the package manager):-
Code: [Select]
cp /usr/lib/fpc/src/rtl/units/aarch64-linux/cprt0.o /usr/lib/fpc/3.2.2/units/aarch64-linux/rtl/

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
Re: linking errors compiling on aarch64
« Reply #9 on: March 30, 2022, 06:54:02 pm »
I reported it as a bug here
https://bugs.archlinux.org/task/74281

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
Re: linking errors compiling on aarch64
« Reply #10 on: March 30, 2022, 11:57:01 pm »
I reported it as a bug here
https://bugs.archlinux.org/task/74281

Which looped right back round to here.

Arch say that it's nothing to do with them because I'm running Manjaro, and Manjaro say that fpc isn't developed by them so they won't do anything.

Basically I need to somehow find out who is the package maintainer for fpc on Manjaro.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: linking errors compiling on aarch64
« Reply #11 on: March 31, 2022, 12:44:04 am »
Hi!

The trouble with crtbegin.o and ctrend.o on Manjaro we had before:

https://forum.lazarus.freepascal.org/index.php/topic,56114.msg417087.html#msg417087

Winni

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: linking errors compiling on aarch64
« Reply #12 on: March 31, 2022, 09:02:00 am »
Basically I need to somehow find out who is the package maintainer for fpc on Manjaro.

There is nothing that the distros can do here. This needs to be fixed by us and then you'll need to wait for 3.2.4.

 

TinyPortal © 2005-2018