aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-02-09 13:11:55 -0800
committerIan Lance Taylor <iant@golang.org>2022-02-09 13:13:17 -0800
commitf6ff6738fa25fb012ed208e01de5a84d8668d538 (patch)
tree8b39147f24010e5fa562b9c9d0471b4bcb3390b2
parent4cf3c339815cdfa636b25a512f91b63d7c313fd6 (diff)
downloadgcc-f6ff6738fa25fb012ed208e01de5a84d8668d538.zip
gcc-f6ff6738fa25fb012ed208e01de5a84d8668d538.tar.gz
gcc-f6ff6738fa25fb012ed208e01de5a84d8668d538.tar.bz2
gccgo: link static libgo against -lrt on GNU/Linux
The upcoming Go 1.18 release requires linking against -lrt on GNU/Linux (only) in order to call timer_create and friends. Also change gotools to link the runtime test against -lrt. * gospec.cc (RTLIB, RT_LIBRARY): Define. (lang_specific_driver): Add -lrt if linking statically on GNU/Linux. * configure.ac (RT_LIBS): Define. * Makefile.am (check-runtime): Set GOLIBS to $(RT_LIBS). * configure, Makefile.in: Regenerate.
-rw-r--r--gcc/go/gospec.cc42
-rw-r--r--gotools/Makefile.am4
-rw-r--r--gotools/Makefile.in5
-rwxr-xr-xgotools/configure7
-rw-r--r--gotools/configure.ac9
5 files changed, 60 insertions, 7 deletions
diff --git a/gcc/go/gospec.cc b/gcc/go/gospec.cc
index df92b62..ba7ba4e 100644
--- a/gcc/go/gospec.cc
+++ b/gcc/go/gospec.cc
@@ -29,10 +29,12 @@ along with GCC; see the file COPYING3. If not see
#define MATHLIB (1<<2)
/* This bit is set if they did `-lpthread'. */
#define THREADLIB (1<<3)
+/* This bit is set if they did `-lrt'. */
+#define RTLIB (1<<4)
/* This bit is set if they did `-lc'. */
-#define WITHLIBC (1<<4)
+#define WITHLIBC (1<<5)
/* Skip this option. */
-#define SKIPOPT (1<<5)
+#define SKIPOPT (1<<6)
#ifndef MATH_LIBRARY
#define MATH_LIBRARY "m"
@@ -44,6 +46,8 @@ along with GCC; see the file COPYING3. If not see
#define THREAD_LIBRARY "pthread"
#define THREAD_LIBRARY_PROFILE THREAD_LIBRARY
+#define RT_LIBRARY "rt"
+
#define LIBGO "go"
#define LIBGO_PROFILE LIBGO
#define LIBGOBEGIN "gobegin"
@@ -74,6 +78,9 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
/* "-lpthread" if it appears on the command line. */
const struct cl_decoded_option *saw_thread = 0;
+ /* "-lrt" if it appears on the command line. */
+ const struct cl_decoded_option *saw_rt = 0;
+
/* "-lc" if it appears on the command line. */
const struct cl_decoded_option *saw_libc = 0;
@@ -84,6 +91,9 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
/* Whether we need the thread library. */
int need_thread = 0;
+ /* Whether we need the rt library. */
+ int need_rt = 0;
+
/* By default, we throw on the math library if we have one. */
int need_math = (MATH_LIBRARY[0] != '\0');
@@ -156,6 +166,8 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
}
else if (strcmp (arg, THREAD_LIBRARY) == 0)
args[i] |= THREADLIB;
+ else if (strcmp (arg, RT_LIBRARY) == 0)
+ args[i] |= RTLIB;
else if (strcmp (arg, "c") == 0)
args[i] |= WITHLIBC;
else
@@ -260,7 +272,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
#endif
/* Make sure to have room for the trailing NULL argument. */
- num_args = argc + need_math + shared_libgcc + (library > 0) * 5 + 10;
+ num_args = argc + need_math + shared_libgcc + (library > 0) * 6 + 10;
new_decoded_options = XNEWVEC (struct cl_decoded_option, num_args);
i = 0;
@@ -314,6 +326,12 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
saw_thread = &decoded_options[i];
}
+ if (!saw_rt && (args[i] & RTLIB) && library > 0)
+ {
+ --j;
+ saw_rt = &decoded_options[i];
+ }
+
if (!saw_libc && (args[i] & WITHLIBC) && library > 0)
{
--j;
@@ -395,9 +413,23 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
#endif
/* When linking libgo statically we also need to link with the
- pthread library. */
+ pthread and (on GNU/Linux) the rt library. */
if (library > 1 || static_link)
- need_thread = 1;
+ {
+ need_thread = 1;
+ if (strstr (DEFAULT_TARGET_MACHINE, "linux") != NULL)
+ need_rt = 1;
+ }
+ }
+
+ if (saw_rt)
+ new_decoded_options[j++] = *saw_rt;
+ else if (library > 0 && need_rt)
+ {
+ generate_option (OPT_l, RT_LIBRARY, 1, CL_DRIVER,
+ &new_decoded_options[j]);
+ added_libraries++;
+ j++;
}
if (saw_thread)
diff --git a/gotools/Makefile.am b/gotools/Makefile.am
index 199899b..9e81024 100644
--- a/gotools/Makefile.am
+++ b/gotools/Makefile.am
@@ -246,12 +246,14 @@ check-runtime: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc
GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_linknames.go $(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go $(libgodir)/goroot.go" --tag=libffi`; \
- echo "$(ECHO_ENV) GC='$(abs_builddir)/check-gccgo -fgo-compiling-runtime' GOARCH=$${GOARCH} GOOS=$${GOOS} $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles='$${files}' $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > runtime-testlog
+ echo "$(ECHO_ENV) GC='$(abs_builddir)/check-gccgo -fgo-compiling-runtime' GOARCH=$${GOARCH} GOOS=$${GOOS} GOLIBS='$(RT_LIBS)' $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles='$${files}' $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > runtime-testlog
$(CHECK_ENV) \
GC="$${GCCGO} -fgo-compiling-runtime"; \
export GC; \
GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
+ GOLIBS="$(RT_LIBS)"; \
+ export GOLIBS; \
files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_linknames.go $(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go $(libgodir)/goroot.go" --tag=libffi`; \
$(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles="$${files}" $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v >> runtime-testlog 2>&1 || echo "--- $${fl}: go test runtime (0.00s)" >> runtime-testlog
grep '^--- ' runtime-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | sort -k 2
diff --git a/gotools/Makefile.in b/gotools/Makefile.in
index e2c30bf..8a19f6f 100644
--- a/gotools/Makefile.in
+++ b/gotools/Makefile.in
@@ -269,6 +269,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
+RT_LIBS = @RT_LIBS@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
@@ -917,12 +918,14 @@ mostlyclean-local:
@NATIVE_TRUE@ GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
@NATIVE_TRUE@ GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
@NATIVE_TRUE@ files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_linknames.go $(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go $(libgodir)/goroot.go" --tag=libffi`; \
-@NATIVE_TRUE@ echo "$(ECHO_ENV) GC='$(abs_builddir)/check-gccgo -fgo-compiling-runtime' GOARCH=$${GOARCH} GOOS=$${GOOS} $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles='$${files}' $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > runtime-testlog
+@NATIVE_TRUE@ echo "$(ECHO_ENV) GC='$(abs_builddir)/check-gccgo -fgo-compiling-runtime' GOARCH=$${GOARCH} GOOS=$${GOOS} GOLIBS='$(RT_LIBS)' $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles='$${files}' $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > runtime-testlog
@NATIVE_TRUE@ $(CHECK_ENV) \
@NATIVE_TRUE@ GC="$${GCCGO} -fgo-compiling-runtime"; \
@NATIVE_TRUE@ export GC; \
@NATIVE_TRUE@ GOARCH=`$(abs_builddir)/go$(EXEEXT) env GOARCH`; \
@NATIVE_TRUE@ GOOS=`$(abs_builddir)/go$(EXEEXT) env GOOS`; \
+@NATIVE_TRUE@ GOLIBS="$(RT_LIBS)"; \
+@NATIVE_TRUE@ export GOLIBS; \
@NATIVE_TRUE@ files=`$(SHELL) $(libgosrcdir)/../match.sh --goarch=$${GOARCH} --goos=$${GOOS} --srcdir=$(libgosrcdir)/runtime --extrafiles="$(libgodir)/runtime_linknames.go $(libgodir)/runtime_sysinfo.go $(libgodir)/sigtab.go $(libgodir)/goroot.go" --tag=libffi`; \
@NATIVE_TRUE@ $(SHELL) $(libgosrcdir)/../testsuite/gotest --goarch=$${GOARCH} --goos=$${GOOS} --basedir=$(libgosrcdir)/.. --srcdir=$(libgosrcdir)/runtime --pkgpath=runtime --pkgfiles="$${files}" $(GOTESTFLAGS) -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v >> runtime-testlog 2>&1 || echo "--- $${fl}: go test runtime (0.00s)" >> runtime-testlog
@NATIVE_TRUE@ grep '^--- ' runtime-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | sort -k 2
diff --git a/gotools/configure b/gotools/configure
index ff71d2a..5b66722 100755
--- a/gotools/configure
+++ b/gotools/configure
@@ -586,6 +586,7 @@ ac_subst_vars='am__EXEEXT_FALSE
am__EXEEXT_TRUE
LTLIBOBJS
LIBOBJS
+RT_LIBS
NET_LIBS
NATIVE_FALSE
NATIVE_TRUE
@@ -4211,6 +4212,12 @@ if test "$ac_res" != no; then :
fi
+RT_LIBS=
+case ${target} in
+ *-*-linux*) RT_LIBS=-lrt ;;
+esac
+
+
ac_config_files="$ac_config_files Makefile"
diff --git a/gotools/configure.ac b/gotools/configure.ac
index f0a73ec..bf2395f 100644
--- a/gotools/configure.ac
+++ b/gotools/configure.ac
@@ -85,6 +85,15 @@ dnl Test if -lrt is required for sched_yield and/or nanosleep.
AC_SEARCH_LIBS([sched_yield], [rt])
AC_SEARCH_LIBS([nanosleep], [rt])
+dnl On GNU/Linux we need to link the runtime package against -lrt.
+dnl This is a target test, unlike sched_yield/nanosleep above
+dnl which is a host test.
+RT_LIBS=
+case ${target} in
+ *-*-linux*) RT_LIBS=-lrt ;;
+esac
+AC_SUBST(RT_LIBS)
+
AC_CONFIG_FILES(Makefile)
AC_OUTPUT