[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#676558: gcc-4.6: Incorrect assembly code generated for loop over char ** in named sections



On 07.06.2012 21:11, Christoph Schwarz wrote:
> Package: gcc-4.6
> Version: 4.6.3-1
> Severity: normal
> 
> Dear Maintainer,
> 
> I have a program that loops over const char * pointers in named sections.
> In this loop, incorrect generated assembly code causes wrong output, e.g.
> it outputs (null) instead of the string pointed to by the const char * pointer.
> This (null) can be tracked down to the generated assembly code where it
> puts a static zero on the stack instead of the address of the string.
> 
> This incorrect code is generated for 32 bit with optimization levels 1-3
> only. 64 bit is not affected, neither is unoptimized 32 bit.
> 
> I found various versions of gcc 4.6.x containing this bug, including:
> TDM-GCC 4.6.1, MinGW gcc 4.6.2 and Debian gcc 4.6.3-1
> so it seems to me it is a 4.6 issue. I can confirm that neither MinGW gcc 4.5.2
> nor Debian gcc 4.4.5 (Debian Squeeze) contain this bug.
> 
> I already filed a bug against TDM-GCC 4.6.1:
> http://sourceforge.net/tracker/?func=detail&aid=3532366&group_id=200665&atid=974439
> 
> Quoting from this bug report:
> ===== quote begin =====
> The expected and correct output is:
> B: Handling call with 1 args
> B: Handling call one
> B: Handling call with 1 args
> B: Handling call with 3 args
> B: Handling call three
> B: Handling call with 3 args
> B: Handling call with 2 args
> B: Handling call two
> B: Handling call with 2 args
> 
> The incorrect output is:
> B: Handling call with 1 args
> B: Handling call (null)
> B: Handling call with 0 args
> B: Handling call with 3 args
> B: Handling call (null)
> B: Handling call with 0 args
> B: Handling call with 2 args
> B: Handling call (null)
> B: Handling call with 0 args
> 
> The issue can be tracked down to the generated assembly code where the code
> puts a static zero on the stack for printf (instead of the address of the
> char array), resulting in the "(null)" output. Same goes for the "0 args"
> output.
> 
> The incorrect assembly code can be found in lines 30-35 of the attached s file:
> movl $0, 4(%esp)
> movl $LC1, (%esp)
> call _printf
> movl $0, 4(%esp)
> movl $LC0, (%esp)
> call _printf
> ===== quote end =====
> 
> I'll attach the test program and additional files. Please note that I had to
> make slightly modifications to the section names and linker options in order
> to get gcc 4.6.3-1 (or its ld) to sort the sections in alphabetic order
> (compared to the test program that I filed with the TDM-GCC bug).
> 
> thank you for looking into this issue,
> Chris

please could you recheck with 4.7 from unstable?





Reply to: