Recent

Author Topic: error when linking lazarus: Argument list too long  (Read 2226 times)

kencu

  • Newbie
  • Posts: 3
error when linking lazarus: Argument list too long
« on: February 19, 2020, 04:48:16 am »
At MacPorts we are helping a dedicated Lazarus user bring in an easy-to-install version of Lazarus and fpc. However, we have noted some errors of late.

Linking large fpc projects, such as when building and installing Lazarus, is generating link errors on several different versions of macOS (10.7, 10.13 noted so far) with several different versions of the linker (ld64), due to "Argument list too long."

Code: [Select]
opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_lazarus/lazarus/work/lazarus/ide/main.pp(239,39) Hint: (5024) Parameter "Sender" not used
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_lazarus/lazarus/work/lazarus/ide/main.pp(240,40) Hint: (5024) Parameter "Sender" not used
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_lazarus/lazarus/work/lazarus/ide/main.pp(423,35) Hint: (5024) Parameter "Sender" not used
(9001) Assembling (pipe) ../units/x86_64-darwin/cocoa/main.s
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_lazarus/lazarus/work/lazarus/ide/lazarus.pp(75,5) Hint: (5023) Unit "FPCUnitTestRunner" not used in Lazarus
(9001) Assembling (pipe) ../units/x86_64-darwin/cocoa/lazarus.s
(9022) Compiling resource ../units/x86_64-darwin/cocoa/lazarus.or
(9015) Linking ../lazarus
./../ppaslink.sh: line 9: /opt/local/bin/ld: Argument list too long
An error occurred while linking
lazarus.pp(167) Error: (9013) Error while linking
lazarus.pp(167) Fatal: (10026) There were 1 errors compiling module, stopping
Fatal: (1018) Compilation aborted
make[2]: *** [lazarus] Error 1

This error appears similar to https://forum.lazarus.freepascal.org/index.php?topic=37068.0 noted a few years ago, where it appears to have been incompletely described and perhaps for that reason therefore not resolved. It can sometimes be overcome by by choosing a build directory with a shorter pathname, on the same system, with the same toolchain.

Code: [Select]
/opt/local/var/macports/build/_opt_macports-ports_devel_lazarus/lazarus/work/lazarus/ide/main.pp(239,39) Hint: (5024) Parameter "Sender" not used
/opt/local/var/macports/build/_opt_macports-ports_devel_lazarus/lazarus/work/lazarus/ide/main.pp(240,40) Hint: (5024) Parameter "Sender" not used
/opt/local/var/macports/build/_opt_macports-ports_devel_lazarus/lazarus/work/lazarus/ide/main.pp(423,35) Hint: (5024) Parameter "Sender" not used
(9001) Assembling (pipe) ../units/x86_64-darwin/cocoa/main.s
/opt/local/var/macports/build/_opt_macports-ports_devel_lazarus/lazarus/work/lazarus/ide/lazarus.pp(75,5) Hint: (5023) Unit "FPCUnitTestRunner" not used in Lazarus
(9001) Assembling (pipe) ../units/x86_64-darwin/cocoa/lazarus.s
(9022) Compiling resource ../units/x86_64-darwin/cocoa/lazarus.or
(9015) Linking ../lazarus
(1008) 293660 lines compiled, 205.4 sec
(1021) 30 warning(s) issued
(1022) 3082 hint(s) issued
(1023) 1 note(s) issued
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_macports-ports_devel_lazarus/lazarus/work/lazarus/ide'

Sometimes running the link script manually in the build directory will work, for reasons that I am not clear on, perhaps relating to the driver that calls the link script.

The file link.res that generates the error is indeed quite large, with most of the objects having full pathnames. It is `cat` ed onto the link line by the ppaslink.sh script.  I think it is simply exceeding the ARG_MAX of the system.
Code: [Select]
$ ls -la ../link.res
-rw-r--r--  1 macports  admin  243910 18 Feb 19:22 ../link.res
Many larger projects (Mozilla, etc) have come up against this same issue over the years. The solution seems to be to pass the objects as a filelist to the linker using -filelist .

Unfortunately it appears that the existing link.res file cannot simply be used to do that, as it contains other linker commands such as -arch and other library references that my reading says Apple's ld64 does not allow in the filelist files.

I'm not sure if the link.res file can use shorter relative pathnames for at least some objects, or if we can configure it to do so somehow. Or how, exactly, the logic that makes link.res could be altered in some fashion to have it separate the linker commands and the object references into separate files, and then use the linker's -filelist feature.

MacPorts could be altered in some fashion to use a shorter path to it's build directory, and this would probably help a bit, but that is not so simple to accomplish, and sooner or later fpc / lazarus would run up against this ARG_MAX issue again it seems.

Any thoughts much appreciated.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: error when linking lazarus: Argument list too long
« Reply #1 on: February 19, 2020, 09:08:54 am »
Any thoughts much appreciated.

Would you please try whether this occurs with FPC trunk as well? The way the linker is called was changed there in revision 43485 and if that solves your problem that fix might need to be merged to 3.2.

kencu

  • Newbie
  • Posts: 3
Re: error when linking lazarus: Argument list too long
« Reply #2 on: February 19, 2020, 05:19:29 pm »
That commit indeed appears to do what I had in mind; will report back...

kencu

  • Newbie
  • Posts: 3
Re: error when linking lazarus: Argument list too long
« Reply #3 on: August 10, 2020, 05:59:53 pm »
Confirming that upgrading fpc to 3.2.0 fixes this issue. thanks.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: error when linking lazarus: Argument list too long
« Reply #4 on: August 11, 2020, 09:34:21 am »
Thank you for confirming. :)

 

TinyPortal © 2005-2018