Bug 38594

Summary: Fortan program don't link post gcc-3.1
Product: Base System Reporter: Steven G. Kargl <kargl>
Component: gnuAssignee: Alexander Kabaev <kan>
Status: Closed FIXED    
Severity: Affects Only Me CC: obrien
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff
none
f77.diff none

Description Steven G. Kargl 2002-05-27 03:50:03 UTC
Fortran programs don't link after the gcc-3.1 due to a missing
libfrtbegin.a.  libF77/main.o was split out into libfrtbegin in
gcc-3.1 and a dependence was built into g77 (via g77spec.c) to 
unconditionally link libfrtbegin into all Fortran programs.

Fix: The following patch creates libfrtbegin.  The file
libg2c/MAIN.c should be repo-copied to gnu/libfrtbegin.

How-To-Repeat: 
Try to compile a Fortran program.  For example,

      program hello
      print*, 'Hello World!'
      end
Comment 1 ru freebsd_committer freebsd_triage 2002-05-27 15:19:24 UTC
On Sun, May 26, 2002 at 07:41:05PM -0700, Steven G. Kargl wrote:
> 
> Fortran programs don't link after the gcc-3.1 due to a missing
> libfrtbegin.a.  libF77/main.o was split out into libfrtbegin in
> gcc-3.1 and a dependence was built into g77 (via g77spec.c) to 
> unconditionally link libfrtbegin into all Fortran programs.
> 
> The following patch creates libfrtbegin.  The file
> libg2c/MAIN.c should be repo-copied to gnu/libfrtbegin.
> 
... and then "cvs remove"d from gnu/lib/libg2c.

> diff -urNb gnu/lib.old/Makefile gnu/lib/Makefile
> --- gnu/lib.old/Makefile	Wed May 15 09:29:45 2002
> +++ gnu/lib/Makefile	Sun May 26 14:44:23 2002
> @@ -19,7 +19,7 @@
>  .endif
>  
>  .if !defined(NO_FORTRAN)
> -SUBDIR+= libg2c
> +SUBDIR+= libfrtbegin libg2c
>  .endif
>  
>  .include <bsd.subdir.mk>
> diff -urNb gnu/lib.old/libfrtbegin/MAIN.c gnu/lib/libfrtbegin/MAIN.c
> --- gnu/lib.old/libfrtbegin/MAIN.c	Wed Dec 31 16:00:00 1969
> +++ gnu/lib/libfrtbegin/MAIN.c	Sun May 26 14:44:40 2002
> @@ -0,0 +1,4 @@
> +/* $FreeBSD: src/gnu/lib/libg2c/MAIN.c,v 1.2 2000/10/31 11:36:33 obrien Exp $ */
> +
> +int
> +MAIN__(){ return 0; }
> diff -urNb gnu/lib.old/libfrtbegin/Makefile gnu/lib/libfrtbegin/Makefile
> --- gnu/lib.old/libfrtbegin/Makefile	Wed Dec 31 16:00:00 1969
> +++ gnu/lib/libfrtbegin/Makefile	Sun May 26 14:47:02 2002
> @@ -0,0 +1,16 @@
> +# $FreeBSD: src/gnu/lib/libg2c/Makefile,v 1.9 2002/05/12 16:00:46 ru Exp $
> +
> +SRCDIR=	${.CURDIR}/../../../contrib/libf2c
> +
> +.PATH: ${SRCDIR} ${SRCDIR}/libF77
> +

${SRCDIR} is not needed in the .PATH.

> +LIB=		frtbegin
> +SHLIB_MAJOR=	1
> +SHLIB_MINOR=	0
> +

There should only be the static frtbegin library, there's no
point in shared and profiled versions; hence, these SHLIB_*'s
lines should be replaced by NOPIC=YES and NOPROFILE=YES.

> +SRCS=		main.c MAIN.c
> +
> +CFLAGS+=	-I${SRCDIR} -I${SRCDIR}/libF77
> +CFLAGS+=	-I${.CURDIR}
> +

This compiles OK without any CFLAGS.

> +.include <bsd.lib.mk>
> diff -urNb gnu/lib.old/libg2c/Makefile gnu/lib/libg2c/Makefile
> --- gnu/lib.old/libg2c/Makefile	Sun May 12 09:00:46 2002
> +++ gnu/lib/libg2c/Makefile	Sun May 26 14:49:59 2002
> @@ -10,7 +10,7 @@
>  
>  # Traditional FORTRAN Library members defined in libF77
>  
> -F77MISC=	F77_aloc.c main.c s_rnge.c abort_.c getarg_.c \
> +F77MISC=	F77_aloc.c s_rnge.c abort_.c getarg_.c \
>  		iargc_.c getenv_.c signal_.c s_stop.c s_paus.c system_.c \
>  		cabs.c derf_.c derfc_.c erf_.c erfc_.c sig_die.c exit_.c \
>  		setarg.c setsig.c
> @@ -79,7 +79,7 @@
>  		secnds.o second.o signal.o sleep.o srand.o stat.o symlnk.o \
>  		system.o time.o ttynam.o umask.o unlink.o vxtidt.o vxttim.o
>  
> -LIBF77SRCS=	${F77SRCS} ${I77SRCS} ${U77SRCS} ${E77SRCS} MAIN.c
> +LIBF77SRCS=	${F77SRCS} ${I77SRCS} ${U77SRCS} ${E77SRCS}
>  
>  SRCS=		${LIBF77SRCS}
>  OBJS=		${E77OBJS}
> 
Other than that, looks good.


Cheers,
-- 
Ruslan Ermilov		Sysadmin and DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 2 Steven G. Kargl 2002-05-27 16:33:57 UTC
Ruslan Ermilov said:
> 
> Other than that, looks good.
> 

I made the changes you suggested.  libfrtbegin
built without a problem and I could build some
test Fortran programs.

Do you want an updated patch or will you or
David make the minor changes after applying
the current patch?

-- 
Steve
http://troutmask.apl.washington.edu/~kargl/
Comment 3 ru freebsd_committer freebsd_triage 2002-05-27 16:37:41 UTC
On Mon, May 27, 2002 at 08:33:57AM -0700, Steven G. Kargl wrote:
> Ruslan Ermilov said:
> > 
> > Other than that, looks good.
> > 
> 
> I made the changes you suggested.  libfrtbegin
> built without a problem and I could build some
> test Fortran programs.
> 
> Do you want an updated patch or will you or
> David make the minor changes after applying
> the current patch?
> 
Providing an updated patch might be helpful in saving David's time.
I don't think you should "spam" the PR database with it though.  :-)


Cheers,
-- 
Ruslan Ermilov		Sysadmin and DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 4 kargls 2002-06-02 23:27:30 UTC
Here the corrected patched (i.e., Ruslan's suggestions have been
incorporated).  This patch had been sent to obrien@freebsd.org.

--
steve
Comment 5 David E. O'Brien freebsd_committer freebsd_triage 2002-06-08 20:53:24 UTC
State Changed
From-To: open->analyzed

I committed a work around; but this PR should stay around a little longer 
to rembmer the issue.
Comment 6 David E. O'Brien freebsd_committer freebsd_triage 2002-06-08 20:56:06 UTC
My commited "fix" is a hack.  This diff would be the true fix if we
wanted to go to all this trouble.

Index: contrib/gcc/f/g77spec.c
===================================================================
RCS file: /home/ncvs/src/contrib/gcc/f/g77spec.c,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 g77spec.c
--- contrib/gcc/f/g77spec.c	1 Feb 2002 18:15:47 -0000	1.1.1.4
+++ contrib/gcc/f/g77spec.c	8 Jun 2002 19:43:59 -0000
@@ -52,14 +52,23 @@
 #ifndef MATH_LIBRARY
 #define MATH_LIBRARY "-lm"
 #endif
+#ifndef MATH_LIBRARY_PROFILE
+#define MATH_LIBRARY_PROFILE "-lm"
+#endif
 
 #ifndef FORTRAN_INIT
 #define FORTRAN_INIT "-lfrtbegin"
 #endif
+#ifndef FORTRAN_INIT_PROFILE
+#define FORTRAN_INIT_PROFILE "-lfrtbegin"
+#endif
 
 #ifndef FORTRAN_LIBRARY
 #define FORTRAN_LIBRARY "-lg2c"
 #endif
+#ifndef FORTRAN_LIBRARY_PROFILE
+#define FORTRAN_LIBRARY_PROFILE "-lg2c"
+#endif
 
 /* Options this driver needs to recognize, not just know how to
    skip over.  */
@@ -79,6 +88,7 @@
   OPTION_nostdlib,		/* Aka --no-standard-libraries, or
 				   -nodefaultlibs. */
   OPTION_o,			/* Aka --output. */
+  OPTION_p,			/* Aka --profile. */
   OPTION_S,			/* Aka --assemble. */
   OPTION_syntax_only,		/* -fsyntax-only. */
   OPTION_v,			/* Aka --verbose. */
@@ -167,6 +177,9 @@
     opt = OPTION_L, arg = text + 2;
   else if (text[1] == 'o')
     opt = OPTION_o;
+  else if ((text[1] == 'p') && (text[2] == '\0')
+           || (text[1] == 'p') && (text[2] == 'g') && (text[3] == '\0'))
+    opt = OPTION_p;
   else if ((text[1] == 'S') && (text[2] == '\0'))
     opt = OPTION_S, skip = 0;
   else if (text[1] == 'V')
@@ -291,6 +304,9 @@
   /* By default, we throw on the math library if we have one.  */
   int need_math = (MATH_LIBRARY[0] != '\0');
 
+  /* If non-zero, the user gave us the `-p' or `-pg' flag.  */ 
+  int saw_profile_flag = 0;
+
   /* The number of input and output files in the incoming arg list.  */
   int n_infiles = 0;
   int n_outfiles = 0;
@@ -359,6 +375,11 @@
 	  ++n_outfiles;
 	  break;
 
+	case OPTION_p:
+	  saw_profile_flag = 1;
+	  library = FORTRAN_LIBRARY_PROFILE;
+	  break;
+
 	case OPTION_v:
 	  verbose = 1;
 	  break;
@@ -432,7 +453,7 @@
 	  /* Not a filename or library. */
 
 	 if (saw_library == 1 && need_math)    /* -l<library>. */
-	    append_arg (MATH_LIBRARY);
+	    append_arg (saw_profile_flag ? MATH_LIBRARY_PROFILE : MATH_LIBRARY);
 
 	  saw_library = 0;
 
@@ -483,10 +504,12 @@
 		{
 		  if (0 == use_init)
 		    {
-		      append_arg (FORTRAN_INIT);
+		      append_arg (saw_profile_flag ? FORTRAN_INIT_PROFILE
+				  : FORTRAN_INIT);
 		      use_init = 1;
 		    }
-		  append_arg (FORTRAN_LIBRARY);
+		  append_arg (saw_profile_flag ? FORTRAN_LIBRARY_PROFILE
+			      : FORTRAN_LIBRARY);
 		}
 	    }
 	  else if (strcmp (argv[i], FORTRAN_LIBRARY) == 0)
@@ -494,7 +517,8 @@
 	  else
 	    {		/* Other library, or filename. */
 	     if (saw_library == 1 && need_math)
-		append_arg (MATH_LIBRARY);
+		append_arg (saw_profile_flag ? MATH_LIBRARY_PROFILE
+			    : MATH_LIBRARY);
 	      saw_library = 0;
 	    }
 	}
@@ -513,13 +537,14 @@
 	case 0:
 	  if (0 == use_init)
 	    {
-	      append_arg (FORTRAN_INIT);
+	      append_arg (saw_profile_flag ? FORTRAN_INIT_PROFILE
+			  : FORTRAN_INIT);
 	      use_init = 1;
 	    }
 	  append_arg (library);
 	case 1:
 	 if (need_math)
-	   append_arg (MATH_LIBRARY);
+	   append_arg (saw_profile_flag ? MATH_LIBRARY_PROFILE : MATH_LIBRARY);
 	default:
 	  break;
 	}
Index: gnu/lib/Makefile
===================================================================
RCS file: /home/ncvs/src/gnu/lib/Makefile,v
retrieving revision 1.38
diff -u -r1.38 Makefile
--- gnu/lib/Makefile	29 May 2002 00:45:50 -0000	1.38
+++ gnu/lib/Makefile	8 Jun 2002 19:44:01 -0000
@@ -19,7 +19,7 @@
 .endif
 
 .if !defined(NO_FORTRAN)
-SUBDIR+= libg2c
+SUBDIR+= libfrtbegin libg2c
 .endif
 
 .include <bsd.subdir.mk>
Index: gnu/lib/libfrtbegin/Makefile
===================================================================
RCS file: gnu/lib/libfrtbegin/Makefile
diff -N gnu/lib/libfrtbegin/Makefile
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/lib/libfrtbegin/Makefile	8 Jun 2002 19:46:34 -0000
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+SRCDIR=	${.CURDIR}/../../../contrib/libf2c
+.PATH: ${SRCDIR}/libF77
+
+LIB=	frtbegin
+SRCS=	main.c
+
+.include <bsd.lib.mk>
Index: gnu/lib/libg2c/Makefile
===================================================================
RCS file: /home/ncvs/src/gnu/lib/libg2c/Makefile,v
retrieving revision 1.9
diff -u -r1.9 Makefile
--- gnu/lib/libg2c/Makefile	12 May 2002 16:00:46 -0000	1.9
+++ gnu/lib/libg2c/Makefile	8 Jun 2002 19:44:01 -0000
@@ -10,7 +11,7 @@
 
 # Traditional FORTRAN Library members defined in libF77
 
-F77MISC=	F77_aloc.c main.c s_rnge.c abort_.c getarg_.c \
+F77MISC=	F77_aloc.c s_rnge.c abort_.c getarg_.c \
 		iargc_.c getenv_.c signal_.c s_stop.c s_paus.c system_.c \
 		cabs.c derf_.c derfc_.c erf_.c erfc_.c sig_die.c exit_.c \
 		setarg.c setsig.c
Index: gnu/usr.bin/cc/cc_tools/freebsd-native.h
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/cc/cc_tools/freebsd-native.h,v
retrieving revision 1.19
diff -u -r1.19 freebsd-native.h
--- gnu/usr.bin/cc/cc_tools/freebsd-native.h	6 Jun 2002 03:47:02 -0000	1.19
+++ gnu/usr.bin/cc/cc_tools/freebsd-native.h	8 Jun 2002 19:44:01 -0000
@@ -49,6 +49,10 @@
 /* For the native system compiler, we actually build libgcc in a profiled
    version.  So we should use it with -pg.  */
 #define LIBGCC_SPEC "%{!pg: -lgcc} %{pg: -lgcc_p}"
+#define LIBSTDCXX_PROFILE	"-lstdc++_p"
+#define MATH_LIBRARY_PROFILE	"-lm_p"
+#define FORTRAN_INIT_PROFILE	"-lfrtbegin_p"
+#define FORTRAN_LIBRARY_PROFILE	"-lg2c_p"
 
 /* FreeBSD is 4.4BSD derived */
 #define bsd4_4
Index: gnu/usr.bin/cc/f77/Makefile
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/cc/f77/Makefile,v
retrieving revision 1.18
diff -u -r1.18 Makefile
--- gnu/usr.bin/cc/f77/Makefile	8 Jun 2002 18:48:40 -0000	1.18
+++ gnu/usr.bin/cc/f77/Makefile	8 Jun 2002 19:44:01 -0000
@@ -10,7 +10,6 @@
 
 CFLAGS+= -DDEFAULT_TARGET_VERSION=\"$(version)\"
 CFLAGS+= -DDEFAULT_TARGET_MACHINE=\"$(target)\"
-CFLAGS+= -DFORTRAN_INIT=\"-lg2c\"
 
 DPADD=	${LIBCC_INT}
 LDADD=	${LIBCC_INT}
Comment 7 Gerald Pfeifer freebsd_committer freebsd_triage 2003-03-26 17:48:44 UTC
State Changed
From-To: analyzed->feedback

As far as I can see this has been fixed on 5-CURRENT in the meantime (and 
also doesn't appear to be a problem on 4.7).  Can you confirm this?
Comment 8 Gerald Pfeifer freebsd_committer freebsd_triage 2003-03-31 00:58:09 UTC
State Changed
From-To: feedback->analyzed

We probably should keep this open in case someone (David O'Brien) wants to 
go for the full patch in the audit trail.
Comment 9 Kris Kennaway freebsd_committer freebsd_triage 2003-07-13 01:18:24 UTC
Responsible Changed
From-To: freebsd-bugs->kan

Assign to gcc maintainer
Comment 10 Mark Linimon freebsd_committer freebsd_triage 2007-07-10 16:48:02 UTC
State Changed
From-To: analyzed->closed

Closed at submitter's request (OBE).