Skip to content

Commit b5c1b48

Browse files
committed
auto merge of #10199 : alexcrichton/rust/no-propagate, r=brson
This commit removes the propagation of `link_args` attributes across crates. The first commit message has the reasons as to why. Additionally, this starts statically linking some C/C++ helper libraries that we have to their respective crates instead of throwing then in librustrt and then having everything depend on librustrt. The major downside of this movement is that we're losing the ability to control visible symbols. I couldn't figure out a way to internalize symbols from a static library during the linking process, so everyone who links to librustdoc will be able to use its sundown implementation (not exactly ideal). I'm not entirely sure how to fix this (beyond generating a list of all public symbols, including rust ones, and passing that to the linker), but we may have a much easier time with this once we start using llvm's linker toolchain. There's certainly a lot more possibilities in where this can go, but I didn't want to go too deep just yet. The main idea here is to stop propagating linker arguments and then see how we're able to start statically linking libraries as a result. r? @catamorphism, you're going to be working on linking soon, so feel free to completely throw this away for something else!
2 parents a248e34 + 0ce1b2f commit b5c1b48

File tree

13 files changed

+85
-191
lines changed

13 files changed

+85
-191
lines changed

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,10 @@ config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
625625
# new definitions), make sure definitions always precede their uses,
626626
# especially for the dependency lists of recipes.
627627

628+
include $(CFG_SRC_DIR)mk/rt.mk
628629
include $(CFG_SRC_DIR)mk/target.mk
629630
include $(CFG_SRC_DIR)mk/host.mk
630631
include $(CFG_SRC_DIR)mk/stage0.mk
631-
include $(CFG_SRC_DIR)mk/rt.mk
632632
include $(CFG_SRC_DIR)mk/rustllvm.mk
633633
include $(CFG_SRC_DIR)mk/tools.mk
634634
include $(CFG_SRC_DIR)mk/docs.mk

mk/rt.mk

+51-15
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,11 @@ RUNTIME_CXXS_$(1)_$(2) := \
8787
rt/sync/rust_thread.cpp \
8888
rt/rust_builtin.cpp \
8989
rt/rust_upcall.cpp \
90-
rt/rust_uv.cpp \
9190
rt/miniz.cpp \
9291
rt/rust_android_dummy.cpp \
9392
rt/rust_test_helpers.cpp
9493

95-
RUNTIME_CS_$(1)_$(2) := rt/sundown/src/autolink.c \
96-
rt/sundown/src/buffer.c \
97-
rt/sundown/src/stack.c \
98-
rt/sundown/src/markdown.c \
99-
rt/sundown/html/houdini_href_e.c \
100-
rt/sundown/html/houdini_html_e.c \
101-
rt/sundown/html/html_smartypants.c \
102-
rt/sundown/html/html.c
94+
RUNTIME_CS_$(1)_$(2) :=
10395

10496
RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
10597
rt/arch/$$(HOST_$(1))/record_sp.S
@@ -108,10 +100,7 @@ RT_BUILD_DIR_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/stage$(2)
108100

109101
RUNTIME_DEF_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/rustrt$$(CFG_DEF_SUFFIX_$(1))
110102
RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
111-
-I $$(S)src/rt/arch/$$(HOST_$(1)) \
112-
-I $$(S)src/rt/sundown/src \
113-
-I $$(S)src/rt/sundown/html \
114-
-I $$(S)src/libuv/include
103+
-I $$(S)src/rt/arch/$$(HOST_$(1))
115104
RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
116105
$$(RUNTIME_CS_$(1)_$(2):rt/%.c=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
117106
$$(RUNTIME_S_$(1)_$(2):rt/%.S=$$(RT_BUILD_DIR_$(1)_$(2))/%.o)
@@ -140,10 +129,9 @@ $$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJS_
140129
$$(Q)$(AR_$(1)) rcs $$@ $$^
141130

142131
$$(RT_BUILD_DIR_$(1)_$(2))/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
143-
$$(RUNTIME_DEF_$(1)_$(2)) $$(LIBUV_LIB_$(1))
132+
$$(RUNTIME_DEF_$(1)_$(2))
144133
@$$(call E, link: $$@)
145134
$$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)_$(2)) \
146-
$$(LIBUV_LIB_$(1)) \
147135
$$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)_$(2)),$$(CFG_RUNTIME_$(1)))
148136

149137
# These could go in rt.mk or rustllvm.mk, they're needed for both.
@@ -242,6 +230,54 @@ $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1))
242230
NO_LOAD="$$(LIBUV_NO_LOAD)" \
243231
V=$$(VERBOSE)
244232
endif
233+
234+
# libuv support functionality (extra C/C++ that we need to use libuv)
235+
236+
UV_SUPPORT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),uv_support)
237+
UV_SUPPORT_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/uv_support
238+
UV_SUPPORT_LIB_$(1) := $$(UV_SUPPORT_DIR_$(1))/$$(UV_SUPPORT_NAME_$(1))
239+
UV_SUPPORT_CS_$(1) := rt/rust_uv.cpp
240+
UV_SUPPORT_OBJS_$(1) := $$(UV_SUPPORT_CS_$(1):rt/%.cpp=$$(UV_SUPPORT_DIR_$(1))/%.o)
241+
242+
$$(UV_SUPPORT_DIR_$(1))/%.o: rt/%.cpp
243+
@$$(call E, compile: $$@)
244+
@mkdir -p $$(@D)
245+
$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, \
246+
-I $$(S)src/libuv/include \
247+
$$(RUNTIME_CFLAGS_$(1))) $$<
248+
249+
$$(UV_SUPPORT_LIB_$(1)): $$(UV_SUPPORT_OBJS_$(1))
250+
@$$(call E, link: $$@)
251+
$$(Q)$$(AR_$(1)) rcs $$@ $$^
252+
253+
# sundown markdown library (used by librustdoc)
254+
255+
SUNDOWN_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),sundown)
256+
SUNDOWN_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/sundown
257+
SUNDOWN_LIB_$(1) := $$(SUNDOWN_DIR_$(1))/$$(SUNDOWN_NAME_$(1))
258+
259+
SUNDOWN_CS_$(1) := rt/sundown/src/autolink.c \
260+
rt/sundown/src/buffer.c \
261+
rt/sundown/src/stack.c \
262+
rt/sundown/src/markdown.c \
263+
rt/sundown/html/houdini_href_e.c \
264+
rt/sundown/html/houdini_html_e.c \
265+
rt/sundown/html/html_smartypants.c \
266+
rt/sundown/html/html.c
267+
268+
SUNDOWN_OBJS_$(1) := $$(SUNDOWN_CS_$(1):rt/%.c=$$(SUNDOWN_DIR_$(1))/%.o)
269+
270+
$$(SUNDOWN_DIR_$(1))/%.o: rt/%.c
271+
@$$(call E, compile: $$@)
272+
@mkdir -p $$(@D)
273+
$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, \
274+
-I $$(S)src/rt/sundown/src -I $$(S)src/rt/sundown/html \
275+
$$(RUNTIME_CFLAGS_$(1))) $$<
276+
277+
$$(SUNDOWN_LIB_$(1)): $$(SUNDOWN_OBJS_$(1))
278+
@$$(call E, link: $$@)
279+
$$(Q)$$(AR_$(1)) rcs $$@ $$^
280+
245281
endef
246282

247283
# Instantiate template for all stages/targets

mk/target.mk

+10-2
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,15 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTUV_$(2)): \
7777
$$(LIBRUSTUV_CRATE) $$(LIBRUSTUV_INPUTS) \
7878
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
7979
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
80+
$$(LIBUV_LIB_$(2)) \
81+
$$(UV_SUPPORT_LIB_$(2)) \
8082
| $$(TLIB$(1)_T_$(2)_H_$(3))/
8183
@$$(call E, compile_and_link: $$@)
8284
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTUV_GLOB_$(2)),$$(notdir $$@))
83-
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@
85+
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) \
86+
-L $$(UV_SUPPORT_DIR_$(2)) \
87+
-L $$(dir $$(LIBUV_LIB_$(2))) \
88+
--out-dir $$(@D) $$< && touch $$@
8489
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTUV_GLOB_$(2)),$$(notdir $$@))
8590

8691
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \
@@ -117,13 +122,16 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): \
117122
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@
118123
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTC_GLOB_$(2)),$$(notdir $$@))
119124

125+
# NOTE: after the next snapshot remove these '-L' flags
120126
$$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X_$(3)): \
121127
$$(DRIVER_CRATE) \
122128
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
123129
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)) \
124130
| $$(TBIN$(1)_T_$(2)_H_$(3))/
125131
@$$(call E, compile_and_link: $$@)
126-
$$(STAGE$(1)_T_$(2)_H_$(3)) --cfg rustc -o $$@ $$<
132+
$$(STAGE$(1)_T_$(2)_H_$(3)) --cfg rustc -o $$@ $$< \
133+
-L $$(UV_SUPPORT_DIR_$(2)) \
134+
-L $$(dir $$(LIBUV_LIB_$(2)))
127135
ifdef CFG_ENABLE_PAX_FLAGS
128136
@$$(call E, apply PaX flags: $$@)
129137
@"$(CFG_PAXCTL)" -cm "$$@"

mk/tests.mk

+5-2
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ $(3)/stage$(1)/test/rustuvtest-$(2)$$(X_$(2)): \
358358
$$(LIBRUSTUV_CRATE) $$(LIBRUSTUV_INPUTS) \
359359
$$(STDTESTDEP_$(1)_$(2)_$(3))
360360
@$$(call E, compile_and_link: $$@)
361-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
361+
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test \
362+
-L $$(UV_SUPPORT_DIR_$(2)) \
363+
-L $$(dir $$(LIBUV_LIB_$(2)))
362364

363365
$(3)/stage$(1)/test/syntaxtest-$(2)$$(X_$(2)): \
364366
$$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS) \
@@ -392,7 +394,8 @@ $(3)/stage$(1)/test/rustdoctest-$(2)$$(X_$(2)): \
392394
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX_$(2)) \
393395
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
394396
@$$(call E, compile_and_link: $$@)
395-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
397+
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test \
398+
-L $$(SUNDOWN_DIR_$(2))
396399

397400
endef
398401

mk/tools.mk

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTDOC_$(4)): \
5757
$$(RUSTDOC_LIB) $$(RUSTDOC_INPUTS) \
5858
$$(SREQ$(1)_T_$(4)_H_$(3)) \
5959
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTC_$(4)) \
60+
$$(SUNDOWN_LIB_$(4)) \
6061
| $$(TLIB$(1)_T_$(4)_H_$(3))/
6162
@$$(call E, compile_and_link: $$@)
6263
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTDOC_GLOB_$(4)),$$(notdir $$@))
63-
$$(STAGE$(1)_T_$(4)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@
64+
$$(STAGE$(1)_T_$(4)_H_$(3)) $$(WFLAGS_ST$(1)) \
65+
-L $$(SUNDOWN_DIR_$(4)) --out-dir $$(@D) $$< && touch $$@
6466
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTDOC_GLOB_$(4)),$$(notdir $$@))
6567

6668
$$(TBIN$(1)_T_$(4)_H_$(3))/rustdoc$$(X_$(4)): \

src/librustc/back/link.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use lib::llvm::llvm;
1616
use lib::llvm::ModuleRef;
1717
use lib;
1818
use metadata::common::LinkMeta;
19-
use metadata::{encoder, csearch, cstore, filesearch};
19+
use metadata::{encoder, cstore, filesearch};
2020
use middle::trans::context::CrateContext;
2121
use middle::trans::common::gensym_name;
2222
use middle::ty;
@@ -1043,14 +1043,6 @@ pub fn link_args(sess: Session,
10431043
let ula = cstore::get_used_link_args(cstore);
10441044
for arg in ula.iter() { args.push(arg.to_owned()); }
10451045

1046-
// Add all the link args for external crates.
1047-
do cstore::iter_crate_data(cstore) |crate_num, _| {
1048-
let link_args = csearch::get_link_args_for_crate(cstore, crate_num);
1049-
for link_arg in link_args.move_iter() {
1050-
args.push(link_arg);
1051-
}
1052-
}
1053-
10541046
// # Extern library linking
10551047

10561048
// User-supplied library search paths (-L on the cammand line) These are

src/librustc/lib/llvm.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ pub mod llvm {
304304
use super::debuginfo::*;
305305
use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong};
306306

307-
#[link_args = "-Lrustllvm -lrustllvm"]
308-
#[link_name = "rustllvm"]
307+
#[link_args = "-lrustllvm"]
309308
extern {
310309
/* Create and destroy contexts. */
311310
pub fn LLVMContextCreate() -> ContextRef;

src/librustc/metadata/csearch.rs

-7
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,6 @@ pub fn get_item_visibility(cstore: @mut cstore::CStore,
261261
decoder::get_item_visibility(cdata, def_id.node)
262262
}
263263

264-
pub fn get_link_args_for_crate(cstore: @mut cstore::CStore,
265-
crate_num: ast::CrateNum)
266-
-> ~[~str] {
267-
let cdata = cstore::get_crate_data(cstore, crate_num);
268-
decoder::get_link_args_for_crate(cdata)
269-
}
270-
271264
pub fn each_impl(cstore: @mut cstore::CStore,
272265
crate_num: ast::CrateNum,
273266
callback: &fn(ast::DefId)) {

src/librustc/metadata/decoder.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1456,16 +1456,6 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId {
14561456
}
14571457
}
14581458

1459-
pub fn get_link_args_for_crate(cdata: Cmd) -> ~[~str] {
1460-
let link_args = reader::get_doc(reader::Doc(cdata.data), tag_link_args);
1461-
let mut result = ~[];
1462-
do reader::tagged_docs(link_args, tag_link_args_arg) |arg_doc| {
1463-
result.push(arg_doc.as_str());
1464-
true
1465-
};
1466-
result
1467-
}
1468-
14691459
pub fn each_impl(cdata: Cmd, callback: &fn(ast::DefId)) {
14701460
let impls_doc = reader::get_doc(reader::Doc(cdata.data), tag_impls);
14711461
let _ = do reader::tagged_docs(impls_doc, tag_impls_impl) |impl_doc| {

src/librustc/metadata/encoder.rs

-21
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct Stats {
7575
attr_bytes: u64,
7676
dep_bytes: u64,
7777
lang_item_bytes: u64,
78-
link_args_bytes: u64,
7978
impl_bytes: u64,
8079
misc_bytes: u64,
8180
item_bytes: u64,
@@ -1610,19 +1609,6 @@ fn encode_lang_items(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
16101609
ebml_w.end_tag(); // tag_lang_items
16111610
}
16121611

1613-
fn encode_link_args(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
1614-
ebml_w.start_tag(tag_link_args);
1615-
1616-
let link_args = cstore::get_used_link_args(ecx.cstore);
1617-
for link_arg in link_args.iter() {
1618-
ebml_w.start_tag(tag_link_args_arg);
1619-
ebml_w.writer.write(link_arg.as_bytes());
1620-
ebml_w.end_tag();
1621-
}
1622-
1623-
ebml_w.end_tag();
1624-
}
1625-
16261612
struct ImplVisitor<'self> {
16271613
ecx: &'self EncodeContext<'self>,
16281614
ebml_w: &'self mut writer::Encoder,
@@ -1740,7 +1726,6 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
17401726
attr_bytes: 0,
17411727
dep_bytes: 0,
17421728
lang_item_bytes: 0,
1743-
link_args_bytes: 0,
17441729
impl_bytes: 0,
17451730
misc_bytes: 0,
17461731
item_bytes: 0,
@@ -1797,11 +1782,6 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
17971782
encode_lang_items(&ecx, &mut ebml_w);
17981783
ecx.stats.lang_item_bytes = wr.tell() - i;
17991784

1800-
// Encode the link args.
1801-
i = wr.tell();
1802-
encode_link_args(&ecx, &mut ebml_w);
1803-
ecx.stats.link_args_bytes = wr.tell() - i;
1804-
18051785
// Encode the def IDs of impls, for coherence checking.
18061786
i = wr.tell();
18071787
encode_impls(&ecx, crate, &mut ebml_w);
@@ -1838,7 +1818,6 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
18381818
println!(" attribute bytes: {}", ecx.stats.attr_bytes);
18391819
println!(" dep bytes: {}", ecx.stats.dep_bytes);
18401820
println!(" lang item bytes: {}", ecx.stats.lang_item_bytes);
1841-
println!(" link args bytes: {}", ecx.stats.link_args_bytes);
18421821
println!(" impl bytes: {}", ecx.stats.impl_bytes);
18431822
println!(" misc bytes: {}", ecx.stats.misc_bytes);
18441823
println!(" item bytes: {}", ecx.stats.item_bytes);

src/librustdoc/html/markdown.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct buf {
6969
}
7070

7171
// sundown FFI
72+
#[link_args = "-lsundown"]
7273
extern {
7374
fn sdhtml_renderer(callbacks: *sd_callbacks,
7475
options_ptr: *html_renderopt,

src/librustuv/uvll.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ pub struct uv_err_data {
10031003
err_msg: ~str,
10041004
}
10051005

1006+
// uv_support is the result of compiling rust_uv.cpp
1007+
#[link_args = "-luv_support -luv"]
10061008
extern {
10071009

10081010
fn rust_uv_handle_size(type_: uintptr_t) -> size_t;
@@ -1172,3 +1174,13 @@ extern {
11721174
signum: c_int) -> c_int;
11731175
fn rust_uv_signal_stop(handle: *uv_signal_t) -> c_int;
11741176
}
1177+
1178+
// libuv requires various system libraries to successfully link on some
1179+
// platforms
1180+
#[cfg(target_os = "linux")]
1181+
#[link_args = "-lpthread"]
1182+
extern {}
1183+
1184+
#[cfg(target_os = "win32")]
1185+
#[link_args = "-lWs2_32 -lpsapi -liphlpapi"]
1186+
extern {}

0 commit comments

Comments
 (0)