From 00211ecfda53521ea6b6405beff1c490b04f3ce5 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Thu, 12 Mar 2015 19:24:59 -0700 Subject: [PATCH 1/2] Avoid passing -L "" during cross-compilation. LLVM_LIBDIR_ is only defined for host triples, not target triples. FWIW, the same is true for LLVM_STDCPP_RUSTFLAGS_, where we explicitly define it as empty when --enable-llvm-static-stdcpp is not specified, but it's still undefined for cross-compiled triples. --- mk/main.mk | 1 + mk/target.mk | 2 +- mk/tests.mk | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mk/main.mk b/mk/main.mk index ad9d0d0ca5e..b9f2cf1cce8 100644 --- a/mk/main.mk +++ b/mk/main.mk @@ -290,6 +290,7 @@ LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version) LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir) LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir) LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir) +LLVM_LIBDIR_RUSTFLAGS_$(1)=-L "$$(LLVM_LIBDIR_$(1))" LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS)) LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags) # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM), diff --git a/mk/target.mk b/mk/target.mk index 4182ec81a7e..0a41f363649 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -84,7 +84,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \ $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) \ $$(RUST_LIB_FLAGS_ST$(1)) \ -L "$$(RT_OUTPUT_DIR_$(2))" \ - -L "$$(LLVM_LIBDIR_$(2))" \ + $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \ $$(LLVM_STDCPP_RUSTFLAGS_$(2)) \ $$(RUSTFLAGS_$(4)) \ --out-dir $$(@D) \ diff --git a/mk/tests.mk b/mk/tests.mk index 78f5ac11f06..48e50e47d4d 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -372,7 +372,7 @@ $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \ $(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(3)) \ $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \ -L "$$(RT_OUTPUT_DIR_$(2))" \ - -L "$$(LLVM_LIBDIR_$(2))" \ + $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \ $$(RUSTFLAGS_$(4)) endef From 85b084f4bd5c61adf23ca0de08cfba3d23ef1cfc Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Fri, 13 Mar 2015 23:49:44 -0700 Subject: [PATCH 2/2] Reject `-L ""`, `-L native=`, and other empty search paths. It wasn't clear to me that early_error was correct here, but it seems to work. This code is reachable from `rustdoc`, which is problematic, because early_error panics. rustc handles the panics gracefully (without ICEing or crashing), but rustdoc does not. It's not the first such rustdoc problem, though: $ rustdoc hello.rs --extern std=bad-std error: extern location for std does not exist: bad-std hello.rs:1:1: 1:1 error: can't find crate for `std` hello.rs:1 ^ error: aborting due to 2 previous errors thread '' panicked at 'Box', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:151 thread '' panicked at 'called `Result::unwrap()` on an `Err` value: "rustc failed"', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libcore/result.rs:744 thread '
' panicked at 'child thread None panicked', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread.rs:661 --- src/librustc/session/search_paths.rs | 4 ++++ .../compile-fail/manual-link-bad-search-path.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/test/compile-fail/manual-link-bad-search-path.rs diff --git a/src/librustc/session/search_paths.rs b/src/librustc/session/search_paths.rs index f85fb303910..3c5d9744505 100644 --- a/src/librustc/session/search_paths.rs +++ b/src/librustc/session/search_paths.rs @@ -10,6 +10,7 @@ use std::slice; use std::path::{Path, PathBuf}; +use session::early_error; #[derive(Clone, Debug)] pub struct SearchPaths { @@ -50,6 +51,9 @@ pub fn add_path(&mut self, path: &str) { } else { (PathKind::All, path) }; + if path.is_empty() { + early_error("empty search path given via `-L`"); + } self.paths.push((kind, PathBuf::new(path))); } diff --git a/src/test/compile-fail/manual-link-bad-search-path.rs b/src/test/compile-fail/manual-link-bad-search-path.rs new file mode 100644 index 00000000000..2bf61cbe24c --- /dev/null +++ b/src/test/compile-fail/manual-link-bad-search-path.rs @@ -0,0 +1,15 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags:-L native= +// error-pattern: empty search path given via `-L` + +fn main() { +}