Skip to content

Commit b765132

Browse files
committedFeb 11, 2014
Build compiler-rt and link it to all crates, similarly to morestack.
1 parent 5d12d84 commit b765132

File tree

9 files changed

+61
-6
lines changed

9 files changed

+61
-6
lines changed
 

‎.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
url = https://github.com/rust-lang/gyp.git
1212
[submodule "src/compiler-rt"]
1313
path = src/compiler-rt
14-
url = https://github.com/vadimcn/compiler-rt.git
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/librustc/back/link.rs

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

10071008
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
10081009
for &(cnum, ref path) in crates.iter() {
@@ -1130,6 +1131,19 @@ fn link_args(sess: Session,
11301131
args.push(~"-shared-libgcc");
11311132
}
11321133

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

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

5 commit comments

Comments
 (5)

bors commented on Feb 12, 2014

@bors
Collaborator

saw approval from alexcrichton
at vadimcn@b765132

bors commented on Feb 12, 2014

@bors
Collaborator

merging vadimcn/rust/compiler-rt = b765132 into auto

bors commented on Feb 12, 2014

@bors
Collaborator

vadimcn/rust/compiler-rt = b765132 merged ok, testing candidate = db8a580

bors commented on Feb 12, 2014

@bors
Collaborator

bors commented on Feb 12, 2014

@bors
Collaborator

fast-forwarding master to auto = db8a580

Please sign in to comment.