public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Segmentation fault before main
@ 2015-10-30 19:18 Marco Atzeri
  2015-10-30 21:23 ` Corinna Vinschen
  0 siblings, 1 reply; 7+ messages in thread
From: Marco Atzeri @ 2015-10-30 19:18 UTC (permalink / raw)
  To: cygwin

Hi Corinna,

as mention some time ago, testing netcdf 4.4.0 release candidates
I see a puzzling SIGSEGV before reaching main, so something goes wrong
on cygwin loading/inizialization of the program.

It happens in a simple test programs that is linked to
cygnetcdf-7.dll and its only job is to create a test file
called ctest0.nc.

Previous 4.3.3.1 test case runs fine.
The new ctest.c fails both with the new and with the old library.
Test case and binaries are here :
   http://matzeri.altervista.org/works/segfault/

$ gcc ctest.c -o ctest.exe -lnetcdf

$ gdb ./ctest.exe
(gdb) break main
Breakpoint 1 at 0x100401171
(gdb) run
Starting program: /cygdrive/e/cyg_pub/devel/netcdf/tests/ctest-440.exe
[New Thread 8404.0x18f4]
[New Thread 8404.0xa8c]
[New Thread 8404.0x2270]

Program received signal SIGSEGV, Segmentation fault.
___chkstk_ms () at 
/usr/src/debug/gcc-4.9.3-1/libgcc/config/i386/cygwin.S:146
146             orq     $0x0, (%rcx)            /* probe there */


$ uname -svrm
CYGWIN_NT-6.1 2.2.1(0.289/5/3) 2015-08-20 11:42 x86_64


libnetcdf-devel                         4.3.3.1-2
libnetcdf7                              4.3.3.1-2
netcdf                                  4.3.3.1-2
netcdf-debuginfo                        4.3.3.1-2


Unfortunately I have no clue about this code:

/* ___chkstk_ms is a *special* function call, which uses %rax as the 
argument.
    We avoid clobbering any registers.  Unlike ___chkstk, it just probes the
    stack and does no stack allocation.  */
         .global ___chkstk_ms
#ifdef __x86_64__
         cfi_startproc()
___chkstk_ms:
         pushq   %rcx                    /* save temps */
         cfi_push(%rcx)
         pushq   %rax
         cfi_push(%rax)
         cmpq    $0x1000, %rax           /* > 4k ?*/
         leaq    24(%rsp), %rcx          /* point past return addr */
         jb      2f

1:      subq    $0x1000, %rcx           /* yes, move pointer down 4k */
         orq     $0x0, (%rcx)            /* probe there */

Any help will be really appreciated.

Regards
Marco

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Segmentation fault before main
  2015-10-30 19:18 Segmentation fault before main Marco Atzeri
@ 2015-10-30 21:23 ` Corinna Vinschen
  2015-10-31 16:47   ` Marco Atzeri
  0 siblings, 1 reply; 7+ messages in thread
From: Corinna Vinschen @ 2015-10-30 21:23 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2680 bytes --]

On Oct 30 16:25, Marco Atzeri wrote:
> Hi Corinna,
> 
> as mention some time ago, testing netcdf 4.4.0 release candidates
> I see a puzzling SIGSEGV before reaching main, so something goes wrong
> on cygwin loading/inizialization of the program.
> 
> It happens in a simple test programs that is linked to
> cygnetcdf-7.dll and its only job is to create a test file
> called ctest0.nc.
> 
> Previous 4.3.3.1 test case runs fine.
> The new ctest.c fails both with the new and with the old library.
> Test case and binaries are here :
>   http://matzeri.altervista.org/works/segfault/
> 
> $ gcc ctest.c -o ctest.exe -lnetcdf
> 
> $ gdb ./ctest.exe
> (gdb) break main
> Breakpoint 1 at 0x100401171
> (gdb) run
> Starting program: /cygdrive/e/cyg_pub/devel/netcdf/tests/ctest-440.exe
> [New Thread 8404.0x18f4]
> [New Thread 8404.0xa8c]
> [New Thread 8404.0x2270]
> 
> Program received signal SIGSEGV, Segmentation fault.
> ___chkstk_ms () at
> /usr/src/debug/gcc-4.9.3-1/libgcc/config/i386/cygwin.S:146
> 146             orq     $0x0, (%rcx)            /* probe there */
> 
> 
> $ uname -svrm
> CYGWIN_NT-6.1 2.2.1(0.289/5/3) 2015-08-20 11:42 x86_64
> 
> 
> libnetcdf-devel                         4.3.3.1-2
> libnetcdf7                              4.3.3.1-2
> netcdf                                  4.3.3.1-2
> netcdf-debuginfo                        4.3.3.1-2
> 
> 
> Unfortunately I have no clue about this code:
> 
> /* ___chkstk_ms is a *special* function call, which uses %rax as the
> argument.
>    We avoid clobbering any registers.  Unlike ___chkstk, it just probes the
>    stack and does no stack allocation.  */
>         .global ___chkstk_ms
> #ifdef __x86_64__
>         cfi_startproc()
> ___chkstk_ms:
>         pushq   %rcx                    /* save temps */
>         cfi_push(%rcx)
>         pushq   %rax
>         cfi_push(%rax)
>         cmpq    $0x1000, %rax           /* > 4k ?*/
>         leaq    24(%rsp), %rcx          /* point past return addr */
>         jb      2f
> 
> 1:      subq    $0x1000, %rcx           /* yes, move pointer down 4k */
>         orq     $0x0, (%rcx)            /* probe there */
> 
> Any help will be really appreciated.

Well, it's a stack probe.  It's typically called when trying to allocate
big datastructures on the stack, e.g. with alloca.  Did you try to raise
the default stacksize in the executable header (see peflags -x and -X
options).  There's not much else to work with...


HTH,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Segmentation fault before main
  2015-10-30 21:23 ` Corinna Vinschen
@ 2015-10-31 16:47   ` Marco Atzeri
  2015-11-04 21:42     ` Marco Atzeri
  0 siblings, 1 reply; 7+ messages in thread
From: Marco Atzeri @ 2015-10-31 16:47 UTC (permalink / raw)
  To: cygwin

On 30/10/2015 20:18, Corinna Vinschen wrote:
> On Oct 30 16:25, Marco Atzeri wrote:
>> Hi Corinna,
>>

>> Any help will be really appreciated.
>
> Well, it's a stack probe.  It's typically called when trying to allocate
> big datastructures on the stack, e.g. with alloca.  Did you try to raise
> the default stacksize in the executable header (see peflags -x and -X
> options).  There's not much else to work with...
>
>
> HTH,
> Corinna

I increased it to 20M and was still failing; after I gave up.

Upstream mentioned a change to be implemented on the matter.
May be I was not the only one reporting it

Thanks
Marco








--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Segmentation fault before main
  2015-10-31 16:47   ` Marco Atzeri
@ 2015-11-04 21:42     ` Marco Atzeri
  2015-11-05  8:49       ` Csaba Raduly
  2015-11-05  9:21       ` Corinna Vinschen
  0 siblings, 2 replies; 7+ messages in thread
From: Marco Atzeri @ 2015-11-04 21:42 UTC (permalink / raw)
  To: cygwin

On 30/10/2015 20:45, Marco Atzeri wrote:
> On 30/10/2015 20:18, Corinna Vinschen wrote:
>> On Oct 30 16:25, Marco Atzeri wrote:
>>> Hi Corinna,
>>>
>
>>> Any help will be really appreciated.
>>
>> Well, it's a stack probe.  It's typically called when trying to allocate
>> big datastructures on the stack, e.g. with alloca.  Did you try to raise
>> the default stacksize in the executable header (see peflags -x and -X
>> options).  There's not much else to work with...
>>


For the archive, I found the culprit in the test code.
Using "%lu" to print int is not a good idea on cygwin 64 bit.


-       bbprintf0(stmt,"%ssize_t %s_countset[%lu] = {",
+       bbprintf0(stmt,"%ssize_t %s_countset[%u] = {",
                         indented(1),
                         cname(vsym),
                         rank);


as it could produce

     size_t br_startset[25769803777] = {0} ;
     size_t br_countset[25769803777] = {2};

instead of
    size_t br_startset[1] = {0} ;
    size_t br_countset[1] = {2};


as 25769803777 = 0x00060001

Regards
Marco

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Segmentation fault before main
  2015-11-04 21:42     ` Marco Atzeri
@ 2015-11-05  8:49       ` Csaba Raduly
  2015-11-05 13:11         ` Marco Atzeri
  2015-11-05  9:21       ` Corinna Vinschen
  1 sibling, 1 reply; 7+ messages in thread
From: Csaba Raduly @ 2015-11-05  8:49 UTC (permalink / raw)
  To: cygwin list

On Wed, Nov 4, 2015 at 10:42 PM, Marco Atzeri  wrote:
>
>
> For the archive, I found the culprit in the test code.
> Using "%lu" to print int is not a good idea on cygwin 64 bit.

That's why we have -Wformat=2

Csaba
-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Segmentation fault before main
  2015-11-04 21:42     ` Marco Atzeri
  2015-11-05  8:49       ` Csaba Raduly
@ 2015-11-05  9:21       ` Corinna Vinschen
  1 sibling, 0 replies; 7+ messages in thread
From: Corinna Vinschen @ 2015-11-05  9:21 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2008 bytes --]

On Nov  4 22:42, Marco Atzeri wrote:
> On 30/10/2015 20:45, Marco Atzeri wrote:
> >On 30/10/2015 20:18, Corinna Vinschen wrote:
> >>On Oct 30 16:25, Marco Atzeri wrote:
> >>>Hi Corinna,
> >>>
> >
> >>>Any help will be really appreciated.
> >>
> >>Well, it's a stack probe.  It's typically called when trying to allocate
> >>big datastructures on the stack, e.g. with alloca.  Did you try to raise
> >>the default stacksize in the executable header (see peflags -x and -X
> >>options).  There's not much else to work with...
> >>
> 
> 
> For the archive, I found the culprit in the test code.

I'm happy to read that.

> Using "%lu" to print int is not a good idea on cygwin 64 bit.
> 
> 
> -       bbprintf0(stmt,"%ssize_t %s_countset[%lu] = {",
> +       bbprintf0(stmt,"%ssize_t %s_countset[%u] = {",
>                         indented(1),
>                         cname(vsym),
>                         rank);

...and you wouldn't even have noticed it on Linux, because it uses the
SystemV ABI which passes the first 6 arguments in registers, in contrast
to the MS ABI which only passes the first 4 arguments in regs.

Thus on Linux you'd have silenty get the benefit of the CPU clearing the
upper 32 bits of a register when moving a 32 bit value into it, which
doesn't happen when moving a 32 bit argument to the stack.

That's one of the interesting side effects of porting an application.
Maybe it would make sense to mention this problem in
https://cygwin.com/faq/faq.html#faq.programming.64bitporting...

> as it could produce
> 
>     size_t br_startset[25769803777] = {0} ;
>     size_t br_countset[25769803777] = {2};

Ouch.

> instead of
>    size_t br_startset[1] = {0} ;
>    size_t br_countset[1] = {2};
> 
> 
> as 25769803777 = 0x00060001

I guess you mean 0x600000001 :)


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Segmentation fault before main
  2015-11-05  8:49       ` Csaba Raduly
@ 2015-11-05 13:11         ` Marco Atzeri
  0 siblings, 0 replies; 7+ messages in thread
From: Marco Atzeri @ 2015-11-05 13:11 UTC (permalink / raw)
  To: cygwin



On 05/11/2015 09:49, Csaba Raduly wrote:
> On Wed, Nov 4, 2015 at 10:42 PM, Marco Atzeri  wrote:
>>
>>
>> For the archive, I found the culprit in the test code.
>> Using "%lu" to print int is not a good idea on cygwin 64 bit.
>
> That's why we have -Wformat=2
>
> Csaba
>

Thanks for the suggestion, but it seems not
effective for this type of issue.

I rebuilt the original code and no additional
warning arises.



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-11-05 13:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-30 19:18 Segmentation fault before main Marco Atzeri
2015-10-30 21:23 ` Corinna Vinschen
2015-10-31 16:47   ` Marco Atzeri
2015-11-04 21:42     ` Marco Atzeri
2015-11-05  8:49       ` Csaba Raduly
2015-11-05 13:11         ` Marco Atzeri
2015-11-05  9:21       ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).