Skip to content

Commit 00669b6

Browse files
committed
rust: Do not link with libdl and libpthread unconditionally
ChangeLog: * Makefile.tpl: Add CRAB1_LIBS variable. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Check if -ldl and -lpthread are needed, and if so, add them to CRAB1_LIBS. gcc/rust/ChangeLog: * Make-lang.in: Remove overazealous LIBS = -ldl -lpthread line, link crab1 against CRAB1_LIBS.
1 parent 6460460 commit 00669b6

File tree

5 files changed

+203
-4
lines changed

5 files changed

+203
-4
lines changed

Makefile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ HOST_EXPORTS = \
197197
$(BASE_EXPORTS) \
198198
CC="$(CC)"; export CC; \
199199
ADA_CFLAGS="$(ADA_CFLAGS)"; export ADA_CFLAGS; \
200+
CRAB1_LIBS="$(CRAB1_LIBS)"; export CRAB1_LIBS; \
200201
CFLAGS="$(CFLAGS)"; export CFLAGS; \
201202
CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \
202203
CXX="$(CXX)"; export CXX; \
@@ -450,6 +451,8 @@ GOCFLAGS = $(CFLAGS)
450451
GDCFLAGS = @GDCFLAGS@
451452
GM2FLAGS = $(CFLAGS)
452453

454+
CRAB1_LIBS = @CRAB1_LIBS@
455+
453456
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
454457

455458
GUILE = guile

Makefile.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ HOST_EXPORTS = \
200200
$(BASE_EXPORTS) \
201201
CC="$(CC)"; export CC; \
202202
ADA_CFLAGS="$(ADA_CFLAGS)"; export ADA_CFLAGS; \
203+
CRAB1_LIBS="$(CRAB1_LIBS)"; export CRAB1_LIBS; \
203204
CFLAGS="$(CFLAGS)"; export CFLAGS; \
204205
CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \
205206
CXX="$(CXX)"; export CXX; \
@@ -453,6 +454,8 @@ GOCFLAGS = $(CFLAGS)
453454
GDCFLAGS = @GDCFLAGS@
454455
GM2FLAGS = $(CFLAGS)
455456

457+
CRAB1_LIBS = @CRAB1_LIBS@
458+
456459
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
457460

458461
GUILE = guile

configure

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ extra_host_zlib_configure_flags
690690
extra_host_libiberty_configure_flags
691691
stage1_languages
692692
host_libs_picflag
693+
CRAB1_LIBS
693694
PICFLAG
694695
host_shared
695696
gcc_host_pie
@@ -8826,6 +8827,139 @@ fi
88268827

88278828

88288829

8830+
# Rust requires -ldl and -lpthread if you are using an old glibc that does not include them by
8831+
# default, so we check for them here
8832+
8833+
missing_rust_dynlibs=none
8834+
8835+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5
8836+
$as_echo_n "checking for library containing dlopen... " >&6; }
8837+
if ${ac_cv_search_dlopen+:} false; then :
8838+
$as_echo_n "(cached) " >&6
8839+
else
8840+
ac_func_search_save_LIBS=$LIBS
8841+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
8842+
/* end confdefs.h. */
8843+
8844+
/* Override any GCC internal prototype to avoid an error.
8845+
Use char because int might match the return type of a GCC
8846+
builtin and then its argument prototype would still apply. */
8847+
#ifdef __cplusplus
8848+
extern "C"
8849+
#endif
8850+
char dlopen ();
8851+
int
8852+
main ()
8853+
{
8854+
return dlopen ();
8855+
;
8856+
return 0;
8857+
}
8858+
_ACEOF
8859+
for ac_lib in '' dl; do
8860+
if test -z "$ac_lib"; then
8861+
ac_res="none required"
8862+
else
8863+
ac_res=-l$ac_lib
8864+
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
8865+
fi
8866+
if ac_fn_c_try_link "$LINENO"; then :
8867+
ac_cv_search_dlopen=$ac_res
8868+
fi
8869+
rm -f core conftest.err conftest.$ac_objext \
8870+
conftest$ac_exeext
8871+
if ${ac_cv_search_dlopen+:} false; then :
8872+
break
8873+
fi
8874+
done
8875+
if ${ac_cv_search_dlopen+:} false; then :
8876+
8877+
else
8878+
ac_cv_search_dlopen=no
8879+
fi
8880+
rm conftest.$ac_ext
8881+
LIBS=$ac_func_search_save_LIBS
8882+
fi
8883+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_dlopen" >&5
8884+
$as_echo "$ac_cv_search_dlopen" >&6; }
8885+
ac_res=$ac_cv_search_dlopen
8886+
if test "$ac_res" != no; then :
8887+
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
8888+
8889+
fi
8890+
8891+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing pthread_create" >&5
8892+
$as_echo_n "checking for library containing pthread_create... " >&6; }
8893+
if ${ac_cv_search_pthread_create+:} false; then :
8894+
$as_echo_n "(cached) " >&6
8895+
else
8896+
ac_func_search_save_LIBS=$LIBS
8897+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
8898+
/* end confdefs.h. */
8899+
8900+
/* Override any GCC internal prototype to avoid an error.
8901+
Use char because int might match the return type of a GCC
8902+
builtin and then its argument prototype would still apply. */
8903+
#ifdef __cplusplus
8904+
extern "C"
8905+
#endif
8906+
char pthread_create ();
8907+
int
8908+
main ()
8909+
{
8910+
return pthread_create ();
8911+
;
8912+
return 0;
8913+
}
8914+
_ACEOF
8915+
for ac_lib in '' pthread; do
8916+
if test -z "$ac_lib"; then
8917+
ac_res="none required"
8918+
else
8919+
ac_res=-l$ac_lib
8920+
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
8921+
fi
8922+
if ac_fn_c_try_link "$LINENO"; then :
8923+
ac_cv_search_pthread_create=$ac_res
8924+
fi
8925+
rm -f core conftest.err conftest.$ac_objext \
8926+
conftest$ac_exeext
8927+
if ${ac_cv_search_pthread_create+:} false; then :
8928+
break
8929+
fi
8930+
done
8931+
if ${ac_cv_search_pthread_create+:} false; then :
8932+
8933+
else
8934+
ac_cv_search_pthread_create=no
8935+
fi
8936+
rm conftest.$ac_ext
8937+
LIBS=$ac_func_search_save_LIBS
8938+
fi
8939+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_pthread_create" >&5
8940+
$as_echo "$ac_cv_search_pthread_create" >&6; }
8941+
ac_res=$ac_cv_search_pthread_create
8942+
if test "$ac_res" != no; then :
8943+
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
8944+
8945+
fi
8946+
8947+
8948+
if test $ac_cv_search_dlopen = -ldl; then
8949+
CRAB1_LIBS="$CRAB1_LIBS -ldl"
8950+
elif test $ac_cv_search_dlopen = no; then
8951+
missing_rust_dynlibs="libdl"
8952+
fi
8953+
8954+
if test $ac_cv_search_pthread_create = -lpthread; then
8955+
CRAB1_LIBS="$CRAB1_LIBS -lpthread"
8956+
elif test $ac_cv_search_pthread_crate = no; then
8957+
missing_rust_dynlibs="$missing_rust_dynlibs, libpthread"
8958+
fi
8959+
8960+
CRAB1_LIBS="$CRAB1_LIBS"
8961+
8962+
88298963
# If we are building PIC/PIE host executables, and we are building dependent
88308964
# libs (e.g. GMP) in-tree those libs need to be configured to generate PIC
88318965
# code.
@@ -9066,6 +9200,26 @@ $as_echo "$as_me: WARNING: GDC is required to build $language" >&2;}
90669200
;;
90679201
esac
90689202

9203+
# Disable Rust if we are missing some required C libraries for the Rust runtime.
9204+
case ${add_this_lang}:${language}:${missing_rust_dynlibs} in
9205+
*:rust:none)
9206+
# Nothing to do - we're not missing any C libraries
9207+
;;
9208+
yes:rust:*)
9209+
as_fn_error $? "some C libraries are required to build $language: $missing_rust_dynlibs" "$LINENO" 5
9210+
add_this_lang=unsupported
9211+
;;
9212+
all:rust:*)
9213+
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: some C libraries are required to build $language: $missing_rust_dynlibs" >&5
9214+
$as_echo "$as_me: WARNING: some C libraries are required to build $language: $missing_rust_dynlibs" >&2;}
9215+
add_this_lang=unsupported
9216+
;;
9217+
*:rust:*)
9218+
# Silently disable.
9219+
add_this_lang=unsupported
9220+
;;
9221+
esac
9222+
90699223
# Disable jit if -enable-host-shared not specified
90709224
# but not if building for Mingw. All code in Windows
90719225
# is position independent code (PIC).

configure.ac

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,28 @@ fi
20362036

20372037
AC_SUBST(PICFLAG)
20382038

2039+
# Rust requires -ldl and -lpthread if you are using an old glibc that does not include them by
2040+
# default, so we check for them here
2041+
2042+
missing_rust_dynlibs=none
2043+
2044+
AC_SEARCH_LIBS([dlopen], [dl])
2045+
AC_SEARCH_LIBS([pthread_create], [pthread])
2046+
2047+
if test $ac_cv_search_dlopen = -ldl; then
2048+
CRAB1_LIBS="$CRAB1_LIBS -ldl"
2049+
elif test $ac_cv_search_dlopen = no; then
2050+
missing_rust_dynlibs="libdl"
2051+
fi
2052+
2053+
if test $ac_cv_search_pthread_create = -lpthread; then
2054+
CRAB1_LIBS="$CRAB1_LIBS -lpthread"
2055+
elif test $ac_cv_search_pthread_crate = no; then
2056+
missing_rust_dynlibs="$missing_rust_dynlibs, libpthread"
2057+
fi
2058+
2059+
AC_SUBST(CRAB1_LIBS, "$CRAB1_LIBS")
2060+
20392061
# If we are building PIC/PIE host executables, and we are building dependent
20402062
# libs (e.g. GMP) in-tree those libs need to be configured to generate PIC
20412063
# code.
@@ -2273,6 +2295,25 @@ if test -d ${srcdir}/gcc; then
22732295
;;
22742296
esac
22752297

2298+
# Disable Rust if we are missing some required C libraries for the Rust runtime.
2299+
case ${add_this_lang}:${language}:${missing_rust_dynlibs} in
2300+
*:rust:none)
2301+
# Nothing to do - we're not missing any C libraries
2302+
;;
2303+
yes:rust:*)
2304+
AC_MSG_ERROR([some C libraries are required to build $language: $missing_rust_dynlibs])
2305+
add_this_lang=unsupported
2306+
;;
2307+
all:rust:*)
2308+
AC_MSG_WARN([some C libraries are required to build $language: $missing_rust_dynlibs])
2309+
add_this_lang=unsupported
2310+
;;
2311+
*:rust:*)
2312+
# Silently disable.
2313+
add_this_lang=unsupported
2314+
;;
2315+
esac
2316+
22762317
# Disable jit if -enable-host-shared not specified
22772318
# but not if building for Mingw. All code in Windows
22782319
# is position independent code (PIC).

gcc/rust/Make-lang.in

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ GCCRS_D_OBJS = \
5454
rust/rustspec.o \
5555
$(END)
5656

57-
LIBS += -ldl -lpthread
58-
5957
gccrs$(exeext): $(GCCRS_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS)
6058
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
6159
$(GCCRS_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \
@@ -234,7 +232,7 @@ crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS) $(LIBPROC_MACRO
234232
@$(call LINK_PROGRESS,$(INDEX.rust),start)
235233
+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
236234
$(RUST_ALL_OBJS) attribs.o $(BACKEND) \
237-
$(LIBS) $(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(LIBFFI_POLONIUS) \
235+
$(LIBS) $(CRAB1_LIBS) $(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(LIBFFI_POLONIUS) \
238236
$(BACKENDLIBS)
239237
@$(call LINK_PROGRESS,$(INDEX.rust),end)
240238

@@ -496,4 +494,4 @@ rust/libffi_polonius.a: \
496494
rust/checks/errors/borrowck/ffi-polonius/Cargo.toml \
497495
$(wildcard $(srcdir)/rust/checks/errors/borrowck/ffi-polonius/src/*)
498496
cargo build --manifest-path $(srcdir)/rust/checks/errors/borrowck/ffi-polonius/Cargo.toml --release --target-dir rust/ffi-polonius
499-
cp rust/ffi-polonius/release/libffi_polonius.a rust/libffi_polonius.a
497+
cp rust/ffi-polonius/release/libffi_polonius.a rust/libffi_polonius.a

0 commit comments

Comments
 (0)