This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, v3] Potential solution to librt issue.
I have a theory
I don't know if you got it with gdb or with your brain, but your theory
is very right.
The problem is I'm not sure how to pass "--as-needed -lrt
--no-as-needed" as a single argument (maybe just quoting is
sufficient, I have yet to test) otherwise maybe the test should be if
strcmp then return the concatenation of the rest of the argv's.
This is a mess because there is no place to free the concatenation.
It's easiest to use a backslash to escape the space and have everything
passed as a single argument. Then, the do_spec_1 call in
handle_spec_function separates the arguments again. The attached
cumulative patch seems to work on Paolo C.'s simple test case.
Even if Paolo C. can approve the libstdc++-v3 bits, it needs a GWP for
the GCC parts.
Thanks for the help with this issue.
Paolo
gcc:
2008-07-25 Paolo Bonzini <bonzini@gnu.org>
Chris Fairles <chris.fairles@gmail.com>
* cppspec.c (lang_driver_name): New.
* gccspec.c (lang_driver_name): New.
* gcc.c (if_language_spec_function): New.
(static_spec_functions): Register it.
* gcc.h (lang_driver_name): New.
* config/linux.h (LIB_SPEC): Add -lrt if needed and for C++ only.
(USE_LD_AS_NEEDED): Move above.
gcc/cp:
2008-07-25 Paolo Bonzini <bonzini@gnu.org>
Chris Fairles <chris.fairles@gmail.com>
* g++spec.c (lang_driver_name): New.
gcc/fortran:
2008-07-25 Paolo Bonzini <bonzini@gnu.org>
Chris Fairles <chris.fairles@gmail.com>
* gfortranspec.c (lang_driver_name): New.
gcc/java:
2008-07-25 Paolo Bonzini <bonzini@gnu.org>
Chris Fairles <chris.fairles@gmail.com>
* jvspec.c (lang_driver_name): New.
libstdc++-v3:
2008-07-25 Paolo Bonzini <bonzini@gnu.org>
Chris Fairles <chris.fairles@gmail.com>
* acinclude.m4: Reinstate clock_gettime check, but don't link
libstdc++-v3 with librt.
* src/Makefile.am: Reinstate previous change to add GLIBCXX_LIBS.
* configure: Regenerate.
* configure.in: Likewise.
* Makefile.in: Likewise.
* src/Makefile.in: Likewise.
* libsup++/Makefile.in: Likewise.
* po/Makefile.in: Likewise.
* doc/Makefile.in: Likewise.
* src/chrono.cc (system_clock::now): Move...
* include/std/chrono: ... here.
* testsuite/20_util/duration/cons/1_neg.cc: Adjust line numbers.
* config/abi/pre/gnu.ver: Remove system_clock::now.
Index: gcc/java/jvspec.c
===================================================================
--- gcc/java/jvspec.c (revision 138139)
+++ gcc/java/jvspec.c (working copy)
@@ -685,3 +685,6 @@ lang_specific_pre_link (void)
}
return err;
}
+
+/* Driver name. */
+const char *lang_driver_name = "gcj";
Index: gcc/cppspec.c
===================================================================
--- gcc/cppspec.c (revision 138139)
+++ gcc/cppspec.c (working copy)
@@ -208,3 +208,6 @@ int lang_specific_pre_link (void)
/* Number of extra output files that lang_specific_pre_link may generate. */
int lang_specific_extra_outfiles = 0; /* Not used for cpp. */
+
+/* Driver name. */
+const char *lang_driver_name = "cpp";
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c (revision 138139)
+++ gcc/gcc.c (working copy)
@@ -372,6 +372,7 @@ static const char *convert_filename (con
static const char *getenv_spec_function (int, const char **);
static const char *if_exists_spec_function (int, const char **);
static const char *if_exists_else_spec_function (int, const char **);
+static const char *if_language_spec_function (int, const char **);
static const char *replace_outfile_spec_function (int, const char **);
static const char *version_compare_spec_function (int, const char **);
static const char *include_spec_function (int, const char **);
@@ -1646,6 +1647,7 @@ static const struct spec_function static
{ "getenv", getenv_spec_function },
{ "if-exists", if_exists_spec_function },
{ "if-exists-else", if_exists_else_spec_function },
+ { "if-language", if_language_spec_function },
{ "replace-outfile", replace_outfile_spec_function },
{ "version-compare", version_compare_spec_function },
{ "include", include_spec_function },
@@ -7892,6 +7894,24 @@ if_exists_else_spec_function (int argc,
return argv[1];
}
+/* if-language built-in spec function.
+
+ Expands to the second argument if the current driver is the
+ string in the first argument. */
+
+static const char *
+if_language_spec_function (int argc, const char **argv)
+{
+ /* Must have exactly two arguments. */
+ if (argc != 2)
+ return NULL;
+
+ if (!strcmp (lang_driver_name, argv[0]))
+ return argv[1];
+
+ return NULL;
+}
+
/* replace-outfile built-in spec function.
This looks for the first argument in the outfiles array's name and
Index: gcc/gcc.h
===================================================================
--- gcc/gcc.h (revision 138139)
+++ gcc/gcc.h (working copy)
@@ -75,6 +75,9 @@ extern int n_infiles;
/* Number of extra output files that lang_specific_pre_link may generate. */
extern int lang_specific_extra_outfiles;
+/* Driver name for the if-language function. */
+extern const char *lang_driver_name;
+
/* A vector of corresponding output files is made up later. */
extern const char **outfiles;
Index: gcc/cp/g++spec.c
===================================================================
--- gcc/cp/g++spec.c (revision 138139)
+++ gcc/cp/g++spec.c (working copy)
@@ -349,3 +349,6 @@ int lang_specific_pre_link (void) /* No
/* Number of extra output files that lang_specific_pre_link may generate. */
int lang_specific_extra_outfiles = 0; /* Not used for C++. */
+
+/* Driver name. */
+const char *lang_driver_name = "g++";
Index: gcc/fortran/gfortranspec.c
===================================================================
--- gcc/fortran/gfortranspec.c (revision 138139)
+++ gcc/fortran/gfortranspec.c (working copy)
@@ -595,3 +595,6 @@ lang_specific_pre_link (void) /* Not use
/* Number of extra output files that lang_specific_pre_link may generate. */
int lang_specific_extra_outfiles = 0; /* Not used for F77. */
+
+/* Driver name. */
+const char *lang_driver_name = "gfortran";
Index: gcc/gccspec.c
===================================================================
--- gcc/gccspec.c (revision 138139)
+++ gcc/gccspec.c (working copy)
@@ -104,3 +104,6 @@ lang_specific_pre_link (void)
/* Number of extra output files that lang_specific_pre_link may generate. */
int lang_specific_extra_outfiles = 0; /* Not used for C. */
+
+/* Driver name. */
+const char *lang_driver_name = "gcc";
Index: gcc/config/linux.h
===================================================================
--- gcc/config/linux.h (revision 138139)
+++ gcc/config/linux.h (working copy)
@@ -67,12 +67,26 @@ along with GCC; see the file COPYING3.
#undef CPLUSPLUS_CPP_SPEC
#define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"
-#undef LIB_SPEC
-#define LIB_SPEC \
+#undef BASE_LIB_SPEC
+#define BASE_LIB_SPEC \
"%{pthread:-lpthread} \
%{shared:-lc} \
%{!shared:%{mieee-fp:-lieee} %{profile:-lc_p}%{!profile:-lc}}"
+#ifndef HAVE_LD_AS_NEEDED
+#undef LIB_SPEC
+#define LIB_SPEC BASE_LIB_SPEC " \
+ %{!nostdlib:%{!nodefaultlibs:%:if-language(g++ -lrt)}}"
+
+#else
+#undef LIB_SPEC
+#define LIB_SPEC BASE_LIB_SPEC " \
+ %{!nostdlib:%{!nodefaultlibs:%:if-language(g++ --as-needed\\ -lrt\\ --no-as-needed)}}"
+
+/* Use --as-needed -lgcc_s for eh support. */
+#define USE_LD_AS_NEEDED 1
+#endif
+
#define LINUX_TARGET_OS_CPP_BUILTINS() \
do { \
builtin_define ("__gnu_linux__"); \
@@ -94,11 +108,6 @@ along with GCC; see the file COPYING3.
#define LINK_GCC_C_SEQUENCE_SPEC \
"%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
-/* Use --as-needed -lgcc_s for eh support. */
-#ifdef HAVE_LD_AS_NEEDED
-#define USE_LD_AS_NEEDED 1
-#endif
-
/* Determine which dynamic linker to use depending on whether GLIBC or
uClibc is the default C library and whether -muclibc or -mglibc has
been passed to change the default. */
Index: libstdc++-v3/src/chrono.cc
===================================================================
--- libstdc++-v3/src/chrono.cc (revision 138139)
+++ libstdc++-v3/src/chrono.cc (working copy)
@@ -31,45 +31,11 @@
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
-// conditional inclusion of sys/time.h for gettimeofday
-#if !defined(_GLIBCXX_USE_CLOCK_MONOTONIC) && \
- !defined(_GLIBCXX_USE_CLOCK_REALTIME) && \
- defined(_GLIBCXX_USE_GETTIMEOFDAY)
-#include <sys/time.h>
-#endif
-
namespace std
{
namespace chrono
- {
+ {
const bool system_clock::is_monotonic;
-
- system_clock::time_point
- system_clock::now()
- {
-#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC
- timespec tp;
- // -EINVAL, -EFAULT
- clock_gettime(CLOCK_MONOTONIC, &tp);
- return time_point(duration(chrono::seconds(tp.tv_sec)
- + chrono::nanoseconds(tp.tv_nsec)));
-#elif defined(_GLIBCXX_USE_CLOCK_REALTIME)
- timespec tp;
- // -EINVAL, -EFAULT
- clock_gettime(CLOCK_REALTIME, &tp);
- return time_point(duration(chrono::seconds(tp.tv_sec)
- + chrono::nanoseconds(tp.tv_nsec)));
-#elif defined(_GLIBCXX_USE_GETTIMEOFDAY)
- timeval tv;
- // EINVAL, EFAULT
- gettimeofday(&tv, NULL);
- return time_point(duration(chrono::seconds(tv.tv_sec)
- + chrono::microseconds(tv.tv_usec)));
-#else
- std::time_t __sec = std::time(0);
- return system_clock::from_time_t(__sec);
-#endif
- }
}
}
Index: libstdc++-v3/src/Makefile.am
===================================================================
--- libstdc++-v3/src/Makefile.am (revision 138139)
+++ libstdc++-v3/src/Makefile.am (working copy)
@@ -196,10 +196,14 @@ vpath % $(top_srcdir)
libstdc___la_SOURCES = $(sources)
libstdc___la_LIBADD = \
+ $(GLIBCXX_LIBS) \
$(top_builddir)/libmath/libmath.la \
$(top_builddir)/libsupc++/libsupc++convenience.la
-libstdc___la_DEPENDENCIES = ${version_dep} $(libstdc___la_LIBADD)
+libstdc___la_DEPENDENCIES = \
+ ${version_dep} \
+ $(top_builddir)/libmath/libmath.la \
+ $(top_builddir)/libsupc++/libsupc++convenience.la
libstdc___la_LDFLAGS = \
-version-info $(libtool_VERSION) ${version_arg} -lm
Index: libstdc++-v3/include/std/chrono
===================================================================
--- libstdc++-v3/include/std/chrono (revision 138139)
+++ libstdc++-v3/include/std/chrono (working copy)
@@ -51,6 +51,13 @@
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+// conditional inclusion of sys/time.h for gettimeofday
+#if !defined(_GLIBCXX_USE_CLOCK_MONOTONIC) && \
+ !defined(_GLIBCXX_USE_CLOCK_REALTIME) && \
+ defined(_GLIBCXX_USE_GETTIMEOFDAY)
+#include <sys/time.h>
+#endif
+
namespace std
{
namespace chrono
@@ -589,7 +596,31 @@ namespace std
#endif
static time_point
- now();
+ now()
+ {
+#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC
+ timespec tp;
+ // -EINVAL, -EFAULT
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+ return time_point(duration(chrono::seconds(tp.tv_sec)
+ + chrono::nanoseconds(tp.tv_nsec)));
+#elif defined(_GLIBCXX_USE_CLOCK_REALTIME)
+ timespec tp;
+ // -EINVAL, -EFAULT
+ clock_gettime(CLOCK_REALTIME, &tp);
+ return time_point(duration(chrono::seconds(tp.tv_sec)
+ + chrono::nanoseconds(tp.tv_nsec)));
+#elif defined(_GLIBCXX_USE_GETTIMEOFDAY)
+ timeval tv;
+ // EINVAL, EFAULT
+ gettimeofday(&tv, NULL);
+ return time_point(duration(chrono::seconds(tv.tv_sec)
+ + chrono::microseconds(tv.tv_usec)));
+#else
+ std::time_t __sec = std::time(0);
+ return system_clock::from_time_t(__sec);
+#endif
+ }
// Map to C API
static std::time_t
Index: libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc
===================================================================
--- libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc (revision 138139)
+++ libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc (working copy)
@@ -41,6 +41,6 @@ test02()
// { dg-error "instantiated from here" "" { target *-*-* } 30 }
// { dg-error "instantiated from here" "" { target *-*-* } 39 }
-// { dg-error "not exactly representable" "" { target *-*-* } 203 }
-// { dg-error "integral duration with floating point" "" { target *-*-* } 187 }
+// { dg-error "not exactly representable" "" { target *-*-* } 210 }
+// { dg-error "integral duration with floating point" "" { target *-*-* } 194 }
// { dg-excess-errors "In instantiation of" }
Index: libstdc++-v3/config/abi/pre/gnu.ver
===================================================================
--- libstdc++-v3/config/abi/pre/gnu.ver (revision 138139)
+++ libstdc++-v3/config/abi/pre/gnu.ver (working copy)
@@ -893,7 +893,6 @@ GLIBCXX_3.4.11 {
# chrono
_ZNSt6chrono12system_clock12is_monotonicE;
- _ZNSt6chrono12system_clock3nowEv;
# string/wstring initializer_list overloads
_ZNSs6appendESt16initializer_listIcE;
Index: libstdc++-v3/acinclude.m4
===================================================================
--- libstdc++-v3/acinclude.m4 (revision 138139)
+++ libstdc++-v3/acinclude.m4 (working copy)
@@ -1018,7 +1018,16 @@ AC_DEFUN([GLIBCXX_CHECK_CLOCK_GETTIME],
AC_LANG_CPLUSPLUS
ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -fno-exceptions"
-
+ ac_save_LIBS="$LIBS"
+
+ AC_SEARCH_LIBS(clock_gettime, [rt posix4])
+
+ # Link to -lposix4. -lrt on Linux triggers multi-threaded mode,
+ # so it is linked with --as-needed via the LIB_SPEC.
+ case "$ac_cv_search_clock_gettime" in
+ -lposix4*) GLIBCXX_LIBS=$ac_cv_search_clock_gettime ;;
+ esac
+
AC_CHECK_HEADERS(unistd.h, ac_has_unistd_h=yes, ac_has_unistd_h=no)
ac_has_clock_monotonic=no;
@@ -1055,13 +1064,16 @@ AC_DEFUN([GLIBCXX_CHECK_CLOCK_GETTIME],
AC_DEFINE(_GLIBCXX_USE_CLOCK_MONOTONIC, 1,
[ Defined if clock_gettime has monotonic clock support. ])
fi
-
+
if test x"$ac_has_clock_realtime" = x"yes"; then
AC_DEFINE(_GLIBCXX_USE_CLOCK_REALTIME, 1,
[ Defined if clock_gettime has realtime clock support. ])
fi
+ AC_SUBST(GLIBCXX_LIBS)
+
CXXFLAGS="$ac_save_CXXFLAGS"
+ LIBS="$ac_save_LIBS"
AC_LANG_RESTORE
])