1
Fork 0

[LLVM-3.9] Preserve certain functions when internalizing

This makes sure to still use the old way for older LLVM versions.
This commit is contained in:
Jan-Erik Rediger 2016-07-13 00:42:44 +02:00
parent 6ed5db8d35
commit 5b44e10fb7

View file

@ -358,9 +358,24 @@ LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB, bool AddLifetimes) {
extern "C" void
LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
PassManager passes;
llvm::legacy::PassManager passes;
#if LLVM_VERSION_MINOR <= 8
ArrayRef<const char*> ref(symbols, len);
passes.add(llvm::createInternalizePass(ref));
#else
auto PreserveFunctions = [=](const GlobalValue &GV) {
for (size_t i=0; i<len; i++) {
if (GV.getName() == symbols[i]) {
return true;
}
}
return false;
};
passes.add(llvm::createInternalizePass(PreserveFunctions));
#endif
passes.run(*unwrap(M));
}