我有一個簡單的LLVM通道,用於重命名當前翻譯單元中定義的每個函數(即所有預處理步驟發生後所涉及的源文件 - 請參閱here)。我的通行證如下:如何鏈接兩個LLVM位碼模塊?
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/TypeFinder.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/GlobalValue.h"
using namespace llvm;
namespace {
struct FunctionRename : public ModulePass {
static char ID; // Pass identification
FunctionRename() : ModulePass(ID) {}
bool runOnModule(Module &M) override {
// Rename all functions
for (auto &F : M) {
StringRef Name = F.getName();
// Leave library functions alone because their presence or absence
// could affect the behaviour of other passes.
if (F.isDeclaration())
continue;
F.setLinkage(GlobalValue::LinkOnceAnyLinkage);
F.setName(Name + "_renamed");
}
return true;
}
};
}
char FunctionRename::ID = 0;
static RegisterPass<FunctionRename> X("functionrename", "Function Rename Pass");
// ===-------------------------------------------------------==//
//
// Function Renamer - Renames all functions
//
運行後傳過來一個位碼文件,file.bc
,我將結果輸出到一個新文件file_renamed.bc
,如下
opt -load /path/to/libFunctionRenamePass.so -functionrename <file.bc> file_renamed.bc
然後我試圖鏈接這兩個文件如下
llvm-link file.bc file_renamed.bc -o file_linked.bc
但是,我仍然得到C++源文件(從中生成初始位代碼文件)涉及構造函數和析構函數的符號衝突。我的期望是,線
F.setLinkage(GlobalValue::LinkOnceAnyLinkage)
將防止發生在file.bc
和file_renamed.bc
定義的任何符號的符號衝突。
我在做什麼錯?
你能提供你收到錯誤的實際文字嗎? – jvstech