2009/3/15 Wolfgang Glas <wolfgang.g...@ev-i.at>:
> Kai Tietz schrieb:
>> 2009/3/15 Wolfgang Glas <wolfgang.g...@ev-i.at>:
>>> Hi all,
>>>
>>>  I've been trying very hard to reduce my alloca() problems and at got stuck
>>> with every attempt to isolate the problem.
>>>
>>>  Finally I linked a mildly complex C-program, which crashed before using a
>>> handcrafted Makefile and luckily I found out, that the program crashes, 
>>> when I
>>> add a bunch Window's system libraries to the linker command line. (A 
>>> practice I
>>> cowardly copied from another project years ago...)
>>>
>>>  I've uploaded a self-contained (but not small) testcase to our weebserver 
>>> under
>>>
>>>  http://www.ev-i.at/tmp/mingw_hpgspdf_test.tar.gz
>>>
>>> The makefile generates two executables: One linked just with the 
>>> self-generated
>>> DLLs and one linked with a long list of windows system libraries. The 
>>> executable
>>> linked with the windows libraries is called hpgspdffile-read-fail.exe and 
>>> has a
>>> different size than the executable hpgspdffile-read.exe linked with just the
>>> self-generated libraries. Besides, it has the same runtime dependencies and
>>> however it *does* crash right after alloca(), while the other one survives
>>> flawlessly.
>>>
>>>  The program reads a PDF-file, interprets it's internal structure and
>>> re-serializes the file afterwards. (Should work with any normal PDF-file).
>>>
>>>  This is my debug-session:
>>>
>>> **************************************
>>> H:\wglas\CC\mingw_hpgspdf_test\bin64>gdb-w64 .\hpgspdffile-read-fail.exe
>>> GNU gdb 6.7.50.20080109-cvs
>>> Copyright (C) 2008 Free Software Foundation, Inc.
>>> License GPLv3+: GNU GPL version 3 or later 
>>> <http://gnu.org/licenses/gpl.html>
>>> This is free software: you are free to change and redistribute it.
>>> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
>>> and "show warranty" for details.
>>> This GDB was configured as "x86_64-pc-mingw32"...
>>>
>>> warning: A handler for the OS ABI "Cygwin" is not built into this 
>>> configuration
>>> of GDB.  Attempting to continue with the default i386:x86-64 settings.
>>>
>>> (gdb) break hpgspdffile.c:1230
>>> Breakpoint 1 at 0x40eead: file hpgspdffile.c, line 1230.
>>> (gdb) r H:\wglas\doc\hp\bpl13205.pdf x.pdf
>>> Starting program: 
>>> H:\wglas\CC\mingw_hpgspdf_test\bin64/.\hpgspdffile-read-fail.e
>>> xe H:\wglas\doc\hp\bpl13205.pdf x.pdf
>>> len=28.
>>> value=C:\Program Files (x86)\cdes.
>>> prefix=C:\Program Files (x86)\cdes.
>>> Opening file H:\wglas\doc\hp\bpl13205.pdf.
>>> Reading file H:\wglas\doc\hp\bpl13205.pdf.
>>>
>>> Breakpoint 1, hpgs_pdf_file_read_xref (pdf=0x3f7720) at hpgspdffile.c:1230
>>> 1230    hpgspdffile.c: No such file or directory.
>>>        in hpgspdffile.c
>>> (gdb) print tail_data
>>> $1 = 0x22fda0 ""
>>> (gdb) print &len
>>> $2 = (size_t *) 0x22fdb0
>>> (gdb) n
>>>
>>> Program received signal SIGSEGV, Segmentation fault.
>>> 0x000007ff7fc52806 in ?? ()
>>> (gdb) bt
>>> #0  0x000007ff7fc52806 in ?? ()
>>> #1  0x000007ff7fc4a949 in ?? ()
>>> #2  0x0000000000000003 in ?? ()
>>> #3  0x0000000000000003 in ?? ()
>>> #4  0x0000000000000003 in ?? ()
>>> #5  0x000000000033d627 in ?? ()
>>> #6  0x0000000000000000 in ?? ()
>>> (gdb) q
>>> The program is running.  Exit anyway? (y or n) y
>>>
>>> H:\wglas\CC\mingw_hpgspdf_test\bin64>
>>> **************************************
>>>
>>>  Explanation:
>>>
>>> tail_data is a char-array of size 2048, which has been allocated through
>>> alloca(), 'len' is a local variable. The problem her is, that alloca() 
>>> places
>>> tail_data 16 bytes before len, which is far less than the required 2048 
>>> bytes...
>>>
>>>  Hopefully, this will bring us one step further in resolving this curious 
>>> problem.
>>>
>>>  Regards,
>>>
>>>    Wolfgang
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
>>> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
>>> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
>>> software that enables intelligent coding and step-through debugging.
>>> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
>>> _______________________________________________
>>> Mingw-w64-public mailing list
>>> Mingw-w64-public@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>>>
>>
>> By trying to reduce this test case I stumble over the assembly produced
>>  leaq    30(%rbx), %rax
>>  andq    $-16, %rax
>>  call    ___chkstk
>>
>> so, if %rbx is zero (len == 0) this happens what you are describing.
>> that tail_data is just 16 bytes away from file_len. So possibly you
>> should check the result of hpgs_istream_tell(pdf->is,&file_len), if
>> file_len is not equal to zero. If it is, all points to an alias issue.
>
> Well, if I print the content of len in my debugging session, I get:
>
> Breakpoint 1, hpgs_pdf_file_read_xref (pdf=0x3f7720) at hpgspdffile.c:1230
> 1230    hpgspdffile.c: No such file or directory.
>        in hpgspdffile.c
> (gdb) print len
> $1 = 2048
> (gdb) print &len
> $2 = (size_t *) 0x22fdb0
> (gdb) print tail_data
> $3 = 0x22fda0 ""
> (gdb) print file_len
> $4 = 3399207
> (gdb)
>
> Since I really never ever developed a compiler and do not know what an 
> aliasing
> issue, I just have to believe in your words and hope that my testcase may help
> you ;-)
>
> But why the hell is there a difference between the executables with or w/o
> system libraries explicitly specified on the linker cmd line?
>
>  Wolfgang
>

Ok, I found the issue. Your application calls __chkstk from kernel32,
which is pretty false. Because the MS variant just probes the stack,
but does not allocate it as the cygwin variant. There are two possible
ways to solve this, a) Remove the export from kernel32.def in lib64,
or rename the method in gcc/config/i386 defined in cygwin.asm and
referenced in i386.md

We have here a name conflict :/

Cheers,
Kai

-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to