Running LLVM passes on Windows 10 gives no output in terminal?

不羁岁月 提交于 2019-12-12 03:57:49

问题


I've the sample pass code from LLVM.org:

#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

namespace {
    struct Hello : public FunctionPass {
        static char ID;
        Hello() : FunctionPass(ID) {}

        bool runOnFunction(Function &F) override {
            errs() << "Hello: ";
            errs().write_escaped(F.getName()) << '\n';
            return false;
        }
    }; // end of struct Hello
}  // end of anonymous namespace

char Hello::ID = 0;
static RegisterPass<Hello> X("hello", "Hello World Pass",
    false /* Only looks at CFG */,
    false /* Analysis Pass */);

The project builds fine and creates a SkeletonPass.dll.

When I execute the command:

C:\Users\nlykkei\Projects\llvm-pass-tutorial\build>opt -load skeleton\Debug\SkeletonPass.dll -hello foo.bc
opt: Unknown command line argument '-hello'.  Try: 'opt -help'
opt: Did you mean '-help'?

opt doesn't recognize -hello option, even thus everything works fine on Ubuntu 16.04.

In addition, if I execute:

clang -Xclang -load -Xclang skeleton\Debug\SkeletonPass.dll foo.bc

nothing is printed out on Visual Studio terminal (Native Tools Command Prompt x86). On Linux, the function names are printed nicely for the same bitcode file.

What can be the reason for my experience? I do exactly the same on Windows 10 as I do on Ubuntu, but very different results.


回答1:


Plugins are special beasts on Windows, because the latter does not support proper dynamic linking, so, your pass simply does not register itself in the PassRegistry. So you'd either need to compile all the LLVM into .dll or link your pass statically into opt / clang.



来源:https://stackoverflow.com/questions/41943353/running-llvm-passes-on-windows-10-gives-no-output-in-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!