Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-04

Whole Program Optimization with FPC 2.6.0?

19 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Schreiber

Hi,
A minimal MSEgui program compiled with FPC 2.6.0 is 711KB on i386-win32 and 796KB on i386-linux.

I tried to optimize it with "Whole Program Optimization". On win32 I get:
"
Free Pascal Compiler version 2.6.0 [2011/12/25] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Win32 for i386
Compiling minimal.pas
[...]
Compiling main.pas
Compiling main_mfm.pas
Linking minimal.exe
minimal.pas(12,1) Error: Error during reading symbol liveness information produced by "E:\FPC\2.6.0\bin\i386-win32\objdump.exe -t " minimal.pas(12,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted
"
minimal.pas is
"
program minimal;
{$ifdef FPC}{$mode objfpc}{$h+}{$endif}
{$ifdef FPC}
{$ifdef mswindows}{$apptype gui}{$endif}
{$endif}
uses
{$ifdef FPC}{$ifdef linux}cthreads,{$endif}{$endif} msegui,mseforms,main;
begin
application.createform(tmainfo,mainfo);
application.run;
end.
"
^(12,1)

On Linux compiling works, there is a binary of 1.3MB after third run as described in
http://wiki.freepascal.org/Whole_Program_Optimization#Concrete_example After "strip -s" the size is 780KB.

Running the program crashes at startup with
"
An unhandled exception occurred at $080A1045 :
EAbstractError : Abstract method called
$080A1045
$0809B6F5
$0809AD8B
$080AF2AA
$080AEFC0
$080AE4D2
$0806FB92
$0805C884
$0804E48A
$0805FE70
$0804DF94
$0804DCFD
$0804DB2D

An unhandled exception occurred at $0804C2DF :
An unhandled exception occurred at $B7CE9B7A :
"
Should whole program optimization work with FPC 2.6.0?

Martin

Reply by email

Jonas Maebe
to Martin Schreiber
Martin Schreiber wrote 13 lines
I tried to optimize it with "Whole Program Optimization". On win32 I get: " Free Pascal Compiler version 2.6.0 [2011/12/25] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling minimal.pas [...] Compiling main.pas Compiling main_mfm.pas Linking minimal.exe minimal.pas(12,1) Error: Error during reading symbol liveness information produced by "E:\FPC\2.6.0\bin\i386-win32\objdump.exe -t "

From http://wiki.freepascal.org/Whole_Program_Optimization#Limitations_4 :

"This optimisation requires that the nm utility is installed on the system. For Linux binaries, objdump will also work."

On Linux compiling works, there is a binary of 1.3MB after third run as described in http://wiki.freepascal.org/Whole_Program_Optimization#Concrete_example After "strip -s" the size is 780KB.

On my Linux/i386 system it's 133kb after strip -s, and 261kb before. Have you recompiled the 2.6.0 rtl somehow?

Show quoted text 21 lines
Running the program crashes at startup with " An unhandled exception occurred at $080A1045 : EAbstractError : Abstract method called $080A1045 $0809B6F5 $0809AD8B $080AF2AA $080AEFC0 $080AE4D2 $0806FB92 $0805C884 $0804E48A $0805FE70 $0804DF94 $0804DCFD $0804DB2D An unhandled exception occurred at $0804C2DF : An unhandled exception occurred at $B7CE9B7A : "

Strange. This example is tested every night in the test suite runs and works fine there on Linux/i386: http://www.freepascal.org/testsuite/cgi-bin/testsuite.cgi?action=3&run1id=108780&testfileid=3122 . I've also just tested it on Linux/i386 (see above) and it works fine for me.

Should whole program optimization work with FPC 2.6.0?

Yes. The FPC 2.6.0 compiler binary itself is even compiled with whole program optimizations (although not with the symbol liveness information switch, because that requires smart linking and for historical reasons that's not enabled for the binaries we release).

Jonas

Reply by email

Jonas Maebe
to Jonas Maebe
Jonas Maebe wrote
On my Linux/i386 system it's 133kb after strip -s, and 261kb before. Have you recompiled the 2.6.0 rtl somehow?

If I recompile the RTL with Stabs or DWARF debug information, the binary becomes 606kb resp. 564kb before stripping, but still 133kb after. And it also continues to work.

Jonas

Reply by email

Martin Schreiber
to Jonas Maebe: From http://wiki.freepascal.org/Whole_Program_Optimization#Limitations_4 : "This…
Jonas Maebe wrote 20 lines
On 07 Apr 2012, at 12:31, Martin Schreiber wrote: > I tried to optimize it with "Whole Program Optimization". > On win32 I get: > " > Free Pascal Compiler version 2.6.0 [2011/12/25] for i386 > Copyright (c) 1993-2011 by Florian Klaempfl and others > Target OS: Win32 for i386 > Compiling minimal.pas > [...] > Compiling main.pas > Compiling main_mfm.pas > Linking minimal.exe > minimal.pas(12,1) Error: Error during reading symbol liveness information > produced by "E:\FPC\2.6.0\bin\i386-win32\objdump.exe -t " From http://wiki.freepascal.org/Whole_Program_Optimization#Limitations_4 : "This optimisation requires that the nm utility is installed on the system. For Linux binaries, objdump will also work."

Thanks, where can I get that "nm utility" for win32?

Show quoted text 8 lines
> On Linux compiling works, there is a binary of 1.3MB after third run as > described in > http://wiki.freepascal.org/Whole_Program_Optimization#Concrete_example > After "strip -s" the size is 780KB. On my Linux/i386 system it's 133kb after strip -s, and 261kb before. Have you recompiled the 2.6.0 rtl somehow?

The result is wit the MSEgui minimal program not the testprogram in the Wiki, sorry for confusion.

Show quoted text 28 lines
> Running the program crashes at startup with > " > An unhandled exception occurred at $080A1045 : > EAbstractError : Abstract method called > $080A1045 > $0809B6F5 > $0809AD8B > $080AF2AA > $080AEFC0 > $080AE4D2 > $0806FB92 > $0805C884 > $0804E48A > $0805FE70 > $0804DF94 > $0804DCFD > $0804DB2D > > An unhandled exception occurred at $0804C2DF : > An unhandled exception occurred at $B7CE9B7A : > " Strange. This example is tested every night in the test suite runs and works fine there on Linux/i386: http://www.freepascal.org/testsuite/cgi-bin/testsuite.cgi?action=3&run1id=1 08780&testfileid=3122 . I've also just tested it on Linux/i386 (see above) and it works fine for me.

It is the MSEgui minimal program not the example.

Show quoted text 7 lines
> Should whole program optimization work with FPC 2.6.0? Yes. The FPC 2.6.0 compiler binary itself is even compiled with whole program optimizations (although not with the symbol liveness information switch, because that requires smart linking and for historical reasons that's not enabled for the binaries we release).

Then I should try without symbol liveness information too?

Martin

Reply by email

Jonas Maebe
to Martin Schreiber
Martin Schreiber wrote
Thanks, where can I get that "nm utility" for win32?

Any distribution of the GNU binutils for win32 should include it. I don't have Windows myself, but I suppose the mingw site would be a good place to look for it.

It is the MSEgui minimal program not the example.

Then that looks like a bug in the optimization (unless you e.g. use pointer hacks to directly read the addresses of virtual methods from the VMT, in which case there is nothing the compiler can do about this).

The crash you posted means that a virtual method is getting called while the compiler/optimizer thought that it could never be called from the program.

Then I should try without symbol liveness information too?

You can try, yes. It shouldn't make a difference, but you never know.

Jonas

Reply by email

Martin Schreiber
to Jonas Maebe
Jonas Maebe wrote 7 lines
On 07 Apr 2012, at 13:15, Martin Schreiber wrote: > Thanks, where can I get that "nm utility" for win32? Any distribution of the GNU binutils for win32 should include it. I don't have Windows myself, but I suppose the mingw site would be a good place to look for it.

Thanks. The normally 711KB MSEgui win32 minimal program is 694KB after strip with -OWall/-Owall. There is an symbolliveness it is 697KB, there is an EAbstractError too.

Show quoted text 6 lines
> It is the MSEgui minimal program not the example. Then that looks like a bug in the optimization (unless you e.g. use pointer hacks to directly read the addresses of virtual methods from the VMT, in which case there is nothing the compiler can do about this).

AFAIK there is no direct VMT access in MSEgui. I assume gdb debugging with symbolinfo is not possible after whole program optimization? gdb shows:
"
(gdb) run
Starting program: /home/mse/proj/msegui/testcase/mse/minimal/minimal [Thread debugging using libthread_db enabled]
An unhandled exception occurred at $08075595 :
EAbstractError : Abstract method called
$08075595 line 1875 of main.pas
$08070455 line 1875 of main.pas
$0806FA7B line 1875 of main.pas
$080F4389 TWIDGET__HASOVERLAPPINGSIBLINGS, line 8588 of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/msegui.pas $08087711 LOADMODULE, line 1974
of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/mseclasses.pas $080867EC DOLOAD, line 2499
of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/mseclasses.pas $0808663E INITMSECOMPONENT, line 2521
of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/mseclasses.pas $0808504A LOADMSEMODULE, line 2636
of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/mseclasses.pas $080A15D0 TMSEDATAMODULE__CREATE, line 136
of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/msedatamodules.pas $080A77F4 INIT, line 293
of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/msestockobjects.pas $0807BC64 INIT, line 1661
of /home/mse/packs/standard/git/mseide-msegui/lib/common/graphics/msegraphics.pas $0805EC5F TGUIAPPLICATION__INTERNALINITIALIZE, line 16396 of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/msegui.pas $08082AF1 TCUSTOMAPPLICATION__INITIALIZE, line 1615 of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/mseapplication.pas $08081FD3 TCUSTOMAPPLICATION__CREATE, line 1046
of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/mseapplication.pas $0804E23F TGUIAPPLICATION__CREATE, line 16387
of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/msegui.pas $0804DF36 TINTERNALAPPLICATION__CREATE, line 14518 of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/msegui.pas $0804DD25 APPLICATION, line 3423
of /home/mse/packs/standard/git/mseide-msegui/lib/common/kernel/msegui.pas "
main.pas has 16 lines only, hasoverlappingsiblings is never called in minimal program.

Martin

Reply by email

Jonas Maebe
to Martin Schreiber
Martin Schreiber wrote
AFAIK there is no direct VMT access in MSEgui. I assume gdb debugging with symbolinfo is not possible after whole program optimization?

It should be no problem, only a few call instructions point to different places and some VMT entries are set to FPC_ABSTRACTERROR afterwards. However, debug information and smart linking don't work together very well.

Jonas

Reply by email

Tomas Hajny
to Jonas Maebe: Any distribution of the GNU binutils for win32 should include it. I don't have Windows…
Jonas Maebe wrote 5 lines
On 07 Apr 2012, at 13:15, Martin Schreiber wrote: > Thanks, where can I get that "nm utility" for win32? Any distribution of the GNU binutils for win32 should include it. I don't have Windows myself, but I suppose the mingw site would be a good place to look for it.

.
.

I guess that we should add nm.exe to our releases for Win32, Win64, GO32v2 and possibly also OS/2 then...

Tomas

Reply by email

Florian Klämpfl
to Tomas Hajny: . . I guess that we should add nm.exe to our releases for Win32, Win64, GO32v2 and…
Tomas Hajny wrote 10 lines
On 7 Apr 12, at 13:23, Jonas Maebe wrote: > On 07 Apr 2012, at 13:15, Martin Schreiber wrote: > >> Thanks, where can I get that "nm utility" for win32? > > Any distribution of the GNU binutils for win32 should include it. I don't have Windows myself, but I suppose the mingw site would be a good place to look for it. . . I guess that we should add nm.exe to our releases for Win32, Win64,

I'am on the way for them already.

Reply by email

Tomas Hajny
to Florian Klämpfl
Florian Klämpfl wrote 13 lines
Am 07.04.2012 18:19, schrieb Tomas Hajny: > On 7 Apr 12, at 13:23, Jonas Maebe wrote: >> On 07 Apr 2012, at 13:15, Martin Schreiber wrote: >> >>> Thanks, where can I get that "nm utility" for win32? >> >> Any distribution of the GNU binutils for win32 should include it. I don't have Windows myself, but I suppose the mingw site would be a good place to look for it. > . > . > > I guess that we should add nm.exe to our releases for Win32, Win64, I'am on the way for them already.

Alright, I added nm.exe to SVN for GO32v2 (from the same binutils version 2.17 as used for the other tools; there's also a DJGPP build of binutils 2.21 but that would probably require some testing first and I couldn't do that).

BTW, should we go to that version in the future, we need to add GPL version 3 license to our SVN tree in addition to the other license files (GPL3 is explicitly referenced in the version information).

Tomas

Reply by email

Martin Schreiber
to Martin Schreiber: BTW, the same MSEgui minimal program compiled with Delphi 7 has an exe size of 571KB.…
Martin Schreiber wrote 9 lines
Am 07.04.2012 11:31, schrieb Martin Schreiber: > Hi, > A minimal MSEgui program compiled with FPC 2.6.0 is 711KB on > i386-win32 and > 796KB on i386-linux. > BTW, the same MSEgui minimal program compiled with Delphi 7 has an exe size of 571KB.

I made MSEgit Delphi compatible too:

FPC 2.6.0: 1.92MB
Delphi 7: 1.61MB

Martin

Reply by email

Sergei Gorelkin
to Martin Schreiber

08.04.2012 11:33, Martin Schreiber пишет:

Show quoted text 15 lines
Am 07.04.2012 18:09, schrieb Martin Schreiber: > Am 07.04.2012 11:31, schrieb Martin Schreiber: >> Hi, >> A minimal MSEgui program compiled with FPC 2.6.0 is 711KB on >> i386-win32 and >> 796KB on i386-linux. >> > BTW, the same MSEgui minimal program compiled with Delphi 7 has an exe > size of 571KB. > I made MSEgit Delphi compatible too: FPC 2.6.0: 1.92MB Delphi 7: 1.61MB

You might want to compare with FPC 2.7.1 after revision 20119, it is expected to generate smaller code for string and other managed type operations. For Lazarus executable I got about 10% total size decrease.

Regards,
Sergei

Reply by email

Martin Schreiber
to Sergei Gorelkin
Sergei Gorelkin wrote 9 lines
> I made MSEgit Delphi compatible too: > > FPC 2.6.0: 1.92MB > Delphi 7: 1.61MB You might want to compare with FPC 2.7.1 after revision 20119, it is expected to generate smaller code for string and other managed type operations. For Lazarus executable I got about 10% total size decrease.

I can not use FPC 2.7.1 for the testcase because of cpstrnew, sorry.

Martin

Reply by email

Martin Schreiber
to Jonas Maebe
Jonas Maebe wrote 8 lines
On 07 Apr 2012, at 15:32, Martin Schreiber wrote: > Thanks. The normally 711KB MSEgui win32 minimal program is 694KB after > strip with -OWall/-Owall. There is an EAbstractError at startup. > Without symbolliveness it is 697KB, there is an EAbstractError too. The problem was that interface methods that map to virtual methods weren't taken into account. It's fixed in trunk.

Thanks! :-)
Will the fix be backported to fixes_2_6?

Martin

Reply by email

Jonas Maebe
to Martin Schreiber
Martin Schreiber wrote 7 lines
On Saturday 21 April 2012 14:22:45 Jonas Maebe wrote: > > The problem was that interface methods that map to virtual methods weren't > taken into account. It's fixed in trunk. > Thanks! :-) Will the fix be backported to fixes_2_6?

Yes, in a week or so.

Jonas

Reply by email

Jonas Maebe
to Jonas Maebe

Jonas Maebe wrote on Sat, 21 Apr 2012:

Show quoted text 11 lines
On 21 Apr 2012, at 18:34, Martin Schreiber wrote: > On Saturday 21 April 2012 14:22:45 Jonas Maebe wrote: >> >> The problem was that interface methods that map to virtual methods weren't >> taken into account. It's fixed in trunk. >> > Thanks! :-) > Will the fix be backported to fixes_2_6? Yes, in a week or so.

I merged it to the fixes branch last weekend.

Jonas

Reply by email