Recent

Author Topic: Unused code in linked program (Mac OS)  (Read 3859 times)

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Unused code in linked program (Mac OS)
« on: December 08, 2019, 10:28:24 pm »
Hi,

Using FPC 3.0.4 / x86_64 Mac OS.

Are unused procedures/functions (esp. in units) removed from the final build?

(Note the only build option I typically use is optimize 3 (-O3)).

Thanks!
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Unused code in linked program (Mac OS)
« Reply #1 on: December 08, 2019, 10:32:53 pm »
Yes, but there are some exceptions and other details, see e.g. this postof mine for a short description

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: Unused code in linked program (Mac OS)
« Reply #2 on: December 08, 2019, 10:43:24 pm »
Thanks!
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Unused code in linked program (Mac OS)
« Reply #3 on: December 09, 2019, 01:02:52 am »
If concerned about the size of your executable, I've recently found that running strip on the executable on macOS reduced the size of my executable from 12,959,144 bytes  to 7,221,928 bytes!

Quote
strip  removes or modifies the symbol table attached to the output of the assembler
and link editor.  This is useful to save space after a program  has  been  debugged
and to limit dynamically bound symbols.

man strip for more details.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Unused code in linked program (Mac OS)
« Reply #4 on: December 09, 2019, 01:58:40 am »
That still looks big..

did you use the External Debug file option when building the program ?

Or is your program very very huge ?

 I ask that because I have a rather large application that does a lot and its only about < 3 megs on a 32 bit target..

 It uses a lot of dynamic memory when operating but that's beside the point.
The only true wisdom is knowing you know nothing

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Unused code in linked program (Mac OS)
« Reply #5 on: December 09, 2019, 08:10:24 am »
No debugging info in the executable. Application is not that big for macOS 64 bit Cocoa.

Turned on "Link smart (-XX)" in project options and the size is now 5,357,360 bytes and after stripping 3,446,448 bytes.

Changing the compiler optimisation level from -O1 to -O3 had no effect.

Enabling Smart linkable (-CX) also had no effect.

Thanks for posting -- I'd never investigated the final binary size before!

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Unused code in linked program (Mac OS)
« Reply #6 on: December 09, 2019, 12:51:22 pm »
Using -XX on its own can be misleading: use -XXs  -CX -Os
You should see a noticeable difference
Specialize a type, not a var.

guest64953

  • Guest
Re: Unused code in linked program (Mac OS)
« Reply #7 on: December 09, 2019, 02:14:51 pm »
Using -XX on its own can be misleading: use -XXs  -CX -Os
You should see a noticeable difference

I'm on OpenIndiana and DFBSD and would confirm it's has no effect  8-)
The only way to reduce binary size is run strip --strip-all binaryfile  8)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Unused code in linked program (Mac OS)
« Reply #8 on: December 09, 2019, 02:37:01 pm »
Using -XX on its own can be misleading: use -XXs  -CX -Os
You should see a noticeable difference

I'm on OpenIndiana and DFBSD and would confirm it's has no effect  8-)
The only way to reduce binary size is run strip --strip-all binaryfile  8)

The line by Thaddy tells the linker to strip. Apparently the linker doesn't and only a separate strip command does.

Solution: fix linker.

guest64953

  • Guest
Re: Unused code in linked program (Mac OS)
« Reply #9 on: December 09, 2019, 03:59:04 pm »
Using -XX on its own can be misleading: use -XXs  -CX -Os
You should see a noticeable difference

I'm on OpenIndiana and DFBSD and would confirm it's has no effect  8-)
The only way to reduce binary size is run strip --strip-all binaryfile  8)

The line by Thaddy tells the linker to strip. Apparently the linker doesn't and only a separate strip command does.

Solution: fix linker.
Linker is shipped by the platform itself. How to fix?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Unused code in linked program (Mac OS)
« Reply #10 on: December 09, 2019, 04:12:27 pm »
Linker is shipped by the platform itself. How to fix?

Ask platform maintainers. File a bug with their systems.

guest64953

  • Guest
Re: Unused code in linked program (Mac OS)
« Reply #11 on: December 13, 2019, 04:53:19 am »
Linker is shipped by the platform itself. How to fix?

Ask platform maintainers. File a bug with their systems.

 ;D

The fault should be yours, for generating incompatible or faulty ld script or do not adapt to platform specific parameters but not the other way around. Run man ld on these different platforms and you will see how different it is in the way how it work and the parameters it use. Just because it's named binutils or the binary name is ld and being used/available across many system doesn't mean it's all the same binutils/ld on Linux. They're not using the plain binutils, they patched it, forked it... they added their own customization... Your problem is you're so Linux centric so you bring all of this linuxism expectation to other platform  ;D

I think we are a bit disrepect other system other than the main ones (Win, Lin and Mac). If it's Mac will you ask Apple to patch their linker to allow fpc to work correctly or you have to patch fpc to be work correctly with Apple's linker and adapt yourself to Apple's way, too? Just because Mac is a popular one so we have to support it, to follow it and other system is less popular so we think we should force them to patch their own only to allow our software to work correctly? It will not happen. fpc is not that important, gcc is another story, though. No one will answer to your bug report at all, they already have so many of them openning, so many important problems to care about  8-)

guest64953

  • Guest
Re: Unused code in linked program (Mac OS)
« Reply #12 on: December 13, 2019, 04:59:43 am »
Bonus: only fpc have problem generating too big binary because of linking too much unused library. gcc and g++ compiled program doesn't suffer from this, so this can't be the fault of the linker but fpc itself  ;)

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Unused code in linked program (Mac OS)
« Reply #13 on: December 13, 2019, 05:10:59 am »
Bonus: only fpc have problem generating too big binary because of linking too much unused library. gcc and g++ compiled program doesn't suffer from this, so this can't be the fault of the linker but fpc itself  ;)
That is not the case.  I have a few programs originally written in C, compiled with gcc and g++ that are eight [8] times larger than the FPC version.

If anything, it is much easier to write library independent code with FPC than with many of today's popular C/C++ compilers.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

guest64953

  • Guest
Re: Unused code in linked program (Mac OS)
« Reply #14 on: December 13, 2019, 05:24:07 am »
Bonus: only fpc have problem generating too big binary because of linking too much unused library. gcc and g++ compiled program doesn't suffer from this, so this can't be the fault of the linker but fpc itself  ;)
That is not the case.  I have a few programs originally written in C, compiled with gcc and g++ that are eight [8] times larger than the FPC version.

If anything, it is much easier to write library independent code with FPC than with many of today's popular C/C++ compilers.

And you are using Linux, don't you?  ;) Please read about the linuxism I said above. We're not using Linux like you, so your experience not apply  ;D

p/s: Oh, you are using Windows. MinGW compiled binary is notoriously known as big and bloated on Windows, you should have compare with MSVC or Pelles C compiled binary to be fair  :P

 

TinyPortal © 2005-2018