Skip to content

Commit 1956d55

Browse files
committed
Auto merge of #46435 - cuviper:min-llvm-3.9, r=rkruppe
Assume at least LLVM 3.9 in rustllvm and rustc_llvm We bumped the minimum LLVM to 3.9 in #45326. This just cleans up the conditional code in the `rustllvm` C++ wrappers to assume that minimum, and similarly cleans up the `rustc_llvm` build script.
2 parents f2b11f3 + 5c4452a commit 1956d55

File tree

5 files changed

+13
-180
lines changed

5 files changed

+13
-180
lines changed

src/librustc_llvm/build.rs

+12-32
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,14 @@ use std::path::{PathBuf, Path};
1717

1818
use build_helper::output;
1919

20-
fn detect_llvm_link(major: u32, minor: u32, llvm_config: &Path)
21-
-> (&'static str, Option<&'static str>) {
22-
if major > 3 || (major == 3 && minor >= 9) {
23-
// Force the link mode we want, preferring static by default, but
24-
// possibly overridden by `configure --enable-llvm-link-shared`.
25-
if env::var_os("LLVM_LINK_SHARED").is_some() {
26-
return ("dylib", Some("--link-shared"));
27-
} else {
28-
return ("static", Some("--link-static"));
29-
}
30-
} else if major == 3 && minor == 8 {
31-
// Find out LLVM's default linking mode.
32-
let mut mode_cmd = Command::new(llvm_config);
33-
mode_cmd.arg("--shared-mode");
34-
if output(&mut mode_cmd).trim() == "shared" {
35-
return ("dylib", None);
36-
} else {
37-
return ("static", None);
38-
}
20+
fn detect_llvm_link() -> (&'static str, &'static str) {
21+
// Force the link mode we want, preferring static by default, but
22+
// possibly overridden by `configure --enable-llvm-link-shared`.
23+
if env::var_os("LLVM_LINK_SHARED").is_some() {
24+
("dylib", "--link-shared")
25+
} else {
26+
("static", "--link-static")
3927
}
40-
("static", None)
4128
}
4229

4330
fn main() {
@@ -96,11 +83,11 @@ fn main() {
9683
let version_output = output(&mut version_cmd);
9784
let mut parts = version_output.split('.').take(2)
9885
.filter_map(|s| s.parse::<u32>().ok());
99-
let (major, minor) =
86+
let (major, _minor) =
10087
if let (Some(major), Some(minor)) = (parts.next(), parts.next()) {
10188
(major, minor)
10289
} else {
103-
(3, 7)
90+
(3, 9)
10491
};
10592

10693
if major > 3 {
@@ -171,17 +158,13 @@ fn main() {
171158
.cpp_link_stdlib(None) // we handle this below
172159
.compile("rustllvm");
173160

174-
let (llvm_kind, llvm_link_arg) = detect_llvm_link(major, minor, &llvm_config);
161+
let (llvm_kind, llvm_link_arg) = detect_llvm_link();
175162

176163
// Link in all LLVM libraries, if we're uwring the "wrong" llvm-config then
177164
// we don't pick up system libs because unfortunately they're for the host
178165
// of llvm-config, not the target that we're attempting to link.
179166
let mut cmd = Command::new(&llvm_config);
180-
cmd.arg("--libs");
181-
182-
if let Some(link_arg) = llvm_link_arg {
183-
cmd.arg(link_arg);
184-
}
167+
cmd.arg(llvm_link_arg).arg("--libs");
185168

186169
if !is_crossed {
187170
cmd.arg("--system-libs");
@@ -230,10 +213,7 @@ fn main() {
230213
// hack around this by replacing the host triple with the target and pray
231214
// that those -L directories are the same!
232215
let mut cmd = Command::new(&llvm_config);
233-
if let Some(link_arg) = llvm_link_arg {
234-
cmd.arg(link_arg);
235-
}
236-
cmd.arg("--ldflags");
216+
cmd.arg(llvm_link_arg).arg("--ldflags");
237217
for lib in output(&mut cmd).split_whitespace() {
238218
if lib.starts_with("-LIBPATH:") {
239219
println!("cargo:rustc-link-search=native={}", &lib[9..]);

src/rustllvm/ArchiveWrapper.cpp

-49
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ struct RustArchiveMember {
2424

2525
RustArchiveMember()
2626
: Filename(nullptr), Name(nullptr),
27-
#if LLVM_VERSION_GE(3, 8)
2827
Child(nullptr, nullptr, nullptr)
29-
#else
30-
Child(nullptr, nullptr)
31-
#endif
3228
{
3329
}
3430
~RustArchiveMember() {}
@@ -38,13 +34,9 @@ struct RustArchiveIterator {
3834
bool First;
3935
Archive::child_iterator Cur;
4036
Archive::child_iterator End;
41-
#if LLVM_VERSION_GE(3, 9)
4237
Error Err;
4338

4439
RustArchiveIterator() : First(true), Err(Error::success()) {}
45-
#else
46-
RustArchiveIterator() : First(true) {}
47-
#endif
4840
};
4941

5042
enum class LLVMRustArchiveKind {
@@ -84,19 +76,11 @@ extern "C" LLVMRustArchiveRef LLVMRustOpenArchive(char *Path) {
8476
return nullptr;
8577
}
8678

87-
#if LLVM_VERSION_LE(3, 8)
88-
ErrorOr<std::unique_ptr<Archive>> ArchiveOr =
89-
#else
9079
Expected<std::unique_ptr<Archive>> ArchiveOr =
91-
#endif
9280
Archive::create(BufOr.get()->getMemBufferRef());
9381

9482
if (!ArchiveOr) {
95-
#if LLVM_VERSION_LE(3, 8)
96-
LLVMRustSetLastError(ArchiveOr.getError().message().c_str());
97-
#else
9883
LLVMRustSetLastError(toString(ArchiveOr.takeError()).c_str());
99-
#endif
10084
return nullptr;
10185
}
10286

@@ -114,16 +98,12 @@ extern "C" LLVMRustArchiveIteratorRef
11498
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef RustArchive) {
11599
Archive *Archive = RustArchive->getBinary();
116100
RustArchiveIterator *RAI = new RustArchiveIterator();
117-
#if LLVM_VERSION_LE(3, 8)
118-
RAI->Cur = Archive->child_begin();
119-
#else
120101
RAI->Cur = Archive->child_begin(RAI->Err);
121102
if (RAI->Err) {
122103
LLVMRustSetLastError(toString(std::move(RAI->Err)).c_str());
123104
delete RAI;
124105
return nullptr;
125106
}
126-
#endif
127107
RAI->End = Archive->child_end();
128108
return RAI;
129109
}
@@ -141,29 +121,18 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef RAI) {
141121
// but instead advance it *before* fetching the child in all later calls.
142122
if (!RAI->First) {
143123
++RAI->Cur;
144-
#if LLVM_VERSION_GE(3, 9)
145124
if (RAI->Err) {
146125
LLVMRustSetLastError(toString(std::move(RAI->Err)).c_str());
147126
return nullptr;
148127
}
149-
#endif
150128
} else {
151129
RAI->First = false;
152130
}
153131

154132
if (RAI->Cur == RAI->End)
155133
return nullptr;
156134

157-
#if LLVM_VERSION_EQ(3, 8)
158-
const ErrorOr<Archive::Child> *Cur = RAI->Cur.operator->();
159-
if (!*Cur) {
160-
LLVMRustSetLastError(Cur->getError().message().c_str());
161-
return nullptr;
162-
}
163-
const Archive::Child &Child = Cur->get();
164-
#else
165135
const Archive::Child &Child = *RAI->Cur.operator->();
166-
#endif
167136
Archive::Child *Ret = new Archive::Child(Child);
168137

169138
return Ret;
@@ -239,18 +208,13 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
239208
const LLVMRustArchiveMemberRef *NewMembers,
240209
bool WriteSymbtab, LLVMRustArchiveKind RustKind) {
241210

242-
#if LLVM_VERSION_LE(3, 8)
243-
std::vector<NewArchiveIterator> Members;
244-
#else
245211
std::vector<NewArchiveMember> Members;
246-
#endif
247212
auto Kind = fromRust(RustKind);
248213

249214
for (size_t I = 0; I < NumMembers; I++) {
250215
auto Member = NewMembers[I];
251216
assert(Member->Name);
252217
if (Member->Filename) {
253-
#if LLVM_VERSION_GE(3, 9)
254218
Expected<NewArchiveMember> MOrErr =
255219
NewArchiveMember::getFile(Member->Filename, true);
256220
if (!MOrErr) {
@@ -261,30 +225,17 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
261225
MOrErr->MemberName = sys::path::filename(MOrErr->MemberName);
262226
#endif
263227
Members.push_back(std::move(*MOrErr));
264-
#elif LLVM_VERSION_EQ(3, 8)
265-
Members.push_back(NewArchiveIterator(Member->Filename));
266-
#else
267-
Members.push_back(NewArchiveIterator(Member->Filename, Member->Name));
268-
#endif
269228
} else {
270-
#if LLVM_VERSION_LE(3, 8)
271-
Members.push_back(NewArchiveIterator(Member->Child, Member->Name));
272-
#else
273229
Expected<NewArchiveMember> MOrErr =
274230
NewArchiveMember::getOldMember(Member->Child, true);
275231
if (!MOrErr) {
276232
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
277233
return LLVMRustResult::Failure;
278234
}
279235
Members.push_back(std::move(*MOrErr));
280-
#endif
281236
}
282237
}
283-
#if LLVM_VERSION_GE(3, 8)
284238
auto Pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
285-
#else
286-
auto Pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true);
287-
#endif
288239
if (!Pair.second)
289240
return LLVMRustResult::Success;
290241
LLVMRustSetLastError(Pair.second.message().c_str());

src/rustllvm/PassWrapper.cpp

-21
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ extern "C" void LLVMInitializePasses() {
5959
initializeVectorization(Registry);
6060
initializeIPO(Registry);
6161
initializeAnalysis(Registry);
62-
#if LLVM_VERSION_EQ(3, 7)
63-
initializeIPA(Registry);
64-
#endif
6562
initializeTransformUtils(Registry);
6663
initializeInstCombine(Registry);
6764
initializeInstrumentation(Registry);
@@ -273,18 +270,10 @@ enum class LLVMRustRelocMode {
273270
ROPIRWPI,
274271
};
275272

276-
#if LLVM_VERSION_LE(3, 8)
277-
static Reloc::Model fromRust(LLVMRustRelocMode RustReloc) {
278-
#else
279273
static Optional<Reloc::Model> fromRust(LLVMRustRelocMode RustReloc) {
280-
#endif
281274
switch (RustReloc) {
282275
case LLVMRustRelocMode::Default:
283-
#if LLVM_VERSION_LE(3, 8)
284-
return Reloc::Default;
285-
#else
286276
return None;
287-
#endif
288277
case LLVMRustRelocMode::Static:
289278
return Reloc::Static;
290279
case LLVMRustRelocMode::PIC:
@@ -390,9 +379,6 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
390379
}
391380

392381
TargetOptions Options;
393-
#if LLVM_VERSION_LE(3, 8)
394-
Options.PositionIndependentExecutable = PositionIndependentExecutable;
395-
#endif
396382

397383
Options.FloatABIType = FloatABI::Default;
398384
if (UseSoftFloat) {
@@ -720,10 +706,6 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
720706
size_t Len) {
721707
llvm::legacy::PassManager passes;
722708

723-
#if LLVM_VERSION_LE(3, 8)
724-
ArrayRef<const char *> Ref(Symbols, Len);
725-
passes.add(llvm::createInternalizePass(Ref));
726-
#else
727709
auto PreserveFunctions = [=](const GlobalValue &GV) {
728710
for (size_t I = 0; I < Len; I++) {
729711
if (GV.getName() == Symbols[I]) {
@@ -734,7 +716,6 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
734716
};
735717

736718
passes.add(llvm::createInternalizePass(PreserveFunctions));
737-
#endif
738719

739720
passes.run(*unwrap(M));
740721
}
@@ -770,9 +751,7 @@ extern "C" LLVMTargetDataRef LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
770751
}
771752

772753
extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
773-
#if LLVM_VERSION_GE(3, 9)
774754
unwrap(M)->setPIELevel(PIELevel::Level::Large);
775-
#endif
776755
}
777756

778757
extern "C" bool

0 commit comments

Comments
 (0)