Skip to content

Commit 6bb1862

Browse files
committed
---
yaml --- r: 150002 b: refs/heads/try2 c: 17ad504 h: refs/heads/master v: v3
1 parent f5946aa commit 6bb1862

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 0b3df19c6a02a743dae904245c6f98424e75af8c
8+
refs/heads/try2: 17ad504fef35191fe53874bd2fe77ffd14d8e1b9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/metadata/cstore.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,44 @@ impl CStore {
143143
self.used_link_args.with_mut(|s| s.clear());
144144
}
145145

146+
// This method is used when generating the command line to pass through to
147+
// system linker. The linker expects undefined symbols on the left of the
148+
// command line to be defined in libraries on the right, not the other way
149+
// around. For more info, see some comments in the add_used_library function
150+
// below.
151+
//
152+
// In order to get this left-to-right dependency ordering, we perform a
153+
// topological sort of all crates putting the leaves at the right-most
154+
// positions.
146155
pub fn get_used_crates(&self, prefer: LinkagePreference)
147156
-> Vec<(ast::CrateNum, Option<Path>)> {
157+
let mut ordering = Vec::new();
158+
fn visit(cstore: &CStore, cnum: ast::CrateNum,
159+
ordering: &mut Vec<ast::CrateNum>) {
160+
if ordering.as_slice().contains(&cnum) { return }
161+
let meta = cstore.get_crate_data(cnum);
162+
for (_, &dep) in meta.cnum_map.borrow().get().iter() {
163+
visit(cstore, dep, ordering);
164+
}
165+
ordering.push(cnum);
166+
};
167+
for (&num, _) in self.metas.borrow().get().iter() {
168+
visit(self, num, &mut ordering);
169+
}
170+
ordering.as_mut_slice().reverse();
171+
let ordering = ordering.as_slice();
148172
let used_crate_sources = self.used_crate_sources.borrow();
149-
used_crate_sources.get()
173+
let mut libs = used_crate_sources.get()
150174
.iter()
151175
.map(|src| (src.cnum, match prefer {
152176
RequireDynamic => src.dylib.clone(),
153177
RequireStatic => src.rlib.clone(),
154178
}))
155-
.collect()
179+
.collect();
180+
libs.sort_by(|&(a, _), &(b, _)| {
181+
ordering.position_elem(&a).cmp(&ordering.position_elem(&b))
182+
});
183+
libs
156184
}
157185

158186
pub fn add_used_library(&self, lib: ~str, kind: NativeLibaryKind) {

0 commit comments

Comments
 (0)