SIGSEGV error. lazarus / 13-General ---------------------------------------------------------------------- Elphi · 2005-12-29 16:38 Hello, When I run an application an exception is raised: External: SISSEGV I haven't got a clue where I should be looking for. What could be the cause of this? ---------------------------------------------------------------------- matthijs · 2005-12-29 18:50 Is this with any application you run or only with a certain application? If the latter, can you reproduce this in a small example? Going by the information you've given now, we can only guess. ---------------------------------------------------------------------- Anonymous · 2005-12-30 10:18 It is my first Lazarus application. The error surfaces when I include a unit in the uses clause of the main form. That unit uses a lot of units from my Delphi library which are ported in a quick and dirty manner. The IDE/application has been problemstic from the start. See for instance http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&fil e=viewtopic&t=1729 for example for another hurdle in this venture. Hope somebody has some hints what might be wrong. ---------------------------------------------------------------------- Elphi · 2005-12-30 11:31 Solved? In the initialization section of one of the library units the CPU type is determined. The header of the function used looked like this: Code: [Select]function CPU: Integer; assembler; asm   end; This compiled under: Code: [Select]{$mode objfpc} {$asmmode intel} Changed to: Code: [Select]function CPU: Integer; begin   asm         end; end; and I get no exception anymore. ---------------------------------------------------------------------- matthijs · 2005-12-30 11:49 That's something we could not guess. But you are correct, one needs begin ... end around asm-blocks if you are using objfpc-mode. ---------------------------------------------------------------------- Anonymous · 2005-12-30 12:01 Should it compile? I don't think so. ---------------------------------------------------------------------- Vincent Snijders · 2005-12-30 12:06 It depends on the body. Maybe you make assumptions in it that are not correct, if (begin..end) is missing, for example assumptions about the stack frame. ---------------------------------------------------------------------- Elphi · 2006-01-02 09:13 Im my view it is a typical case of syntax error that the compiler should handle. Here is the complete orginal routine including body: Code: [Select]function CPU: Integer; assembler; asm          push      bx                // Save bx          // cpu086 if bits 12-15 of flags are set          pushf                       // Save flags          pop       bx                // Save flags in bx          mov       ax,$0fff          // Clear bits 12-15          and       ax,bx             // in flags          push      ax                // Store new flags value on stack          popf                        // Replace current flags value          pushf                       // Set new flags          pop       ax                // Store new flags in ax          and       ax,$0f000         // If bits 12-15 are set then the CPU          cmp       ax,$0f000         // is (at least) a 8086/8088          jne       @186              // Higher processor          xor       ax,ax             // A 8086/8088: set family bits 11-8 to 000b                                      // Here test for FPU?          jmp       @Exit          //cpu186 How? @186:          // cpu286 if bits 12-15 are always clear @286:    or        bx,$0f000         // Try to set bits 12-15          push      bx          popf          pushf          pop       ax          pop       bx                // Restore bx as 16 bits tests will finish          and       ax,$0f000         // If bits 12-15 aren't cleared          jnz       @386              // then it is a higher processor          mov       ax,$200           // A 286: set family bits 11-8 to 010b                                      // Here test for FPU?          jmp       @Exit          // cpu386 if ac bit (bit 18) of eflags, introduced on the cpu486 can not be set @386:    pushfd          pop       eax               // Get original eflags          mov       ecx,eax           // Save original eflags          xor       eax,$40000        // Flip AC bit in eflags          push      eax               // Save for eflags          popfd                       // Copy to eflags          pushfd                      // Push eflags          pop       eax               // Get new eflags value          xor       eax,ecx           // If ac bit can be toggled          jne       @486              // then it is a higher processor          mov       eax,$300          // A 386: set family bits 11-8 to 011b                                      // Here test for FPU?          jmp       @Exit          // cpu486 id id bit (bit 21) of eflags, introduced on the cpu586 can not be set @486:    pushfd                      // Push original eflags          pop       eax               // Get original eflags in eax          mov       ecx,eax           // Save original eflags in ecx          or        eax,$200000       // Flip id bit in eflags          push      eax               // Save eax for eflags          popfd                       // Copy to eflags          pushfd                      // Push eflags          pop       eax               // Get new eflags value          xor       eax,ecx           // if  id bit can be changed          jne       @586              // then it is a higher processor          mov       eax,$400          // then the CPU is a 486                                      // Here test for FPU?          jmp       @Exit          // cpu586 and higher: cpuid instruction @586:    push      ebx               // Save ebx as it is affected by cpuid          xor       eax,eax           // Prepare for getting the number of cpuid functions db       $0f,$0a2                    // Cpuid instruction. Get number of cpuid function          pop       ebx               // Restore ebx          test      eax,eax           // If number > 0 then          jnz       @AutoF            // use cpuid to get features          mov       eax,$500          // If number = 0 then no functions available                                      // "Manually" setting features: - FPU (bit          jmp       @Exit @AutoF:  push      ebx               // Save ebx as it is affected by cpuid          mov       eax,1             // Prepare getting function 1 information db       $0f,$0a2                     // Cpuid instruction. Get family and features          pop       ebx               // Restore ebx          and       eax,$000000f00    // Family          and       edx,$0fffff0ff    // Features flags          or        eax,edx           // Combine family and features @Exit: end; {CPU} This case revealed other unexpected behavior: Code: [Select] function CPU: Integer; {$ifndef fpc}assembler; {$else} begin {$endif}   asm   {$ifdef fpc}    end; {$endif} end; doesn't work. One has to rewrite the complete routine in fpc syntax. ---------------------------------------------------------------------- Vincent Snijders · 2006-01-02 10:00 Quote from: "Elphi"One has to rewrite the complete routine in fpc syntax. That would be much work. Since it seems you are porting existing code, did you try adding {$mode Delphi} to the top of you source file? Vincent ---------------------------------------------------------------------- Elphi · 2006-01-02 11:12 No, mode objfpc. The application I'm writing is build from scratch. However it uses my Delphi library units extensively. The reasons why I'm using mode objfpc: 1. It was recommended somewhere in the docs to use mode Delphi only for the q&d ports. I have no intention to my leave my code in q&d state. 2. Considering the advice mentioned above, I expect mode Delphi to have drawbacks on size and speed of executables. 3. The main reason to use fpc right now is that it can build 64 bits executables. Please correct me if I'm wrong. In the mean time, I've seen this SIGSEGV error message more than once, so I expect the compiler is not yet ready to relentlessly throw syntax errors; mode delphi or mode objfpc shouldn't be a factor in this, I think. ---------------------------------------------------------------------- Vincent Snijders · 2006-01-02 11:56 support of mode Delphi is mostly syntax related. You can get the same size and speed as mode objfpc, although the compiler developers think that objfpc is more readable and maintainable. (You may disagree). Maybe you can discuss your issues on the fpc-pascal mailing list. ---------------------------------------------------------------------- Anonymous · 2006-01-02 12:15 So, basically what you are saying is that when I plan to use code interchangeably between Delphi and Lazarus mode delphi is advised, even when 64 bits/Linux is the main focus when using Lazarus? P.s. Unfortunately I'm one of those who have troubles reaching the fpc pages reading/posting on their forums. ---------------------------------------------------------------------- Vincent Snijders · 2006-01-02 12:27 Yes, if you are going to use the same source for both Delphi / win32 and Lazarus / linux / 64 bits, then I would recommand using mode Delphi. It should not have an effect on the code generation. The mode settings is purely syntax and setting defaults, like {$H+} and {$asmmode intel}, which are different in {mode objfpc}. Too bad, you cannot reach www.freepascal.org, so you cannot submit bug reports about syntax problems either. ---------------------------------------------------------------------- Anonymous · 2006-01-02 17:24 It's very annoying indeed when the fpc (community) pages are not reacheable or very slow. Did I notice an improvement today? I use Delphi mode now in all units, but I'm still flooded by messages concerning missing fpc include files.