list@decus.com.au (08/14/90)
I seem to have a problem when archiving BLOCK DATA program units. Following is a listing of a test. PROGRAM MAIN CHARACTER*1 CH1,CH2,CH3 COMMON/CHARS/CH1,CH2,CH3 CALL SEG END SUBROUTINE SEG CHARACTER*1 CH1,CH2,CH3,CH10,CH11,CH12 COMMON/CHARS/CH1,CH2,CH3 CH10 = CH1 CH11 = CH2 CH12 = CH3 END BLOCK DATA LEO CHARACTER*1 CH1,CH2,CH3 COMMON/CHARS/CH1,CH2,CH3 DATA CH1/"A" DATA CH2/"B" DATA CH3/"C" END When compiling the above code without archiving any of the routines the program behaves as expected (eg. doing a dump in the debugger shows the correct initial and final values). When I archive the BLOCK DATA program unit and link, none of the variables are initialised (eg. a dump shows null values). Has anybody else seen this, knows what's happening, has a work around (I'm talking about 900 subroutines with 60 BLOCK DATA program units, so specifying the BLOCK DATA units individually at link time is not going to work. Thanx in advance, Leo List SIR(Australasia)
list@decus.com.au (08/17/90)
Following is a summary of the replies to this problem. 1) ----------------------------------------------------- a sort-of-kludgy way around this is to CALL the block data routines. then the linker will properly drag them into the executable. at least it works under RSX and VMS linkers... MAIN FOO if (something .false.) CALL ONE ! so it never REALLY gets called, ! but sneaky enough so an optimizer won't ! completely delete the CALL ... END BLOCK DATA ONE blah blah END 2) -------------------------------------------------------------------- This is a common problem with BLOCK DATA. Whenever an archive is used individual modules are linked in only when there is a reference from some other module. For BLOCK DATA subprograms there is never a reference, so they are never linked in from an archive. There is no true solution to this problem, but there are two possible solutions that may or may not work: a) In every module referring to some COMMON block write a reference to the BLOCK DATA subprogram initializing the COMMON block: EXTERNAL BLKDAT0 etc. This will link in the BLOCK DATA subprogram on some systems (but not on others). b) If there is for each COMMON block a major subroutine that is always used when the COMMON block is used you can compile that subroutine and the BLOCK DATA subprogram as a single file. The remark under 1 applies also here, but this works on all Unix systems as far as I know. 3) ---------------------------------------------------------------------- as fas as i know you have to have an EXTERNAL <NAME> statement for each block-data routine to force the linker to load it, e.g. if there is no reference to a block-data-routine the linker does not load it. 4) ---------------------------------------------------------------------- Yes, this is a known problem with the compiler. It has been fixed in a later release. Conclusion --------------------------------------------------------- I have declared all BLOCK DATA <names> as EXTERNALS in my main program. That seems to work ok. As to this being a known problem, I've contacted DEC support and they have yet not found a reason for this problem (nor a work around). Thanks to all who helped trying to solve this Leo List SIR(Australasia)