Skip to content

Commit db8a580

Browse files
committed
auto merge of #12027 : vadimcn/rust/compiler-rt, r=alexcrichton
This is an attempt to remove some more of Rust's dependencies on libgcc and replace it with LLVM's compiler-rt lib. I've added compiler-rt as a submodule and changed libstd to link with it. As far as I could verify, after this change, the only symbols still imported by std from libgcc are the stack unwinding functions. Other crates, however, still picked up symbols from libgcc, not from libstd, as I had hoped. So linking definitely requires some work. I've only tested this on windows, 32-bit linux and android and fully expect it to fail on other platforms. Patches are welcome.
2 parents a4a908e + b765132 commit db8a580

File tree

10 files changed

+64
-5
lines changed

10 files changed

+64
-5
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
[submodule "src/gyp"]
1010
path = src/gyp
1111
url = https://github.com/rust-lang/gyp.git
12+
[submodule "src/compiler-rt"]
13+
path = src/compiler-rt
14+
url = https://github.com/rust-lang/compiler-rt.git

Makefile.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ endif
355355
# Prerequisites for using the stageN compiler to build target artifacts
356356
TSREQ$(1)_T_$(2)_H_$(3) = \
357357
$$(HSREQ$(1)_H_$(3)) \
358-
$$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
358+
$$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a \
359+
$$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a
359360

360361
# Prerequisites for a working stageN compiler and libraries, for a specific
361362
# target

mk/clean.mk

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ clean-generic-$(2)-$(1):
5454
$(1)/rt \
5555
$(1)/test \
5656
$(1)/stage* \
57+
-type f \( \
5758
-name '*.[odasS]' -o \
5859
-name '*.so' -o \
5960
-name '*.dylib' -o \
@@ -62,6 +63,7 @@ clean-generic-$(2)-$(1):
6263
-name '*.dll' -o \
6364
-name '*.def' -o \
6465
-name '*.bc' \
66+
\) \
6567
| xargs rm -f
6668
$(Q)find $(1)\
6769
-name '*.dSYM' \
@@ -96,6 +98,7 @@ clean$(1)_T_$(2)_H_$(3): \
9698
$$(foreach crate,$$(CRATES),clean$(1)_T_$(2)_H_$(3)-lib-$$(crate)) \
9799
$$(foreach tool,$$(TOOLS),clean$(1)_T_$(2)_H_$(3)-tool-$$(tool))
98100
$$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
101+
$$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a
99102
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/librun_pass_stage* # For unix
100103
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/run_pass_stage* # For windows
101104

mk/crates.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ HOST_CRATES := syntax rustc rustdoc fourcc
5555
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5656
TOOLS := compiletest rustdoc rustc
5757

58-
DEPS_std := native:rustrt
58+
DEPS_std := native:rustrt native:compiler-rt
5959
DEPS_extra := std term sync serialize getopts collections
6060
DEPS_green := std
6161
DEPS_rustuv := std native:uv native:uv_support

mk/install.mk

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ install-target-$(1)-host-$(2): \
9696
$$(call INSTALL_LIB,$$(call CFG_LIB_GLOB_$(1),$$(crate)));\
9797
$$(call INSTALL_LIB,$$(call CFG_RLIB_GLOB,$$(crate)));)
9898
$$(Q)$$(call INSTALL_LIB,libmorestack.a)
99+
$$(Q)$$(call INSTALL_LIB,libcompiler-rt.a)
99100

100101
endef
101102

@@ -110,6 +111,7 @@ install-target-$(1)-host-$(2): $$(CSREQ$$(ISTAGE)_T_$(1)_H_$(2))
110111
$$(Q)$$(foreach crate,$$(TARGET_CRATES),\
111112
$$(call INSTALL_LIB,$$(call CFG_RLIB_GLOB,$$(crate)));)
112113
$$(Q)$$(call INSTALL_LIB,libmorestack.a)
114+
$$(Q)$$(call INSTALL_LIB,libcompiler-rt.a)
113115
endef
114116

115117
$(foreach target,$(CFG_TARGET), \

mk/rt.mk

+31
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,37 @@ $$(LIBUV_DIR_$(1))/Release/libuv.a: $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1)) \
217217

218218
endif
219219

220+
################################################################################
221+
# compiler-rt
222+
################################################################################
223+
224+
ifdef CFG_ENABLE_FAST_MAKE
225+
COMPRT_DEPS := $(S)/.gitmodules
226+
else
227+
COMPRT_DEPS := $(wildcard \
228+
$(S)src/compiler-rt/* \
229+
$(S)src/compiler-rt/*/* \
230+
$(S)src/compiler-rt/*/*/* \
231+
$(S)src/compiler-rt/*/*/*/*)
232+
endif
233+
234+
COMPRT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
235+
COMPRT_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(COMPRT_NAME_$(1))
236+
COMPRT_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/compiler-rt
237+
238+
$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS)
239+
@$$(call E, make: compiler-rt)
240+
$$(Q)$$(MAKE) -C "$(S)src/compiler-rt" \
241+
ProjSrcRoot="$(S)src/compiler-rt" \
242+
ProjObjRoot="$$(abspath $$(COMPRT_BUILD_DIR_$(1)))" \
243+
CC="$$(CC_$(1))" \
244+
AR="$$(AR_$(1))" \
245+
RANLIB="$$(AR_$(1)) s" \
246+
CFLAGS="$$(CFG_GCCISH_CFLAGS_$(1))" \
247+
TargetTriple=$(1) \
248+
triple-runtime
249+
$$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/runtime/libcompiler_rt.a $$(COMPRT_LIB_$(1))
250+
220251
endef
221252

222253
# Instantiate template for all stages/targets

mk/target.mk

+6
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/:
138138
$$(TLIB$(1)_T_$(2)_H_$(3))/:
139139
mkdir -p $$@
140140

141+
$$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a: \
142+
$$(RT_OUTPUT_DIR_$(2))/$$(call CFG_STATIC_LIB_NAME_$(2),compiler-rt) \
143+
| $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
144+
@$$(call E, cp: $$@)
145+
$$(Q)cp $$< $$@
146+
141147
$$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a: \
142148
$$(RT_OUTPUT_DIR_$(2))/$$(call CFG_STATIC_LIB_NAME_$(2),morestack) \
143149
| $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)

mk/tests.mk

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ tidy:
262262
| grep '^$(S)src/gyp' -v \
263263
| grep '^$(S)src/etc' -v \
264264
| grep '^$(S)src/doc' -v \
265+
| grep '^$(S)src/compiler-rt' -v \
265266
| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
266267

267268
endif

src/compiler-rt

Submodule compiler-rt added at d4606f1

src/librustc/back/link.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ fn link_rlib(sess: Session,
10051005
fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
10061006
let mut a = link_rlib(sess, None, obj_filename, out_filename);
10071007
a.add_native_library("morestack").unwrap();
1008+
a.add_native_library("compiler-rt").unwrap();
10081009

10091010
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
10101011
for &(cnum, ref path) in crates.iter() {
@@ -1132,6 +1133,19 @@ fn link_args(sess: Session,
11321133
args.push(~"-shared-libgcc");
11331134
}
11341135

1136+
if sess.targ_cfg.os == abi::OsAndroid {
1137+
// Many of the symbols defined in compiler-rt are also defined in libgcc.
1138+
// Android linker doesn't like that by default.
1139+
args.push(~"-Wl,--allow-multiple-definition");
1140+
}
1141+
1142+
// Stack growth requires statically linking a __morestack function
1143+
args.push(~"-lmorestack");
1144+
// compiler-rt contains implementations of low-level LLVM helpers
1145+
// It should go before platform and user libraries, so it has first dibs
1146+
// at resolving symbols that also appear in libgcc.
1147+
args.push(~"-lcompiler-rt");
1148+
11351149
add_local_native_libraries(&mut args, sess);
11361150
add_upstream_rust_crates(&mut args, sess, dylib, tmpdir);
11371151
add_upstream_native_libraries(&mut args, sess);
@@ -1159,9 +1173,6 @@ fn link_args(sess: Session,
11591173
~"-L/usr/local/lib/gcc44"]);
11601174
}
11611175

1162-
// Stack growth requires statically linking a __morestack function
1163-
args.push(~"-lmorestack");
1164-
11651176
// FIXME (#2397): At some point we want to rpath our guesses as to
11661177
// where extern libraries might live, based on the
11671178
// addl_lib_search_paths

0 commit comments

Comments
 (0)