Fix symbol name mangling for LLVM 7.0.

The Mach-O executable format, used on macOS/Darwin, stores function
names in mangled form, so we need to mangle it ourselves during
function pointer lookup.

Bug b/115344057

Change-Id: I8de5756c52b5af666826134fca8274b4467fa85a
Reviewed-on: https://swiftshader-review.googlesource.com/c/22188
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index c08572c..f7cbfab 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -61,6 +61,7 @@
 	#include "llvm/IR/Intrinsics.h"
 	#include "llvm/IR/LLVMContext.h"
 	#include "llvm/IR/LegacyPassManager.h"
+	#include "llvm/IR/Mangler.h"
 	#include "llvm/IR/Module.h"
 	#include "llvm/Support/Error.h"
 	#include "llvm/Support/TargetSelect.h"
@@ -635,10 +636,16 @@
 			auto moduleKey = session.allocateVModule();
 			llvm::cantFail(compileLayer.addModule(moduleKey, std::move(mod)));
 
-			llvm::JITSymbol symbol = compileLayer.findSymbolIn(moduleKey, name, false);
+			std::string mangledName;
+			{
+				llvm::raw_string_ostream mangledNameStream(mangledName);
+				llvm::Mangler::getNameWithPrefix(mangledNameStream, name, dataLayout);
+			}
+
+			llvm::JITSymbol symbol = compileLayer.findSymbolIn(moduleKey, mangledName, false);
 
 			llvm::Expected<llvm::JITTargetAddress> expectAddr = symbol.getAddress();
-			if (!expectAddr)
+			if(!expectAddr)
 			{
 				return nullptr;
 			}