This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

possible problem with spec file processing in gfortran


I am investigating why gfortran does not seem to generate debug symbols on Darwin platforms. The problem that I describe below with spec files or spec strings is also present in linux. The bug apparently doesn't cause any ill effects so it hasn't been noticed there...yet anyway. The problem also seems to be common between 4.5.1 and the 4.6 trunk.

I could use some advice at this point as to how to proceed. I'm willing to continue working on this - if I have some idea where to go next.

In general, there doesn't seem to be any symbols in executables generated on Darwin 10:

=============================================
et:gdb-7.2-fortran-test sjbespa$ /volumes/dev/gcc/4.5.1/bin/gfortran -g -o test-fortran test_1.f90
et:gdb-7.2-fortran-test sjbespa$ dwarfdump test-fortran
----------------------------------------------------------------------
 File: test-fortran (x86_64)
----------------------------------------------------------------------
.debug_info contents:
< EMPTY >
=============================================

The same thing happens with -gdwarf-2 and -g3... I can't explain why the symbols are getting stripped yet because there are symbols in object files:

=============================================
et:gdb-7.2-fortran-test sjbespa$ /volumes/dev/gcc/4.5.1/bin/gfortran -g -c -o test-fortran.o test_1.f90
et:gdb-7.2-fortran-test sjbespa$ dwarfdump test-fortran.o
----------------------------------------------------------------------
 File: test-fortran.o (x86_64)
----------------------------------------------------------------------
.debug_info contents:

0x00000000: Compile Unit: length = 0x00000288  version = 0x0002  abbr_offset = 0x00000000  addr_size = 0x08  (next CU at 0x0000028c)
[ the complete output is at the bottom]
==================================================

The gcc compiler built from the same sources generates an OS X dSYM bundle with the debug symbols:

==================================================
et:gdb-7.2-fortran-test sjbespa$ ls
hello_world.c	test_1.f90
et:gdb-7.2-fortran-test sjbespa$ /volumes/dev/gcc/4.5.1/bin/gcc -g hello_world.c
et:gdb-7.2-fortran-test sjbespa$ ls
a.out		a.out.dSYM	hello_world.c	test_1.f90
==================================================

The dSYM file is generated from a second spec string in the link_command_spec in darwin.h:

%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
%{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm: \
%{g*:%{!gstabs*:%{!g0: dsymutil %{o*:%*}%{!o:a.out}}}}}}}}}}}}

Adding the file suffixes for fortran source files does not work. 

The problem seems to be that when gfortran is called, certain values of the spec file strings are not processed correctly. The spec file I created to experiment with, included below, outputs the "base name of the file" (%B) when the link command is processed with the following command string:

%{g*:echo ** %B}

It is always the wrong value with gfortran:

============
et:gdb-7.2-fortran-test sjbespa$ /volumes/dev/gfortran-4.6-trunk/bin/gfortran -specs=/users/sjbespa/Desktop/linkcommandspec.txt -g -o test-fortran test_1.f90
** -lgfortran
et:gdb-7.2-fortran-test sjbespa$ /volumes/dev/gfortran-4.6-trunk/bin/gcc -specs=/users/sjbespa/Desktop/linkcommandspec.txt -g -o test-gcc hello_world.c
** hello_world.c
============

The the source file name is -lgfortran for %B in OS X, and -lm in linux, but with c language files the spec processing functions gets it right. 

Obviously, with the wrong input file name the part of the (darwin) link spec string that checks the file suffix isn't going to work.

Best regards,
Stephen J. Bespalko

================
et:gdb-7.2-fortran-test sjbespa$ dwarfdump test-fortran.o
----------------------------------------------------------------------
 File: test-fortran.o (x86_64)
----------------------------------------------------------------------
.debug_info contents:

0x00000000: Compile Unit: length = 0x00000288  version = 0x0002  abbr_offset = 0x00000000  addr_size = 0x08  (next CU at 0x0000028c)

0x0000000b: TAG_compile_unit [1] *
             AT_producer( "GNU Fortran 4.5.1" )
             AT_language( DW_LANG_C89 )
             AT_name( "test_1.f90" )
             AT_comp_dir( "/volumes/dev/gdb-7.2-fortran-test" )
             AT_low_pc( 0x0000000000000000 )
             AT_high_pc( 0x000000000000025c )
             AT_stmt_list( 0x00000000 )

0x00000060:     TAG_subprogram [2] *
                 AT_external( 0x01 )
                 AT_name( "test_1_sub" )
                 AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                 AT_decl_line( 11 )
                 AT_MIPS_linkage_name( "__test_1_module_MOD_test_1_sub" )
                 AT_low_pc( 0x0000000000000000 )
                 AT_high_pc( 0x00000000000001f2 )
                 AT_frame_base( 0x00000000
                    0x0000000000000000 - 0x0000000000000001: rsp+8
                    0x0000000000000001 - 0x0000000000000004: rsp+16
                    0x0000000000000004 - 0x00000000000001f1: rbp+16
                    0x00000000000001f1 - 0x00000000000001f2: rsp+8 )
                 AT_sibling( {0x00000120} )

0x000000a6:         TAG_variable [3]  
                     AT_name( "i" )
                     AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                     AT_decl_line( 13 )
                     AT_type( {0x00000120} ( integer(kind=4) ) )
                     AT_location( fbreg -20 )

0x000000b2:         TAG_lexical_block [4] *
                     AT_low_pc( 0x000000000000000b )
                     AT_high_pc( 0x0000000000000070 )
                     AT_sibling( {0x000000d9} )

0x000000c7:             TAG_lexical_block [5]  
                         AT_low_pc( 0x0000000000000043 )
                         AT_high_pc( 0x000000000000005e )

0x000000d8:             NULL

0x000000d9:         TAG_lexical_block [5]  
                     AT_low_pc( 0x000000000000009f )
                     AT_high_pc( 0x00000000000000d8 )

0x000000ea:         TAG_lexical_block [6] *
                     AT_low_pc( 0x0000000000000102 )
                     AT_high_pc( 0x00000000000001ab )

0x000000fb:             TAG_lexical_block [6] *
                         AT_low_pc( 0x0000000000000102 )
                         AT_high_pc( 0x0000000000000195 )

0x0000010c:                 TAG_lexical_block [5]  
                             AT_low_pc( 0x000000000000013d )
                             AT_high_pc( 0x0000000000000186 )

0x0000011d:                 NULL

0x0000011e:             NULL

0x0000011f:         NULL

0x00000120:     TAG_base_type [7]  
                 AT_byte_size( 0x04 )
                 AT_encoding( DW_ATE_signed )
                 AT_name( "integer(kind=4)" )

0x00000133:     TAG_subprogram [8]  
                 AT_name( "test_1" )
                 AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                 AT_decl_line( 32 )
                 AT_low_pc( 0x00000000000001f2 )
                 AT_high_pc( 0x000000000000021a )
                 AT_frame_base( 0x00000060
                    0x00000000000001f2 - 0x00000000000001f3: rsp+8
                    0x00000000000001f3 - 0x00000000000001f6: rsp+16
                    0x00000000000001f6 - 0x0000000000000219: rbp+16
                    0x0000000000000219 - 0x000000000000021a: rsp+8 )

0x00000151:     TAG_subprogram [9] *
                 AT_external( 0x01 )
                 AT_name( "main" )
                 AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                 AT_decl_line( 34 )
                 AT_prototyped( 0x01 )
                 AT_type( {0x00000120} ( integer(kind=4) ) )
                 AT_low_pc( 0x000000000000021a )
                 AT_high_pc( 0x000000000000025c )
                 AT_frame_base( 0x000000c0
                    0x000000000000021a - 0x000000000000021b: rsp+8
                    0x000000000000021b - 0x000000000000021e: rsp+16
                    0x000000000000021e - 0x000000000000025b: rbp+16
                    0x000000000000025b - 0x000000000000025c: rsp+8 )
                 AT_sibling( {0x00000197} )

0x00000177:         TAG_formal_parameter [10]  
                     AT_name( "argc" )
                     AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                     AT_decl_line( 34 )
                     AT_type( {0x00000197} ( const integer(kind=4) ) )
                     AT_location( fbreg -20 )

0x00000186:         TAG_formal_parameter [10]  
                     AT_name( "argv" )
                     AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                     AT_decl_line( 34 )
                     AT_type( {0x0000019c} ( character(kind=1)* ) )
                     AT_location( fbreg -32, deref )

0x00000196:         NULL

0x00000197:     TAG_const_type [11]  
                 AT_type( {0x00000120} ( integer(kind=4) ) )

0x0000019c:     TAG_pointer_type [12]  
                 AT_byte_size( 0x08 )
                 AT_type( {0x000001a2} ( character(kind=1) ) )

0x000001a2:     TAG_base_type [7]  
                 AT_byte_size( 0x01 )
                 AT_encoding( DW_ATE_unsigned_char )
                 AT_name( "character(kind=1)" )

0x000001b7:     TAG_structure_type [13]  
                 AT_name( "array1_real(kind=4)" )
                 AT_declaration( 0x01 )

0x000001cd:     TAG_variable [14]  
                 AT_name( "data" )
                 AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                 AT_decl_line( 7 )
                 AT_MIPS_linkage_name( "__test_1_module_MOD_data" )
                 AT_type( {0x000001b7} ( array1_real(kind=4) ) )
                 AT_external( 0x01 )
                 AT_location( [0x0000000000000980] )

0x000001fd:     TAG_variable [14]  
                 AT_name( "x" )
                 AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                 AT_decl_line( 3 )
                 AT_MIPS_linkage_name( "__test_1_module_MOD_x" )
                 AT_type( {0x00000227} ( real(kind=4) ) )
                 AT_external( 0x01 )
                 AT_location( [0x00000000000009b0] )

0x00000227:     TAG_base_type [7]  
                 AT_byte_size( 0x04 )
                 AT_encoding( DW_ATE_float )
                 AT_name( "real(kind=4)" )

0x00000237:     TAG_variable [14]  
                 AT_name( "y" )
                 AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                 AT_decl_line( 4 )
                 AT_MIPS_linkage_name( "__test_1_module_MOD_y" )
                 AT_type( {0x00000227} ( real(kind=4) ) )
                 AT_external( 0x01 )
                 AT_location( [0x00000000000009b4] )

0x00000261:     TAG_variable [14]  
                 AT_name( "z" )
                 AT_decl_file( "/Volumes/dev/gdb-7.2-fortran-test/test_1.f90" )
                 AT_decl_line( 5 )
                 AT_MIPS_linkage_name( "__test_1_module_MOD_z" )
                 AT_type( {0x00000227} ( real(kind=4) ) )
                 AT_external( 0x01 )
                 AT_location( [0x00000000000009b8] )

0x0000028b:     NULL

=========================== file: test_1.f90 ====================
module test_1_module

real, save :: x
real :: y
real, protected :: z

real, dimension(:), allocatable :: data

contains

subroutine test_1_sub

integer::i
allocate (data(10))
do i=1,10
   data(i) = real(i*i)
end do

y = 11
z = 12

do i=1,10
   print *,data(i)/real(x)
end do

deallocate(data)

end subroutine test_1_sub

end module test_1_module

program test_1

use test_1_module

x = 13

call test_1_sub()
call test_1_sub()

end program test_1
==================================================================

============================ file: hello_world.c ====================
#include <stdio.h>

main()
{
   int i;
  for(i=0;i<10;i++)
      { 
          printf ("Hello World!\n");
      }
  return 0;
}
==============================================================

========================= file: linkcommandspec.txt =================
*link_command:
%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
%(linker) \
%{flto*:%<fcompare-debug*} \
%{flto*} \
%l %X %{d} %{s} %{t} %{Z} %{u*} \
%{A} %{e*} %{m} %{r} \
%{o*}%{!o:-o a.out} \
%{!A:%{!nostdlib:%{!nostartfiles:%S}}} \
%{L*} %(link_libgcc) %o %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
%{fopenmp|ftree-parallelize-loops=*: \
%{static|static-libgcc|static-libstdc++|static-libgfortran: libgomp.a%s; : -lgomp } } \
%{!nostdlib:%{!nodefaultlibs: %(link_ssp) %G %L }} \
%{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*}}}}}}}}
%{g*:echo ** %B}
%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
%{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm: \
%{g*:%{!gstabs*:%{!g0: dsymutil %{o*:%*}%{!o:a.out}}}}}}}}}}}}
%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
%{.f|.F|.for|.FOR|.ftn|.FTN|.f90|.F90|.f95|.F95|.f03|.F03|.f08|.F08: \
%{g*:%{!gstabs*:%{!g0: dsymutil %{o*:%*}%{!o:a.out}}}}}}}}}}}}
================================================================




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]