Skip to content

Commit 5b44e10

Browse files
committed
[LLVM-3.9] Preserve certain functions when internalizing
This makes sure to still use the old way for older LLVM versions.
1 parent 6ed5db8 commit 5b44e10

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/rustllvm/PassWrapper.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,24 @@ LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB, bool AddLifetimes) {
358358

359359
extern "C" void
360360
LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
361-
PassManager passes;
361+
llvm::legacy::PassManager passes;
362+
363+
#if LLVM_VERSION_MINOR <= 8
362364
ArrayRef<const char*> ref(symbols, len);
363365
passes.add(llvm::createInternalizePass(ref));
366+
#else
367+
auto PreserveFunctions = [=](const GlobalValue &GV) {
368+
for (size_t i=0; i<len; i++) {
369+
if (GV.getName() == symbols[i]) {
370+
return true;
371+
}
372+
}
373+
return false;
374+
};
375+
376+
passes.add(llvm::createInternalizePass(PreserveFunctions));
377+
#endif
378+
364379
passes.run(*unwrap(M));
365380
}
366381

0 commit comments

Comments
 (0)