OSDN Git Service

Fix symbol name mangling for LLVM 7.0.
authorNicolas Capens <capn@google.com>
Wed, 31 Oct 2018 18:38:53 +0000 (14:38 -0400)
committerNicolas Capens <nicolascapens@google.com>
Wed, 31 Oct 2018 19:17:15 +0000 (19:17 +0000)
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>
src/Reactor/LLVMReactor.cpp

index c08572c..f7cbfab 100644 (file)
@@ -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 @@ namespace rr
                        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;
                        }