Recent

Author Topic: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.  (Read 1362 times)

Cyrax

  • Hero Member
  • *****
  • Posts: 624
I'm using FPC trunk.

In short; when building a cross compiler for 32-bit Windows, there is no support for SEH exception handling even -dTEST_WIN32_SEH is added at make build options. This will cause e.g 32-bit DoubleCommander to quit unexpectedly shortly after it is executed under 32-bit Wine environment. No error messages are displayed.

PascalDragon

  • Full Member
  • ***
  • Posts: 206
  • Compiler Developer
Re: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.
« Reply #1 on: October 07, 2018, 10:44:18 am »
How did you build the cross compiler? A "make clean all OS_TARGET=win32 CPU_TARGET=i386 OPT=-dTEST_WIN32_SEH" should be the way to do it. Does a simple test application raising and catching an exception work? Does it work on Windows?

Cyrax

  • Hero Member
  • *****
  • Posts: 624
Re: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.
« Reply #2 on: October 07, 2018, 04:54:42 pm »
I use this make command line to build the cross compiler:
Code: Pascal  [Select]
  1. make all OS_TARGET=win32 CPU_TARGET=i386 OPT="-gw2 -godwarfsets -godwarfmethodclassprefix -gl -O- -Xs- -Si- -vbq -Sew- -dEXTDEBUG -Xd -Fl/usr/lib32 -dTEST_WIN32_SEH" COMPILER_OPTIONS="-gw2 -godwarfsets -godwarfmethodclassprefix -gl -O- -Xs- -Si- -vbq -dEXTDEBUG -Sew- -Xd -Fl/usr/lib32 -dTEST_WIN32_SEH" FPC=fpc REVSTR=39872 UPXPROG=echo NOWPOCYCLE=1 ALLOW_WARNINGS=1

Cyrax

  • Hero Member
  • *****
  • Posts: 624
Re: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.
« Reply #3 on: October 07, 2018, 05:55:34 pm »
In attached file (project1.zip) you will find test project.

Under Wine 32-bit it will output following text :
Code: Pascal  [Select]
  1. An unhandled exception occurred at $004016ED:
  2. EDivByZero: Division by zero
  3.   $004016ED  main,  line 20 of project1.lpr

Under Wine 64-bit it will output following text :
Code: Pascal  [Select]
  1. Windows 32/64-bit SEH is used.
  2. Division by zero

I also attached project1.s assembler file for respective OSes.

PascalDragon

  • Full Member
  • ***
  • Posts: 206
  • Compiler Developer
Re: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.
« Reply #4 on: October 07, 2018, 06:58:15 pm »
Your Win32 assembly code does not show that it has been compiled with a SEH-enabled compiler. You should see accesses to %fs:(x) instead of fpc_setjmp in the assembly output. Your output however should already have told you that however as the "Windows 32/64-bit SEH is used" line is missing.

I also compiled a cross compiler from Linux to Windows locally (though only with -dTEST_WIN32_SEH as option) and your example came out without any problems. So you should probably check whether something in your building went wrong.

Also a few notes regarding your build line:
- COMPILER_OPTIONS is only needed if you want to add options *only* for the compiler; however the options passed to OPT are passed to the compiler as well, so passing the same values is superfluous
- UPXPROG is not required anymore as we've removed UPX support some time ago already
- passing ALLOW_WARNINGS and -Sew- is essentially the same as well


Cyrax

  • Hero Member
  • *****
  • Posts: 624
Re: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.
« Reply #5 on: October 08, 2018, 01:52:17 am »
If I leave ALLOW_WARNINGS=1 out, compilation process will stop with this error :
Code: Pascal  [Select]
  1. fpc -Ur -Xs -O2 -n -Fui386 -Fusystems -Fu/mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/rtl/units/i386-linux -Fii386 -FE. -FUi386/units/i386-linux -dRELEASE -gw2 -godwarfsets -godwarfmethodclassprefix -gl -O- -Xs- -Si- -vbq -Sew- -dEXTDEBUG -Xd -Fl/usr/lib32   -di386 -dGDB -dBROWSERLOG -Fux86 -Sew pp.pas
  2. Compiling Release Version
  3. Free Pascal Compiler version 3.0.4-r37149 [2018/02/11] for i386
  4. Copyright (c) 1993-2017 by Florian Klaempfl and others
  5. (1002) Target OS: Linux for i386
  6. (3104) Compiling pp.pas
  7. (3104) Compiling catch.pas
  8. (3104) Compiling verbose.pas
  9. (3104) Compiling cutils.pas
  10. (3104) Compiling constexp.pas
  11. (3104) Compiling globtype.pas
  12. (3104) Compiling finput.pas
  13. (3104) Compiling cclasses.pas
  14. (3104) Compiling cstreams.pas
  15. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1141,10) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): temprefn
  16. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1141,10) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): blockn
  17. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1141,18) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): temprefn
  18. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1141,18) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): blockn
  19. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1140,14) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): temprefn
  20. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1140,14) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): blockn
  21. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1147,10) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): temprefn
  22. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1147,10) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): blockn
  23. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1146,14) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): temprefn
  24. /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler/cclasses.pas(1146,14) Warning: Location (LOC_REG) not equal to expectloc (LOC_CREG): blockn
  25. cclasses.pas(3186) Fatal: (10026) There were 10 errors compiling module, stopping
  26. Fatal: (1018) Compilation aborted
  27. Error: /mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/i386/release/3.0.4/binary/release/bin/i386-linux/ppc386 returned an error exitcode
  28. make[5]: *** [Makefile:4329: ppc386] Error 1
  29. make[4]: *** [Makefile:4375: next] Error 2
  30. make[3]: *** [Makefile:4379: ppc1] Error 2
  31. make[2]: *** [Makefile:4391: cycle] Error 2
  32. make[1]: *** [Makefile:2824: compiler_cycle] Error 2
  33. make: *** [Makefile:2856: build-stamp.i386-linux] Error 2
  34. make[5]: Leaving directory '/mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler'
  35. make[4]: Leaving directory '/mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler'
  36. make[3]: Leaving directory '/mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler'
  37. make[2]: Leaving directory '/mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source/compiler'
  38. make[1]: Leaving directory '/mnt/UUSI_OHJELMOINTI/ohjelmointi/pascal/binaries/fpc/source/git_source'
  39.  

PascalDragon

  • Full Member
  • ***
  • Posts: 206
  • Compiler Developer
Re: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.
« Reply #6 on: October 08, 2018, 07:42:45 am »
Then disable -dEXTDEBUG. That define is only really needed when debugging nasty problems inside the compiler.

Cyrax

  • Hero Member
  • *****
  • Posts: 624
Re: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.
« Reply #7 on: October 08, 2018, 07:49:57 am »
Okay, now I know what was wrong. I didn't pass -dTEST_WIN32_SEH to build environment when targeting solely linux i386 .  I did pass that option only when trying to build the cross compiler. That was the reason why it didn't work at first place.   %)

Now everything works when I use -dTEST_WIN32_SEH in both cases.  :)

Thanks PascalDragon for trying to help me, but it was an user error.

PascalDragon

  • Full Member
  • ***
  • Posts: 206
  • Compiler Developer
Re: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.
« Reply #8 on: October 08, 2018, 04:13:41 pm »
To be fair I had already thought that it's a user error after I tested it myself  :-[

Maybe it's time to switch trunk to Win32 SEH by default...

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6617
Re: Cross compiler (from 32-bit linux to 32-bit Windows) SEH problem.
« Reply #9 on: October 08, 2018, 05:20:28 pm »
Maybe it's time to switch trunk to Win32 SEH by default...

PLEASE YES! :-)