gfortran, ncar and blockdata_test failures

Jack Howarth howarth@bromo.msbb.uc.edu
Sun Nov 18 21:25:00 GMT 2007


Walter,
   I asked HJ Lu and he suggested I look at...

http://sourceware.org/ml/binutils/2003-04/msg00245.html
http://sourceware.org/ml/binutils/2003-04/msg00253.html

which are existing common symbol bugs. On powerpc-apple-darwin9,
the first seems to pass okay...

gcc -O -g -c main.c
gcc -O -g -c foo.c
gcc -o foo1 -B./ main.o foo.o
gcc -o foo2 -B./ foo.o main.o
for f in foo1 foo2; do echo "Running: $f"; ./$f; \
	  if [ $? != 0 ]; then echo Failed; fi; done
Running: foo1
0: 0
1: 1
2: 2
3: 3
Running: foo2
0: 0
1: 1
2: 2
3: 3

However the second generates and interesting warning...

gcc -O -g -c main.c
gcc -O -g -c foo.c
gcc -o foo1 -B./ main.o foo.o
ld: warning alignment lost in merging tentative definition _bar
gcc -o foo2 -B./ foo.o main.o
for f in foo1 foo2; do echo "Running: $f"; ./$f; \
	  if [ $? != 0 ]; then echo Failed; fi; done
Running: foo1
0x2014: 4
0x2058: 8
Running: foo2
0x2014: 4
0x2058: 8

This is the same warning that alerted us to the fact that bind-c
support doesn't provide the same alignment in gfortran as c uses...

http://gcc.gnu.org/ml/fortran/2007-08/msg00138.html

I may try a local build of gcc 4.2.2 on Leopard using a modification
of the proposed patch that uses the same alignment as c with or
without bind-c.

Index: gcc/fortran/trans-common.c
===================================================================
--- gcc/fortran/trans-common.c	(revision 127182)
+++ gcc/fortran/trans-common.c	(working copy)
@@ -413,7 +413,20 @@ build_common_decl (gfc_common_head *com,
       SET_DECL_ASSEMBLER_NAME (decl, gfc_sym_mangled_common_id (com));
       TREE_PUBLIC (decl) = 1;
       TREE_STATIC (decl) = 1;
-      DECL_ALIGN (decl) = BIGGEST_ALIGNMENT;
+	  /* Do not set the alignment for bind(c) common blocks to
+	     BIGGEST_ALIGNMENT because that won't match what C does.  Also,
+	     for common blocks with one element, the alignment must be
+	     that of the field within the common block in order to match
+	     what C will do.  */
+	  tree field = NULL_TREE;
+	  field = TYPE_FIELDS (TREE_TYPE (decl));
+	  if (TREE_CHAIN (field) == NULL_TREE)
+	    DECL_ALIGN (decl) = TYPE_ALIGN (TREE_TYPE (field));
       DECL_USER_ALIGN (decl) = 0;
       GFC_DECL_COMMON_OR_EQUIV (decl) = 1;

It will be interesting to see if that eliminates blockdata_test failures
on Darwin.
               Jack

On Sun, Nov 18, 2007 at 09:04:45AM -0800, Walter Spector wrote:
> Jack Howarth wrote:
> > 
> > Walter,
> >    Now I am confused. I hadn't realized that gfortran was passing
> > this test passes under linux i386 and x86_64. Does the linux linker
> > do something to explicitly make this work or is it just a happy
> > accident? Perhaps a radar report could be opened against the Darwin
> > linker if we knew what had to be done to fix the issue linker-side.
> 
> Hmmm.  I tried the test on my redhat system, and like Tobias, the
> 'bad' case works!
> 
> The wierd thing is that ld on my cygwin system is actually more
> recent than the ld on my redhat system.  (v2.17.50 on cygwin
> and v2.15.92.0.2 on redhat.)
> 
> Go figure.
> 
> W.



More information about the Fortran mailing list