This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[gomp] fix 24845


We'll now automatically find all the right libraries when -fopenmp
is present on the link line.  This required some amount of hoop
jumping, since we don't know exactly what set of libraries is 
needed until we've done some autoconf probing.  This doesn't seem
too terribly gross though.


r~


        PR 24845
gcc/
        * gcc.c (link_gomp_spec): New.
        (static_specs): Include it.
        (LINK_COMMAND_SPEC): Add link_gomp.
        (GOMP_SELF_SPECS): New.
        (driver_self_specs): Include it.
        (switch_matches): Don't mark inline.
        (main): Load libgomp.spec.
libgomp/
        * Makefile.am (nodist_toolexeclib_HEADERS): New.
        * configure.ac (link_gomp): New.  Substitute it.
        (AC_CONFIG_FILES): Add libgomp.spec.
        * libgomp.spec.in: New file.
        * Makefile.in, testsuite/Makefile.in, configure: Rebuild.
        * testsuite/lib/libgomp-dg.exp: Add -B${blddir}/ to flags.

=== gcc/gcc.c
==================================================================
--- gcc/gcc.c	(revision 107154)
+++ gcc/gcc.c	(local)
@@ -697,7 +697,7 @@
 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
     %(linker) %l " LINK_PIE_SPEC "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\
     %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
-    %{static:} %{L*} %(mfwrap) %(link_libgcc) %o %(mflib)\
+    %{static:} %{L*} %(mfwrap) %(link_gomp) %(link_libgcc) %o %(mflib)\
     %{fprofile-arcs|fprofile-generate|coverage:-lgcov}\
     %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\
     %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
@@ -736,6 +736,7 @@
 static const char *lib_spec = LIB_SPEC;
 static const char *mfwrap_spec = MFWRAP_SPEC;
 static const char *mflib_spec = MFLIB_SPEC;
+static const char *link_gomp_spec = "";
 static const char *libgcc_spec = LIBGCC_SPEC;
 static const char *endfile_spec = ENDFILE_SPEC;
 static const char *startfile_spec = STARTFILE_SPEC;
@@ -834,8 +835,14 @@
 #define DRIVER_SELF_SPECS ""
 #endif
 
-static const char *const driver_self_specs[] = { DRIVER_SELF_SPECS };
+/* Adding -fopenmp should imply pthreads.  This is particularly important
+   for targets that use different start files and suchlike.  */
+#define GOMP_SELF_SPECS "%{fopenmp: -pthread}"
 
+static const char *const driver_self_specs[] = {
+  DRIVER_SELF_SPECS, GOMP_SELF_SPECS
+};
+
 #ifndef OPTION_DEFAULT_SPECS
 #define OPTION_DEFAULT_SPECS { "", "" }
 #endif
@@ -1534,6 +1541,7 @@
   INIT_STATIC_SPEC ("lib",			&lib_spec),
   INIT_STATIC_SPEC ("mfwrap",			&mfwrap_spec),
   INIT_STATIC_SPEC ("mflib",			&mflib_spec),
+  INIT_STATIC_SPEC ("link_gomp",		&link_gomp_spec),
   INIT_STATIC_SPEC ("libgcc",			&libgcc_spec),
   INIT_STATIC_SPEC ("startfile",		&startfile_spec),
   INIT_STATIC_SPEC ("switches_need_spaces",	&switches_need_spaces),
@@ -5474,10 +5482,10 @@
 	  && input_suffix[end_atom - atom] == '\0');
 }
 
-/* Inline subroutine of handle_braces.  Returns true if a switch
+/* Subroutine of handle_braces.  Returns true if a switch
    matching the atom bracketed by ATOM and END_ATOM appeared on the
    command line.  */
-static inline bool
+static bool
 switch_matches (const char *atom, const char *end_atom, int starred)
 {
   int i;
@@ -6632,6 +6640,20 @@
       putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH");
       putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV);
 
+      /* If -fopenmp is in effect, load the spec file that contains
+	 the set of libraries we may need.  */
+      {
+	const char *str = "fopenmp";
+	char *file;
+
+	if (switch_matches (str, str+strlen(str), 0))
+	  {
+	    str = "libgomp.spec";
+	    file = find_a_file (&startfile_prefixes, str, R_OK, 0);
+	    read_specs (file ? file : str, FALSE);
+	  }
+      }
+
       value = do_spec (link_command_spec);
       if (value < 0)
 	error_count = 1;
=== libgomp/Makefile.am
==================================================================
--- libgomp/Makefile.am	(revision 107154)
+++ libgomp/Makefile.am	(local)
@@ -18,6 +18,7 @@
 AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
 
 toolexeclib_LTLIBRARIES = libgomp.la
+nodist_toolexeclib_HEADERS = libgomp.spec
 
 if LIBGOMP_BUILD_VERSIONED_SHLIB
 libgomp_version_script = -Wl,--version-script,$(top_srcdir)/libgomp.map
@@ -35,6 +36,7 @@
 if USE_FORTRAN
 nodist_include_HEADERS += omp_lib.mod omp_lib_kinds.mod
 endif
+
 omp.h: omp.h.in mkomp_h.pl
 	$(PERL) -w $(srcdir)/mkomp_h.pl "$(COMPILE)" $(srcdir)/omp.h.in omp.h
 omp_lib.h: omp_lib.h.in mkomp_h.pl
=== libgomp/configure.ac
==================================================================
--- libgomp/configure.ac	(revision 107154)
+++ libgomp/configure.ac	(local)
@@ -203,7 +203,18 @@
   multilib_arg=
 fi
 
+# Set up the set of libraries that we need to link against for libgomp.
+# Note that the GOMP_DRIVER_SPEC in gcc.c will force -pthread for -fopenmp,
+# which will force linkage against -lpthread (or equivalent for the system).
+# That's not 100% ideal, but about the best we can do easily.
+if test $enable_shared = yes; then
+  link_gomp="-lgomp %{static: $LIBS}"
+else
+  link_gomp="-lgomp $LIBS"
+fi
+AC_SUBST(link_gomp)
+
 AM_CONDITIONAL([USE_FORTRAN], [test "$ac_cv_fc_compiler_gnu" = yes])
 
-AC_CONFIG_FILES(Makefile testsuite/Makefile)
+AC_CONFIG_FILES(Makefile testsuite/Makefile libgomp.spec)
 AC_OUTPUT
=== libgomp/testsuite/lib/libgomp-dg.exp
==================================================================
--- libgomp/testsuite/lib/libgomp-dg.exp	(revision 107154)
+++ libgomp/testsuite/lib/libgomp-dg.exp	(local)
@@ -104,8 +104,9 @@
     set_ld_library_path_env_vars
 
     set ALWAYS_CFLAGS ""
+    lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
+    lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
     lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
-    lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
     lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs -lgomp"
     if { [info exists lang_test_file] && [file exists "${blddir}/"] } {
 	lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/${lang_library_path} ${lang_link_flags}"
=== libgomp/libgomp.spec.in
==================================================================
--- libgomp/libgomp.spec.in	(revision 107154)
+++ libgomp/libgomp.spec.in	(local)
@@ -0,0 +1,3 @@
+# This spec file is read by gcc when linking.  It is used to specify the
+# standard libraries we need in order to link with -fopenmp.
+*link_gomp: @link_gomp@


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