Recent

Author Topic: [SOLVED] Segmentation fault with console app  (Read 16000 times)

clauslack

  • Sr. Member
  • ****
  • Posts: 275
[SOLVED] Segmentation fault with console app
« on: December 12, 2009, 11:21:21 pm »
I upgrade from kernel 2.4.36 to 2.6.31.6 SMP
and all console application now
show
Segmentation fault

Intel(R) Pentium(R) Dual  CPU  E2160  @ 1.80GHz
kernel 2.6.31.6 SMP
in /var/log/messages show
Dec 12 18:35:25 linuxscsi kernel: project1[1343]: segfault at 21 ip 00000021 sp bf9d3144 error 4 in project1[8048000+4d000]

project1 has a simple writeln('hola')

but with kernel 2.4 works fine

Any Idea?
SMP and Freepascal not work?
Dosemu not work too. but other app work fine (samba, firebird, lighttpd, etc)

Thanks


« Last Edit: December 26, 2009, 03:08:16 pm by clauslack »

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Re: Segmentation fault with console app
« Reply #1 on: December 14, 2009, 12:34:29 pm »
Console apps sure run on those machines (remeber the compiler itself is also a console app)

What is your console app doing ? what happens if you run it in gdb ?
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: Segmentation fault with console app
« Reply #2 on: December 14, 2009, 02:08:15 pm »
Under Intel(R) Pentium(R) Dual  CPU  E2160  @ 1.80GHz with kernel 2.4 (without smp) all console app run fine.
When I compile the linux kernel 2.6.31.6 with SMP support; all console app. show segmentation fault, even a simple writeln('hello world')
FreePascal is not instaled in this machine.

In other Linux 2.6 (with SMP) work fine.

I will test with gdb
and
I will recompile the kernel 2.6 without SMP and try again.

Thanks




marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12708
  • FPC developer.
Re: Segmentation fault with console app
« Reply #3 on: December 14, 2009, 04:34:36 pm »
Under Intel(R) Pentium(R) Dual  CPU  E2160  @ 1.80GHz with kernel 2.4 (without smp) all console app run fine.
When I compile the linux kernel 2.6.31.6 with SMP support; all console app. show segmentation fault, even a simple writeln('hello world')
FreePascal is not instaled in this machine.

In other Linux 2.6 (with SMP) work fine.

Heaps of people run FPC on multicore machines, so I wouldn't automatically assume it is that.
 
A gdb trace would be best.

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: Segmentation fault with console app
« Reply #4 on: December 20, 2009, 07:55:51 pm »
Hi
With cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Pentium(R) Dual  CPU  E2160  @ 1.80GHz

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Pentium(R) Dual  CPU  E2160  @ 1.80GHz

The SMP works.
I use prelocompiled SMP kernel 2.6.27 from Slackware, all app. work (with processor M486).
But if I compile the kernel 2.6.31.8 with processor MPentium3, all app. from freepascal show Segmentation fault. Firebird, Samba (works)

Look like freepascal app. not work with SMP Pentium3, but work with SMP 486.
The app. is a simple writeln('Hola).
Here is the backtrace.
Quote
GNU gdb (GDB) 7.0
Copyright (C) 2009 Free Software Foundation, Inc.
Starting program: /home/claudio/bases/temp/syscami-bin/pro386

Program received signal SIGSEGV, Segmentation fault.
0x00000021 in ?? ()
(gdb) bt
#0  0x00000021 in ?? ()
#1  0x080484dc in SYSTEM_FPSYSCALL$LONGINT$LONGINT$LONGINT$$LONGINT ()
#2  0x08048b3e in SYSTEM_FPUGETRLIMIT$LONGINT$PRLIMIT$$LONGINT ()
#3  0x0805f547 in SYSTEM_CHECKINITIALSTKLEN$LONGWORD$$LONGWORD ()
#4  0x00000000 in ?? ()
(gdb)

I will test compile kernel 2.6.31.8 with SMP M686 (PentiumPro).

Some cthreads problem???
Any idea?

Regards

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Re: Segmentation fault with console app
« Reply #5 on: December 21, 2009, 12:50:59 am »
A simple app doesn't use threads and runs on one core. You're looking in the wrong direction. FPC has run for years (and still runs) on my dual PIII
The dump you gave doesn't look like a simple hello world. Can you paste the source ?
« Last Edit: December 21, 2009, 12:53:31 am by Marc »
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: Segmentation fault with console app
« Reply #6 on: December 21, 2009, 02:05:00 am »
@Marc
What kernel version do you have?

With kernel 2.6.31.9 SMP M486/MPentium/MPentium3 freepascal app. not work.
But with a precompiled kernel 2.6.27.8 SMP M486 freepascal app.work; in the same machine.

I have many console app. build with fpc 2.2.4(cgi, database), all show segmentation fault IP:21.

Code: [Select]
program Project1;
{$mode objfpc}{$H+}
uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };
{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}
begin
writeln('Hola');
end.

I take the .config (working) from 2.6.27.8 and compiled with 2.6.31.9, and not work. I use gcc 3.2 (I read kernel Documentation/Changes)

I will compile other kernel version, for try find the problem.

Regards




Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Re: Segmentation fault with console app
« Reply #7 on: December 21, 2009, 11:32:51 am »
I'm running 2.6.26.8-57.fc8
Still need to upgrade some day
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Bart

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Re: Segmentation fault with console app
« Reply #8 on: December 22, 2009, 12:03:16 am »
What happens if you make an even smaller app.
Skip all uses clauses for example.

Code: [Select]
program foo;
{$mode objfpc}
begin
end.

or

Code: [Select]
program foo;
{$mode objfpc}
begin
  writeln('Hello World');
end.

Bart

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: Segmentation fault with console app
« Reply #9 on: December 22, 2009, 01:08:35 am »

ok, I will test that. (Maybe with a disassembler)

After check with other version of kernel 2.6 SMP.

Regards



clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: [SOLVED] Segmentation fault with console app
« Reply #10 on: December 26, 2009, 02:49:11 pm »
After many, many, many test (kernel compilations) I found the two problem.

1) FreePascal App. show Segmentation Fault with kernel 2.6 SMP.
2) Dosemu non root show Segmentation Fault with kernel 2.6 SMP.

Case
1) The problem was the kernel compiled with gcc 3.2.2, finally upgrade to gcc 3.3.6 and works!! (only  affect to fpc app.)
Code: [Select]
0804841D:<SYSTEM_INITSYSCALLINTF+0x1d>  83C004               add eax, 0x4
ald> s
eax = 0xBFBF7F30 ebx = 0x00000001 ecx = 0x00000001 edx = 0x00000000
esp = 0xBFBF7E8C ebp = 0xBFBF7EA8 esi = 0x00000007 edi = 0x00000000
ds  = 0x007B es  = 0x007B fs  = 0x0000 gs  = 0x0000
ss  = 0x007B cs  = 0x0073 eip = 0x08048420 eflags = 0x00000296

Flags: PF AF SF IF

08048420:<SYSTEM_INITSYSCALLINTF+0x20>  8B10                 mov edx, dword [eax]
ald> examine 0xbfbf7f30
Dumping 64 bytes of memory starting at 0xBFBF7F30 in hex
BFBF7F30:  20 00 00 00 21 00 00 00 10 00 00 00 FF FB EB BF     ...!...........
//
Here save 0x21

ald> disas 0x0804841d (maybe procedure InitSyscallIntf; rtl/linux/i386/syscall.inc)
0804841D:<SYSTEM_INITSYSCALLINTF+0x1d>  83C004               add eax, 0x4
08048420:<SYSTEM_INITSYSCALLINTF+0x20>  8B10                 mov edx, dword [eax]
08048422:<SYSTEM_INITSYSCALLINTF+0x22>  83FA20               cmp edx, 0x20
08048425:<SYSTEM_INITSYSCALLINTF+0x25>  7519                 jne +0x19 (0x8048440:SYSTEM_INITSYSCALLINTF+0x40)
08048427:<SYSTEM_INITSYSCALLINTF+0x27>  8B5004               mov edx, dword [eax+0x4]
//here save bad pointer 0x21
0804842A:<SYSTEM_INITSYSCALLINTF+0x2a>  8915B4540908         mov dword [+0x80954b4], edx
08048430:<SYSTEM_INITSYSCALLINTF+0x30>  85D2                 test edx, edx
08048432:<SYSTEM_INITSYSCALLINTF+0x32>  7415                 je +0x15 (0x8048449:SYSTEM_INITSYSCALLINTF+0x49)
08048434:<SYSTEM_INITSYSCALLINTF+0x34>  C705B054090801000000 mov dword [+0x80954b0], 0x1
0804843E:<SYSTEM_INITSYSCALLINTF+0x3e>  EB09                 jmp short +0x9 (0x8048449:SYSTEM_INITSYSCALLINTF+0x49)
08048440:<SYSTEM_INITSYSCALLINTF+0x40>  83C008               add eax, 0x8
08048443:<SYSTEM_INITSYSCALLINTF+0x43>  8B10                 mov edx, dword [eax]
08048445:<SYSTEM_INITSYSCALLINTF+0x45>  85D2                 test edx, edx
08048447:<SYSTEM_INITSYSCALLINTF+0x47>  75D7                 jne +0xd7 (0x8048520:SYSTEM_FPSYSCALL$LONGINT$LONGINT$LONGINT$LONGINT$$LONGINT+0x20)
08048449:<SYSTEM_INITSYSCALLINTF+0x49>  C3       
// Try to run invalid 0x21
080484D6:<SYSTEM_FPSYSCALL$LONGINT$LONGINT$LONGINT$$LONGINT+0x16>  FF15B4540908         call near dword [+0x80954b4]
ald> s
eax = 0x000000BF ebx = 0x00000003 ecx = 0xBFAEFD6C edx = 0x00000003
esp = 0xBFAEFD54 ebp = 0xBFAEFD60 esi = 0x00040000 edi = 0x00000000
ds  = 0x007B es  = 0x007B fs  = 0x0000 gs  = 0x0000
ss  = 0x007B cs  = 0x0073 eip = 0x00000021 eflags = 0x00000202

Flags: IF


Error disassembling next instruction (address: 0x00000021)

Dumping 64 bytes of memory starting at 0x080954B4 in hex
080954B4:  21 00 00 00 00 00 8D B6 00 00 00 00 00 00 00 00    !...............
//
rtl/linux/system.pp
{$if defined(i386) and not defined(FPC_USE_LIBC)}
  InitSyscallIntf;
{$endif}

Case
2) The kernel 2.6.31.9 has the option    CONFIG_DEFAULT_MMAP_MIN_ADDR=4096, must be 0 for dosemu.
or echo 0 > /proc/sys/vm/mmap_min_addr
http://kernel.xc.net/html/linux-2.6.31/x86/DEFAULT_MMAP_MIN_ADDR

Now all work 100% :), Intel dual core, kernel 2.6.31.9 SMP 32bits compiled for Pentium3.

Thanks


 

TinyPortal © 2005-2018