[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::fortran

Title:Digital Fortran
Notice:Read notes 1.* for important information
Moderator:QUARK::LIONEL
Created:Thu Jun 01 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1333
Total number of notes:6734

1190.0. "f77 -S = no local symbols?" by RHETT::PARKER () Thu Feb 20 1997 12:10

    
    Hi, All,
    
    A customer sent me mail describing a problem I hope someone can
    explain. I checked the f77 man page and could not figure it out 
    - f77 may be working as expected, I just can't seem to find the
    magic switch.
    
    I looked at -static & -noautomatic but since these are defaults...
    
    Thanks for any advice!
    
    Lee
    ------------------------------------------------------------------
    
    I've got a test program called foobar.f.  If I compile it with the
    command:
    
       f77 -g2 -c foobar.f
    
    and then do an odump -t foobar.o, the symbol table contains all the
    local symbols I've defined (in particular two local variables IFOO and
    IBAR).
    
    If I compile it with:
    
      f77 -g2 -S foobar.f
      f77 -g2 -c foobar.s
    
    and then do an odump -t foobar.o, the symbol table doesn't contain the
    local symbols.  Is there a switch that can be used to force the
    declaration of symbols in the foobar.s file?
    
    The following is the output of what I've described above:
    
    rckingdc1> cat foobar.f
    
          PROGRAM FOOBAR
    C
          IMPLICIT NONE
    C
          INTEGER*2  IFOO
          INTEGER*2  IBAR
    C
          WRITE ( *, * ) IFOO, IBAR
    C
          END
    
    rckingdc1> f77 -g2 -c foobar.f
    rckingdc1> odump -t foobar.o
    
    
                            ***SYMBOL TABLE INFORMATION***
    [Index] Name            Value            Sclass   Symtype   Ref
    foobar.o:
    [0]      foobar.f  0x0000000000000000    0x01     0x0b      0x0008
    [1]      foobar_   0x0000000000000000    0x01     0x06      0x0019
    [2]                0x0000000000000010    0x01     0x07      0x0006
    [3]      IFOO      0x0000000000000150    0x03     0x02      0x001b
    [4]      IBAR      0x0000000000000158    0x03     0x02      0x001c
    [5]                0x000000000000008c    0x01     0x08      0x0002
    [6]      foobar_   0x0000000000000098    0x01     0x08      0x0001
    [7]      foobar.f  0x0000000000000000    0x01     0x08      0x0000
    [8]      MAIN__    0x0000000000000000    0x01     0x06      0x0001
    [9]      foobar_   0x0000000000000000    0x01     0x06      0x0001
    [10]     for_write_seq_lis0x0000000000000000    0x06     0x06
    0xfffff
    [11]     for_write_seq_lis_xmit0x0000000000000000    0x06     0x06
    0xfffff
    [12]     for_set_reentrancy0x0000000000000000    0x06     0x06
    0xfffff
    [13]     _fpdata   0x0000000000000000    0x06     0x01      0xfffff
    
    rckingdc1> f77 -g2 -S foobar.f
    rckingdc1> f77 -g2 -c foobar.s
    rckingdc1> odump -t foobar.o
    
    
                            ***SYMBOL TABLE INFORMATION***
    [Index] Name            Value            Sclass   Symtype   Ref
    foobar.o:
    [0]      foobar.s  0x0000000000000000    0x01     0x0b      0x0006
    [1]      $$1       0x0000000000000110    0x02     0x02      0xfffff
    [2]      $$2       0x0000000000000114    0x02     0x02      0xfffff
    [3]      $$3       0x0000000000000100    0x02     0x02      0xfffff
    [4]      $$4       0x0000000000000120    0x03     0x02      0xfffff
    [5]      foobar.s  0x0000000000000000    0x01     0x08      0x0000
    [6]      foobar.f  0x0000000000000000    0x01     0x0b      0x000a
    [7]      foobar_   0x0000000000000000    0x01     0x06      0x0002
    [8]      foobar_   0x0000000000000098    0x01     0x08      0x0007
    [9]      foobar.f  0x0000000000000000    0x01     0x08      0x0006
    [10]     $$1       0x0000000000000000    0x00     0x00      0xfffff
    [11]     $$2       0x0000000000000000    0x00     0x00      0xfffff
    [12]     $$3       0x0000000000000000    0x00     0x00      0xfffff
    [13]     $$4       0x0000000000000000    0x00     0x00      0xfffff
    [14]     foobar_   0x0000000000000000    0x01     0x06      0x0007
    [15]     for_set_reentrancy0x0000000000000000    0x06     0x01
    0xfffff
    [16]     for_write_seq_lis0x0000000000000000    0x06     0x01
    0xfffff
    [17]     for_write_seq_lis_xmit0x0000000000000000    0x06     0x01
    0xfffff
    [18]     _fpdata   0x0000000000000000    0x06     0x01      0xfffff
T.RTitleUserPersonal
Name
DateLines
1190.1TLE::MENARDnew kid on the COMMON blockFri Feb 21 1997 09:587
I looked at this briefly, and it does look like a bug.

We'll get back to you when we've got it sorted out and fixed.

	Thanks for the simple program -

		- Lorri
1190.2Thanks!!RHETT::PARKERFri Feb 21 1997 11:2610
    
    Thanks for looking into this. I was not sure if it was f77(1) or
    as(1) or something else that could be causing the problem. 
    Still not sure ...
    
    Thanks again!
    
    Lee
    
    
1190.3TLE::MENARDnew kid on the COMMON blockFri Feb 21 1997 11:277
>    I was not sure if it was f77(1) or
>    as(1) or something else that could be causing the problem. 
>    Still not sure ...

    Frankly, I'm not either ;-) but we'll figure it out somehow!

	    - Lorri
1190.4QUARRY::nethCraig NethFri Feb 21 1997 13:119
You should ask Gene Albert for sure, but I'm pretty sure that this behavior
is what is intended.    The compiler front ends turn all local variables into
a name that starts with $$.   The reason this is done is to ensure that 
local variables do not conflict with any global variables in the application.
There is no concept of 'local' vs 'global' symbols in .s files.




1190.5feature, not a bug (although a front-end improvement would help)GEMGRP::ALBERTSun Feb 23 1997 10:1737
Craig is right, this is to keep namespaces from colliding.
Consider the following C program:

  main () { 
    static int localvar = 0;
    foo(localvar);
    printf("a: 1=%d\n", localvar);
  }

  foo (i)
    int i;
  {
    static int localvar = 1;
    printf("foo: 1=%d\n", localvar);
  }

Both main and foo define "localvar", and both of these require
static storage.  In the .s file, which has a flat namespace,
this looks like:

  $$1$localvar:
        .long   0x0 # .long 0
  $$2$localvar:
        .long   0x1 # .long 1

The back end calls the front end to generate these names.
The C compiler prepends a unique prefix to the user's name.
The Fortran compiler generates an entirely new name, loosing
the original name in the process.  The front ends could do better
than they currently are, but the basic task of ensuring
that all local names are unique in a .s file remains.

FYI, GEM calls GEM_ST_GET_NAME with the GEM_ST_CONTEXT_K_SFILE
context to request name disambiguation.


 
1190.6Thanks - more infoRHETT::PARKERMon Feb 24 1997 10:26405
    
    Ok, now I understand why it works this way. The customer gave
    me a much more complete explanation of why/what they are trying
    to acomplish so I thought I'd see if any of you fortran guru's
    might have a "work around" - not that anything is broken. :-)
    
    Thanks, 
    
    Lee
    ---------------------------------------------------------------------
    Customer email:
    


As I've said before, we're trying to use System V type shared memory 
for our FORTRAN applications.  Mike has developed a Windows application 
called Coed which we use to manage and create the FORTRAN INCLUDE files 
for our applications.  These INCLUDE files are basically the definitions 
for all of the variables that reside in our FORTRAN GLOBAL COMMONS.  (An 
example of one of these include files is attached - called comlog_l.f.)  

The way things currently work is: we take the comlog_l.f file and run it
through the FORTRAN compiler with the -g2 -c switches and generate a .o
file.  This .o file is then processed by another utility written by Mike
called ascomm.  ascomm reads the .o file and extracts the GLOBAL COMMON's 
name from the .o file and creates an assembly language routine.
(An example of the assembly routine that we're currently generating for
comlog_l.f is attached - called comlog_l.s.)

This routine is callable from the FORTRAN program at run time and remaps
the program to the System V shared memory space.  The problem with
ascomm is that it can't generate all the necessary symbol table
information for the variables in the GLOBAL COMMON necessary for
debugging.

What I would like to be able to do is compile the comlog_l.f type files
with the -S switch to generate the assembly language code.  Then, I'd
like to modify the assembly language code to be a callable subroutine
that, when called, will remap to the System V shared memory - much the
same way things are working now.

The "problem" (?) with the FORTRAN compiler the way it currently works
is that the symbol table is generated fine if I just use the -c option.
But, if I use the -S option, none of the variable's symbols make it into
the .s file.

I know what we're trying to do sounds a little strange, but we've
developed an architecture around the Coed and ascomm utilities and
everything works fine - except we can't look at values in GLOBAL COMMON
with dbx.

------------------------------------------------------------------------

comlog_l.f

C
C     NODE:    DC1                                           1997/02/17
C     REGION:   COMLOG                                  13:32:03
C
      BLOCK DATA COMLOG_L
C
C     Data Logging Common
C
      IMPLICIT NONE
      INCLUDE '/usr/include/sysparam.inc'
      INTEGER   *   2   NCOMLOG   (512)
      COMMON           /COMLOG_ /  NCOMLOG
C
      DATA  NCOMLOG / 512 * 0 /
C
C     VARIABLE DECLARATIONS:
C
C
C     Sum of A-622 Filter Argon Gas (North, Middle, South)              
C
      REAL*8               D622AR(3)
      EQUIVALENCE         (D622AR, NCOMLOG(1))
      DATA          D622AR / 3 * 0.0/
C
C     Sum of A-622 Filter Chlorine Gas (North, Middle, South)           
C
      REAL*8               D622CL(3)
      EQUIVALENCE         (D622CL, NCOMLOG(201))
      DATA          D622CL / 3 * 0.0/
C
C     Sum of R-934 Filter Argon Gas (North, Middle, South)              
C
      REAL*8               D934AR(3)
      EQUIVALENCE         (D934AR, NCOMLOG(189))
      DATA          D934AR / 3 * 0.0/
C
C     Sum of R-934 Filter Chlorine Gas (North, Middle, South)           
C
      REAL*8               D934CL(3)
      EQUIVALENCE         (D934CL, NCOMLOG(213))
      DATA          D934CL / 3 * 0.0/
C
C     Sum of Casting Temperature                                        
C
      REAL*8               DCASTP
      EQUIVALENCE         (DCASTP, NCOMLOG(25))
      DATA          DCASTP / 0.0/
C
C     Sum of Cooling Water Flow                                         
C
      REAL*8               DCWFLO
      EQUIVALENCE         (DCWFLO, NCOMLOG(297))
C
C     Sum of Cooling Water Temperature                                  
C
      REAL*8               DCWTMP
      EQUIVALENCE         (DCWTMP, NCOMLOG(301))
C
C     Sum of A-622 Filter Disperser (#1, #2, #3)                        
C
      REAL*8               DDISPR(3)
      EQUIVALENCE         (DDISPR, NCOMLOG(225))
C
C     Sum of Drop Rate                                                  
C
      REAL*8               DDRATE
      EQUIVALENCE         (DDRATE, NCOMLOG(37))
C
C     Sum of Grain Rod Speed                                            
C
      REAL*8               DGRARF
      EQUIVALENCE         (DGRARF, NCOMLOG(305))
C
C     Sum of Holding Furnace Temperature                                
C
      REAL*8               DHFTMP
      EQUIVALENCE         (DHFTMP, NCOMLOG(21))
C
C     Sum of Fluxing Gas Rate in Melting Furnace                        
C
      REAL*8               DMFGAS
      EQUIVALENCE         (DMFGAS, NCOMLOG(17))
C
C     Sum of Melting Furnace Temperature                                
C
      REAL*8               DMFTMP
      EQUIVALENCE         (DMFTMP, NCOMLOG(13))
C
C     Sum of Metal Level (#1, #2, #3, #4, #5, #6, #7)                   
C
      REAL*8               DMLCAV(7)
      EQUIVALENCE         (DMLCAV, NCOMLOG(237))
C
C     One Minute Count for Casting Temperature                          
C
      INTEGER*2            I1MCTP
      EQUIVALENCE         (I1MCTP, NCOMLOG(81))
C
C     One Minute Count for Grain Refiner                                
C
      INTEGER*2            I1MGRF
      EQUIVALENCE         (I1MGRF, NCOMLOG(77))
C
C     One Minute Count for Steady State                                 
C
      INTEGER*2            I1MINC
      EQUIVALENCE         (I1MINC, NCOMLOG(69))
C
C     Five Minute Count for Steady State                                
C
      INTEGER*2            I5MINC
      EQUIVALENCE         (I5MINC, NCOMLOG(73))
C
C     Start Cast Crew                                                   
C
      INTEGER*2            ICCREW
      EQUIVALENCE         (ICCREW, NCOMLOG(177))
C
C     Start Cast Day of Year                                            
C
      INTEGER*2            ICDAYR
      EQUIVALENCE         (ICDAYR, NCOMLOG(109))
C
C     Start Furnace Number                                              
C
      INTEGER*2            ICFURN
      EQUIVALENCE         (ICFURN, NCOMLOG(129))
C
C     Start Narrow Dimension of Mold                                    
C
      INTEGER*2            ICGAGE
      EQUIVALENCE         (ICGAGE, NCOMLOG(117))
C
C     Start Number of Active Molds                                      
C
      INTEGER*2            ICNUMI
      EQUIVALENCE         (ICNUMI, NCOMLOG(125))
C
C     Total CO2 Flow Time                                               
C
      INTEGER*2            ICOTIM
      EQUIVALENCE         (ICOTIM, NCOMLOG(65))
C
C     Start Cast Time (Minutes Past Midnight)                           
C
      INTEGER*2            ICTIME
      EQUIVALENCE         (ICTIME, NCOMLOG(113))
C
C     Start Wide Dimension of Mold                                      
C
      INTEGER*2            ICWDTH
      EQUIVALENCE         (ICWDTH, NCOMLOG(121))
C
C     Start Cast Year                                                   
C
      INTEGER*2            ICYEAR
      EQUIVALENCE         (ICYEAR, NCOMLOG(105))
C
C     Active Molds in Drop                                              
C
      INTEGER*2            IDNUMI
      EQUIVALENCE         (IDNUMI, NCOMLOG(169))
C
C     Acceptable Ingot Length for the Stop Cast Report                  
C
      INTEGER*2            ILABTR
      EQUIVALENCE         (ILABTR, NCOMLOG(309))
C
C     Total Melting Furnace Gas Flow Time                               
C
      INTEGER*2            IMFGTM
      EQUIVALENCE         (IMFGTM, NCOMLOG(61))
C
C     End Cast Crew                                                     
C
      INTEGER*2            ISCREW
      EQUIVALENCE         (ISCREW, NCOMLOG(181))
C
C     Casting Temperature Target                                        
C
      INTEGER*2            ISCSTG
      EQUIVALENCE         (ISCSTG, NCOMLOG(161))
C
C     Cooling Water Flow Target                                         
C
      INTEGER*2            ISCWTG
      EQUIVALENCE         (ISCWTG, NCOMLOG(165))
C
C     End Cast Day of Year                                              
C
      INTEGER*2            ISDAYR
      EQUIVALENCE         (ISDAYR, NCOMLOG(149))
C
C     Grain Refiner Target for Drop                                     
C
      INTEGER*2            ISGRTG
      EQUIVALENCE         (ISGRTG, NCOMLOG(157))
C
C     End Cast Time (Minutes Past Midnight)                             
C
      INTEGER*2            ISTIME
      EQUIVALENCE         (ISTIME, NCOMLOG(153))
C
C     End Cast Year                                                     
C
      INTEGER*2            ISYEAR
      EQUIVALENCE         (ISYEAR, NCOMLOG(145))
C
C     Walk Thru Crew                                                    
C
      INTEGER*2            IWCREW
      EQUIVALENCE         (IWCREW, NCOMLOG(185))
C
C     Start Cast Day of Year for Walkthru                               
C
      INTEGER*2            IWDAYR
      EQUIVALENCE         (IWDAYR, NCOMLOG(141))
C
C     Start Cast Time (Minutes Past Midnight)                           
C
      INTEGER*2            IWTIME
      EQUIVALENCE         (IWTIME, NCOMLOG(137))
C
C     Start Cast Year of Walk Thru                                      
C
      INTEGER*2            IWYEAR
      EQUIVALENCE         (IWYEAR, NCOMLOG(133))
C
C     Print Header for Cast History                                     
C
      LOGICAL*2            LDLGHA
      EQUIVALENCE         (LDLGHA, NCOMLOG(317))
C
C     Flag used to Print the Stop Cast Report                           
C
      LOGICAL*2            LNOPRT
      EQUIVALENCE         (LNOPRT, NCOMLOG(313))
C
C     Trough Jacks in Auto at Start of Cast                             
C
      LOGICAL*2            LTJCST
      EQUIVALENCE         (LTJCST, NCOMLOG(93))
C
C     Maximum CO2 Flow Rate                                             
C
      REAL*4               RCO2MX
      EQUIVALENCE         (RCO2MX, NCOMLOG(41))
C
C     Maximum Casting Temperature                                       
C
      REAL*4               RCSMAX
      EQUIVALENCE         (RCSMAX, NCOMLOG(29))
C
C     Minimum Casting Temperature                                       
C
      REAL*4               RCSMIN
      EQUIVALENCE         (RCSMIN, NCOMLOG(33))
C
C     Minimum Cooling Water Flow                                        
C
      REAL*4               RCWFMN
      EQUIVALENCE         (RCWFMN, NCOMLOG(49))
C
C     Maximum Cooling Water Flow                                        
C
      REAL*4               RCWFMX
      EQUIVALENCE         (RCWFMX, NCOMLOG(45))
C
C     Maximum Grain Refiner Speed                                       
C
      REAL*4               RGRMAX
      EQUIVALENCE         (RGRMAX, NCOMLOG(53))
C
C     Minimum Grain Refiner Speed                                       
C
      REAL*4               RGRMIN
      EQUIVALENCE         (RGRMIN, NCOMLOG(57))
C
C     One Inch Calibration Box Readings (#1, #2, #3, etc.)              
C
      REAL*4               RMLCB1(7)
      EQUIVALENCE         (RMLCB1, NCOMLOG(265))
C
C     Three Inch Calibration Box Readings (#1, #2, #3, etc.)            
C
      REAL*4               RMLCB3(7)
      EQUIVALENCE         (RMLCB3, NCOMLOG(281))
C
C     North LVDT Value at the Start of the Cast                         
C
      REAL*4               RNLTCS
      EQUIVALENCE         (RNLTCS, NCOMLOG(85))
C
C     Platen LVDT Value at Block Set Time                               
C
      REAL*4               RPLTCE
      EQUIVALENCE         (RPLTCE, NCOMLOG(97))
C
C     Platen LVDT Value at Cast Start Time                              
C
      REAL*4               RPLTCS
      EQUIVALENCE         (RPLTCS, NCOMLOG(101))
C
C     Ending Actual Ingot Length of Drop                                
C
      REAL*4               RRACIL
      EQUIVALENCE         (RRACIL, NCOMLOG(173))
C
C     South LVDT Value at the Start of the Cast                         
C
      REAL*4               RSLTCS
      EQUIVALENCE         (RSLTCS, NCOMLOG(89))
C
C     DATA STATEMENTS
C
      END

--------------------------------------------------------------------------

comlog_l.s

	.set noat
	.set noreorder
	.text
	.align 4
	.globl	comlog_l
	.ent	comlog_l
comlog_l:
	ldgp	$gp, 0($27)
	lda	$sp, -16($sp)
	stq	$26, 0($sp)
	.mask 0x04000000,-16
	.frame  $sp, 16, $26, 0
	.prologue 1
	.extern	comlog_ 8192
	.rdata
	.align 4
comlog_nm:
	.ascii	"comlog\X00"
	.text
	lda	$16, comlog_nm
	mov	8192, $17
	jsr	$26, mapgbl_
	ldgp	$gp, 0($26)
	.text
	ldq	$26, 0($sp)
	lda	$sp, 16($sp)
	ret	($26)
	.end	comlog_l
    
1190.7Does shcom_connect(3f) do what they want?SUBPAC::FARICELLIMon Feb 24 1997 11:275
   Is the customer aware of shcom_connect(3f), which sounds like
   a much cleaner way to get common blocks shared across processes.

   -- John Faricelli
1190.8Not a bugTLE::EKLUNDAlways smiling on the inside!Tue Feb 25 1997 10:5719
    	Currently the .s file will only contain references to
    the original local symbols if they are data initialized
    (via data statements or the like).  If you take a closer
    look at the C example given a few notes back, you will
    observe that the local variables were declared static
    AND data initialized.  Both of these are required in order
    for the symbols to appear in the .s file!  So C has
    exactly the same behavior as Fortran for local symbols.
    
    	I looked at what it might take to change this, and
    it does NOT look simple.  It is unlikely that we could
    justify the effort to change this.
    
    	We will add this as a low priority item for possible
    future work.
    
    Cheers!
    Dave Eklund
    
1190.9Great Info!RHETT::PARKERTue Feb 25 1997 17:2811
    
    Thanks!
    
    I understand even better now. Thanks to all who replied. I
    have asked the customer about shcom_connect(3) but I have
    not heard back yet. I expect they can work around the issue
    with all of the information supplied here. 
    
    Thanks again!!
    
    Lee
1190.10RHETT::PARKERThu Feb 27 1997 11:599
    
    
    RE: .7 - Should shcom_connect(3) work with System V shared
    memory. They can't seem to get it to work...
    
    Thanks, 
    
    Lee
    
1190.11shcom_connect(3f) has nothing to do with Sys V ipcSUBPAC::FARICELLIFri Feb 28 1997 08:2912
   shcom_connect(3f) doesn't have anything to do with System V
   shared memory. It uses mmap(3) to map a shared library containing
   the common block to be shared amongst processes.
   I assume that the end user is trying to share a common block across
   multiple processes, correct?

   The man page "man 3f shcom_connect" has a complete example.

   What exactly is the user trying to achieve?

   -- John Faricelli
1190.12.6 explains what they are trying to doRHETT::PARKERFri Feb 28 1997 11:1517
    
    John,
    
    Thanks for the reply. I posted an explanation of what they are
    trying to do in .6. 
    
    >> I assume that the end user is trying to share a common block across
    >> multiple processes, correct?
    
    Yes. But, they have already implemented it using SysV shared memory
    and they think it will be too much work to change it now.
    
    Thanks for the help! I don't know if there is anything else we can
    do for them. If anyone has any ideas, I'm open to them.
    
    Lee
    
1190.13If they'd rather munge object files, be my guestSUBPAC::FARICELLIFri Feb 28 1997 14:2613
   I can't think of anything more cludgy that what was posted in reply .6

   I proposed shcom_connect() as a supported way to get the end result
   they want. I don't think it would be that big a deal -- they just
   create a block data subroutine with the common blocks they wish to share,
   make it into a shared library, and then call shcom_connect().

   But the customer is always right... ;-)

   -- John Faricelli