http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50201

--- Comment #9 from Jouko Orava <jouko.orava at iki dot fi> ---
It turns out that while fdp2.f90,
    PROGRAM fdp2
        IMPLICIT none
        INTEGER, PARAMETER :: b128 = SELECTED_REAL_KIND(33, 1000)
        REAL(KIND=b128) :: x(4)
        x = 3.4_b128
        PRINT *, KIND(x)
        WRITE (*, "(4F10.3)") x(1:4)
    END PROGRAM
crashes when compiled static,
    PROGRAM fdp2
        IMPLICIT none
        INTEGER, PARAMETER :: b128 = SELECTED_REAL_KIND(33, 1000)
        REAL(KIND=b128) :: x(4)
        x = 3.4_b128
        PRINT *, KIND(x)
        WRITE (*, "(4F10.3)") x(1), x(3:4)
    END PROGRAM
does not. The only thing that changes in the second-to-last line:
with x(1:4) it segfaults, with x(1),x(3:4) it works fine.
Compiled on 4.7.3 using
    gfortran-4.7 -static -ggdb -W -Wall -O3 fdp2.f90 -o fdp2
and on 4.8.1 using
    gfortran-4.8 -static -ggdb -W -Wall -O3 fdp2.f90 -o fdp2

Comparing the disassembly of the two, both do have a large number of
    callq  0 <__libc_tsd_LOCALE>
calls. However, where the first one segfaults, the second one has
    callq  423320 <quadmath_snprintf>

Furthermore, compiling using -Wl,-uquadmath_snprintf fixes the issue, i.e.
    gfortran-4.7 -static -ggdb -W -Wall -O3 fdp2.f90 -Wl,-uquadmath_snprintf
fdp2
causes the shown example program to work correctly.

Finally, compiling Bill Long's example fdp2.f90 using
    gfortran-4.7 -fdefault-real-8 -static fdp2.f90 -Wl,-uquadmath_snprintf -o
a.out
or
    gfortran-4.8 -fdefault-real-8 -static fdp2.f90 -Wl,-uquadmath_snprintf -o
a.out
fixes the segfault for me.

It seems like some kind of linking issue. How the issue is masked by printing a
scalar before an array is a mystery to me, however.

Reply via email to