Recent

Author Topic: [SOLVED] How to get rid of linker option --gc-sections  (Read 1113 times)

Nevada Smith

  • New Member
  • *
  • Posts: 20
[SOLVED] How to get rid of linker option --gc-sections
« on: May 16, 2022, 07:06:43 am »
I am trying to statically link portaudio in Windows. I am using the libportaudio.a file obtained through MSYS2. I had to jump through a few hoops, but I am there, I think, almost.

Please note that I have specified -Xe option to use external linker.

The linker runs with the below options, but errors out, without any specific message. It exits with a non-zero return code (%ERRORLEVEL%) and the executable generate has a size of 0 bytes.


ld.exe -b pei-x86-64  --gc-sections  -s --subsystem windows --entry=_WinMainCRTStartup    -o D:\pdev\fpc\g_catbell\vc\src\catbell.exe D:\pdev\fpc\g_catbell\vc\src\link.res


However, I have been able to link it successfully if I omit the flag --gc-sections. The executable although not extensively tested, appears to run fine.

I tried to use add --no-gc-sections through Project Options > Compilation and Linknig > Pass options to linker with "-k" option, but the command-line ends up having both --no-gc-sections and --gc-sections, in that order, and the latter overrides the former (I think).

Is there any way to get the flag --gc-sections omitted or overridden through the IDE?  Or at least through lazbuild?
« Last Edit: May 18, 2022, 08:49:33 pm by Nevada Smith »

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: How to get rid of linker option --gc-sections
« Reply #1 on: May 16, 2022, 07:52:36 am »
For the external linker, a linker script can be  created, so maybe you should edit that? Usually not recommended.
(-s option)
https://www.freepascal.org/docs-html/current/user/usersu71.html
https://www.freepascal.org/docs-html/current/user/usersu15.html#x38-450005.1.4
« Last Edit: May 16, 2022, 07:57:57 am by Thaddy »
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: How to get rid of linker option --gc-sections
« Reply #2 on: May 16, 2022, 09:35:56 am »
Disable smart linking.  (-XX)

Nevada Smith

  • New Member
  • *
  • Posts: 20
Re: How to get rid of linker option --gc-sections
« Reply #3 on: May 18, 2022, 08:48:20 pm »
Adding -s (-sh) to Custom options worked. It created a ppas.bat and stopped. I could then perform the actual linking on my own.

 

TinyPortal © 2005-2018