about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-09-29 08:14:50 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-09-29 08:14:50 -0700
commit1a18258d863c0c887b108cecbd4c726862e6d90c (patch)
tree5b2e374538a3f7dd96a630478b163ed6b4369e39
parent915511ec6d9ef0d93d4c170580faa47aaca7ade9 (diff)
parent991f5062481d9b31e468273b76b27b8e14ad2c0a (diff)
downloadrust-1a18258d863c0c887b108cecbd4c726862e6d90c.tar.gz
rust-1a18258d863c0c887b108cecbd4c726862e6d90c.zip
rollup merge of #17619 : wizeman/fix-perm
-rw-r--r--src/librustc/back/link.rs12
-rw-r--r--src/test/run-make/lto-readonly-lib/Makefile12
-rw-r--r--src/test/run-make/lto-readonly-lib/lib.rs11
-rw-r--r--src/test/run-make/lto-readonly-lib/main.rs13
4 files changed, 48 insertions, 0 deletions
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index 633248562a5..b793096b30a 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -1319,6 +1319,18 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session,
                         sess.abort_if_errors();
                     }
                 }
+                // Fix up permissions of the copy, as fs::copy() preserves
+                // permissions, but the original file may have been installed
+                // by a package manager and may be read-only.
+                match fs::chmod(&dst, io::UserRead | io::UserWrite) {
+                    Ok(..) => {}
+                    Err(e) => {
+                        sess.err(format!("failed to chmod {} when preparing \
+                                          for LTO: {}", dst.display(),
+                                         e).as_slice());
+                        sess.abort_if_errors();
+                    }
+                }
                 let handler = &sess.diagnostic().handler;
                 let config = ArchiveConfig {
                     handler: handler,
diff --git a/src/test/run-make/lto-readonly-lib/Makefile b/src/test/run-make/lto-readonly-lib/Makefile
new file mode 100644
index 00000000000..0afbbc3450a
--- /dev/null
+++ b/src/test/run-make/lto-readonly-lib/Makefile
@@ -0,0 +1,12 @@
+-include ../tools.mk
+
+all:
+	$(RUSTC) lib.rs
+
+	# the compiler needs to copy and modify the rlib file when performing
+	# LTO, so we should ensure that it can cope with the original rlib
+	# being read-only.
+	chmod 444 $(TMPDIR)/*.rlib
+
+	$(RUSTC) main.rs -C lto
+	$(call RUN,main)
diff --git a/src/test/run-make/lto-readonly-lib/lib.rs b/src/test/run-make/lto-readonly-lib/lib.rs
new file mode 100644
index 00000000000..04d3ae67207
--- /dev/null
+++ b/src/test/run-make/lto-readonly-lib/lib.rs
@@ -0,0 +1,11 @@
+// Copyright 2014 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type = "rlib"]
diff --git a/src/test/run-make/lto-readonly-lib/main.rs b/src/test/run-make/lto-readonly-lib/main.rs
new file mode 100644
index 00000000000..e12ac9e01dc
--- /dev/null
+++ b/src/test/run-make/lto-readonly-lib/main.rs
@@ -0,0 +1,13 @@
+// Copyright 2014 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern crate lib;
+
+fn main() {}