Skip to content

Commit 07f5dbc

Browse files
committed
Revert "Rollup merge of rust-lang#56944 - alexcrichton:less-thin2, r=michaelwoerister"
This reverts commit f1051b5, reversing changes made to 833e0b3.
1 parent ad781a0 commit 07f5dbc

File tree

11 files changed

+240
-18
lines changed

11 files changed

+240
-18
lines changed

src/bootstrap/check.rs

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl Step for Std {
4848
builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
4949
run_cargo(builder,
5050
&mut cargo,
51+
vec![],
5152
&libstd_stamp(builder, compiler, target),
5253
true);
5354

@@ -94,6 +95,7 @@ impl Step for Rustc {
9495
builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
9596
run_cargo(builder,
9697
&mut cargo,
98+
vec![],
9799
&librustc_stamp(builder, compiler, target),
98100
true);
99101

@@ -144,6 +146,7 @@ impl Step for CodegenBackend {
144146
let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
145147
run_cargo(builder,
146148
&mut cargo,
149+
vec![],
147150
&codegen_backend_stamp(builder, compiler, target, backend),
148151
true);
149152
}
@@ -181,6 +184,7 @@ impl Step for Test {
181184
builder.info(&format!("Checking test artifacts ({} -> {})", &compiler.host, target));
182185
run_cargo(builder,
183186
&mut cargo,
187+
vec![],
184188
&libtest_stamp(builder, compiler, target),
185189
true);
186190

@@ -228,6 +232,7 @@ impl Step for Rustdoc {
228232
println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target);
229233
run_cargo(builder,
230234
&mut cargo,
235+
vec![],
231236
&rustdoc_stamp(builder, compiler, target),
232237
true);
233238

src/bootstrap/compile.rs

+41-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use build_helper::{output, mtime, up_to_date};
2929
use filetime::FileTime;
3030
use serde_json;
3131

32-
use crate::dist;
3332
use crate::util::{exe, libdir, is_dylib};
3433
use crate::{Compiler, Mode, GitRepo};
3534
use crate::native;
@@ -115,6 +114,7 @@ impl Step for Std {
115114
&compiler.host, target));
116115
run_cargo(builder,
117116
&mut cargo,
117+
vec![],
118118
&libstd_stamp(builder, compiler, target),
119119
false);
120120

@@ -375,6 +375,7 @@ impl Step for Test {
375375
&compiler.host, target));
376376
run_cargo(builder,
377377
&mut cargo,
378+
vec![],
378379
&libtest_stamp(builder, compiler, target),
379380
false);
380381

@@ -502,6 +503,7 @@ impl Step for Rustc {
502503
compiler.stage, &compiler.host, target));
503504
run_cargo(builder,
504505
&mut cargo,
506+
vec![],
505507
&librustc_stamp(builder, compiler, target),
506508
false);
507509

@@ -644,18 +646,47 @@ impl Step for CodegenBackend {
644646

645647
let out_dir = builder.cargo_out(compiler, Mode::Codegen, target);
646648

647-
let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "build");
649+
let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "rustc");
648650
cargo.arg("--manifest-path")
649651
.arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
650652
rustc_cargo_env(builder, &mut cargo);
651653

652654
let features = build_codegen_backend(&builder, &mut cargo, &compiler, target, backend);
653655

656+
let mut cargo_tails_args = vec![];
657+
658+
if builder.config.llvm_thin_lto {
659+
cargo_tails_args.push("--".to_string());
660+
661+
let num_jobs = builder.jobs();
662+
663+
if !target.contains("msvc") {
664+
// Here we assume that the linker is clang. If it's not, there'll
665+
// be linker errors.
666+
cargo_tails_args.push("-Clink-arg=-fuse-ld=lld".to_string());
667+
cargo_tails_args.push("-Clink-arg=-flto=thin".to_string());
668+
669+
if builder.config.llvm_optimize {
670+
cargo_tails_args.push("-Clink-arg=-O2".to_string());
671+
}
672+
673+
// Let's make LLD respect the `-j` option.
674+
let num_jobs_arg = format!("-Clink-arg=-Wl,--thinlto-jobs={}", num_jobs);
675+
cargo_tails_args.push(num_jobs_arg);
676+
} else {
677+
// Here we assume that the linker is lld-link.exe. lld-link.exe
678+
// does not need the extra arguments except for num_jobs
679+
let num_jobs_arg = format!("-Clink-arg=/opt:lldltojobs={}", num_jobs);
680+
cargo_tails_args.push(num_jobs_arg);
681+
}
682+
}
683+
654684
let tmp_stamp = out_dir.join(".tmp.stamp");
655685

656686
let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
657687
let files = run_cargo(builder,
658688
cargo.arg("--features").arg(features),
689+
cargo_tails_args,
659690
&tmp_stamp,
660691
false);
661692
if builder.config.dry_run {
@@ -728,9 +759,7 @@ pub fn build_codegen_backend(builder: &Builder,
728759
"libstdc++.a");
729760
cargo.env("LLVM_STATIC_STDCPP", file);
730761
}
731-
if builder.config.llvm_link_shared ||
732-
(builder.config.llvm_thin_lto && backend != "emscripten")
733-
{
762+
if builder.config.llvm_link_shared {
734763
cargo.env("LLVM_LINK_SHARED", "1");
735764
}
736765
}
@@ -970,8 +999,6 @@ impl Step for Assemble {
970999
copy_lld_to_sysroot(builder, target_compiler, &lld_install);
9711000
}
9721001

973-
dist::maybe_install_llvm_dylib(builder, target_compiler.host, &sysroot);
974-
9751002
// Link the compiler binary itself into place
9761003
let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host);
9771004
let rustc = out_dir.join(exe("rustc_binary", &*host));
@@ -998,6 +1025,7 @@ pub fn add_to_sysroot(builder: &Builder, sysroot_dst: &Path, stamp: &Path) {
9981025

9991026
pub fn run_cargo(builder: &Builder,
10001027
cargo: &mut Command,
1028+
tail_args: Vec<String>,
10011029
stamp: &Path,
10021030
is_check: bool)
10031031
-> Vec<PathBuf>
@@ -1020,7 +1048,7 @@ pub fn run_cargo(builder: &Builder,
10201048
// files we need to probe for later.
10211049
let mut deps = Vec::new();
10221050
let mut toplevel = Vec::new();
1023-
let ok = stream_cargo(builder, cargo, &mut |msg| {
1051+
let ok = stream_cargo(builder, cargo, tail_args, &mut |msg| {
10241052
let filenames = match msg {
10251053
CargoMessage::CompilerArtifact { filenames, .. } => filenames,
10261054
_ => return,
@@ -1145,6 +1173,7 @@ pub fn run_cargo(builder: &Builder,
11451173
pub fn stream_cargo(
11461174
builder: &Builder,
11471175
cargo: &mut Command,
1176+
tail_args: Vec<String>,
11481177
cb: &mut dyn FnMut(CargoMessage),
11491178
) -> bool {
11501179
if builder.config.dry_run {
@@ -1155,6 +1184,10 @@ pub fn stream_cargo(
11551184
cargo.arg("--message-format").arg("json")
11561185
.stdout(Stdio::piped());
11571186

1187+
for arg in tail_args {
1188+
cargo.arg(arg);
1189+
}
1190+
11581191
builder.verbose(&format!("running: {:?}", cargo));
11591192
let mut child = match cargo.spawn() {
11601193
Ok(child) => child,

src/bootstrap/dist.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1887,13 +1887,13 @@ impl Step for HashSign {
18871887
// LLVM tools are linked dynamically.
18881888
// Note: This function does no yet support Windows but we also don't support
18891889
// linking LLVM tools dynamically on Windows yet.
1890-
pub fn maybe_install_llvm_dylib(builder: &Builder,
1891-
target: Interned<String>,
1892-
sysroot: &Path) {
1890+
fn maybe_install_llvm_dylib(builder: &Builder,
1891+
target: Interned<String>,
1892+
image: &Path) {
18931893
let src_libdir = builder
18941894
.llvm_out(target)
18951895
.join("lib");
1896-
let dst_libdir = sysroot.join("lib/rustlib").join(&*target).join("lib");
1896+
let dst_libdir = image.join("lib/rustlib").join(&*target).join("lib");
18971897
t!(fs::create_dir_all(&dst_libdir));
18981898

18991899
if target.contains("apple-darwin") {

src/bootstrap/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Step for ToolBuild {
8787
let _folder = builder.fold_output(|| format!("stage{}-{}", compiler.stage, tool));
8888
builder.info(&format!("Building stage{} tool {} ({})", compiler.stage, tool, target));
8989
let mut duplicates = Vec::new();
90-
let is_expected = compile::stream_cargo(builder, &mut cargo, &mut |msg| {
90+
let is_expected = compile::stream_cargo(builder, &mut cargo, vec![], &mut |msg| {
9191
// Only care about big things like the RLS/Cargo for now
9292
match tool {
9393
| "rls"

src/librustc_driver/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,14 @@ pub fn run<F>(run_compiler: F) -> isize
210210
}
211211

212212
fn load_backend_from_dylib(path: &Path) -> fn() -> Box<dyn CodegenBackend> {
213-
let lib = DynamicLibrary::open(Some(path)).unwrap_or_else(|err| {
213+
// Note that we're specifically using `open_global_now` here rather than
214+
// `open`, namely we want the behavior on Unix of RTLD_GLOBAL and RTLD_NOW,
215+
// where NOW means "bind everything right now" because we don't want
216+
// surprises later on and RTLD_GLOBAL allows the symbols to be made
217+
// available for future dynamic libraries opened. This is currently used by
218+
// loading LLVM and then making its symbols available for other dynamic
219+
// libraries.
220+
let lib = DynamicLibrary::open_global_now(path).unwrap_or_else(|err| {
214221
let err = format!("couldn't load codegen backend {:?}: {:?}", path, err);
215222
early_error(ErrorOutputType::default(), &err);
216223
});

src/librustc_llvm/build.rs

-4
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ fn main() {
142142
continue;
143143
}
144144

145-
if flag.starts_with("-flto") {
146-
continue;
147-
}
148-
149145
// -Wdate-time is not supported by the netbsd cross compiler
150146
if is_crossed && target.contains("netbsd") && flag.contains("date-time") {
151147
continue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-include ../tools.mk
2+
3+
ifeq ($(UNAME),Darwin)
4+
PLUGIN_FLAGS := -C link-args=-Wl,-undefined,dynamic_lookup
5+
endif
6+
7+
ifeq ($(findstring stage1,$(RUST_BUILD_STAGE)),stage1)
8+
# ignore stage1
9+
all:
10+
11+
else
12+
# Windows doesn't correctly handle include statements with escaping paths,
13+
# so this test will not get run on Windows.
14+
ifdef IS_WINDOWS
15+
all:
16+
else
17+
all: $(call NATIVE_STATICLIB,llvm-function-pass) $(call NATIVE_STATICLIB,llvm-module-pass)
18+
$(RUSTC) plugin.rs -C prefer-dynamic $(PLUGIN_FLAGS)
19+
$(RUSTC) main.rs
20+
21+
$(TMPDIR)/libllvm-function-pass.o:
22+
$(CXX) $(CFLAGS) $(LLVM_CXXFLAGS) -c llvm-function-pass.so.cc -o $(TMPDIR)/libllvm-function-pass.o
23+
24+
$(TMPDIR)/libllvm-module-pass.o:
25+
$(CXX) $(CFLAGS) $(LLVM_CXXFLAGS) -c llvm-module-pass.so.cc -o $(TMPDIR)/libllvm-module-pass.o
26+
endif
27+
28+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#include <stdio.h>
12+
#include <stdlib.h>
13+
#include <unistd.h>
14+
15+
#include "llvm/Pass.h"
16+
#include "llvm/IR/Function.h"
17+
18+
using namespace llvm;
19+
20+
namespace {
21+
22+
class TestLLVMPass : public FunctionPass {
23+
24+
public:
25+
26+
static char ID;
27+
TestLLVMPass() : FunctionPass(ID) { }
28+
29+
bool runOnFunction(Function &F) override;
30+
31+
StringRef getPassName() const override {
32+
return "Some LLVM pass";
33+
}
34+
35+
};
36+
37+
}
38+
39+
bool TestLLVMPass::runOnFunction(Function &F) {
40+
// A couple examples of operations that previously caused segmentation faults
41+
// https://github.com/rust-lang/rust/issues/31067
42+
43+
for (auto N = F.begin(); N != F.end(); ++N) {
44+
/* code */
45+
}
46+
47+
LLVMContext &C = F.getContext();
48+
IntegerType *Int8Ty = IntegerType::getInt8Ty(C);
49+
PointerType::get(Int8Ty, 0);
50+
return true;
51+
}
52+
53+
char TestLLVMPass::ID = 0;
54+
55+
static RegisterPass<TestLLVMPass> RegisterAFLPass(
56+
"some-llvm-function-pass", "Some LLVM pass");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#include <stdio.h>
12+
#include <stdlib.h>
13+
#include <unistd.h>
14+
15+
#include "llvm/IR/Module.h"
16+
17+
using namespace llvm;
18+
19+
namespace {
20+
21+
class TestLLVMPass : public ModulePass {
22+
23+
public:
24+
25+
static char ID;
26+
TestLLVMPass() : ModulePass(ID) { }
27+
28+
bool runOnModule(Module &M) override;
29+
30+
StringRef getPassName() const override {
31+
return "Some LLVM pass";
32+
}
33+
34+
};
35+
36+
}
37+
38+
bool TestLLVMPass::runOnModule(Module &M) {
39+
// A couple examples of operations that previously caused segmentation faults
40+
// https://github.com/rust-lang/rust/issues/31067
41+
42+
for (auto F = M.begin(); F != M.end(); ++F) {
43+
/* code */
44+
}
45+
46+
LLVMContext &C = M.getContext();
47+
IntegerType *Int8Ty = IntegerType::getInt8Ty(C);
48+
PointerType::get(Int8Ty, 0);
49+
return true;
50+
}
51+
52+
char TestLLVMPass::ID = 0;
53+
54+
static RegisterPass<TestLLVMPass> RegisterAFLPass(
55+
"some-llvm-module-pass", "Some LLVM pass");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(plugin)]
12+
#![plugin(some_plugin)]
13+
14+
fn main() {}

0 commit comments

Comments
 (0)