运行 LLVM 通过 Windows 10 在终端中没有输出?

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

我有来自 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 */);

该项目构建良好并创建了 SkeletonPass.dll。

当我执行命令时:

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 无法识别 -hello 选项,即便如此,在 Ubuntu 16.04.

上一切正常

此外,如果我执行:

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

Visual Studio 终端(本机工具命令提示符 x86)上未打印任何内容。在 Linux 上,相同位码文件的函数名称打印得很好。

我的经历可能是什么原因?我在 Windows 10 上做的和在 Ubuntu 上做的完全一样,但结果却大不相同。

插件是 Windows 上的特殊野兽,因为后者不支持适当的动态 linking,因此,您的通行证根本不会在 PassRegistry 中注册。所以你要么需要将所有的 LLVM 编译成 .dll,要么 link 你的 pass 静态地进入 opt / clang。