1

我想如何提取LLVM上的完整功能信息?

  1. 提取物起LLVM IR
  2. 他們每個人保存到不同的文件(或只是一個字符串對象)
  3. 從文件中讀取保存的功能(或只是一個字符串對象)
  4. 重新使用它的框架

不過,我目前的提取方法僅複製部分信息,我不能事後再建功能。我主要有紅外讀者抱怨的問題:

error: use of undefined type named 'class.std::allocator' 
... 
error: use of undefined comdat '$_ZNSt10_Iter_baseIPiLb0EE7_S_baseES0_' 

它可以通過添加適當的聲明(COMDAT和類型),以提取IR的頂部來解決。

BEFORE:

; Function Attrs: noinline nounwind uwtable 
define linkonce_odr i64 @_ZNK9__gnu_cxx13new_allocatorIiE8max_sizeEv(%"class.__gnu_cxx::new_allocator"*) #4 comdat align 2 { 
    ret i64 4611686018427387903 
} 

AFTER:

#include "llvm/IR/Module.h" 
#include "llvm/IR/LLVMContext.h" 
#include "llvm/IRReader/IRReader.h" 
#include "llvm/ADT/StringRef.h" 
#include "llvm/Support/SourceMgr.h" // SMDDiagnostic 
#include "llvm/Support/MemoryBuffer.h" 

using namespace llvm; 

... 

// A method receives a LLVM::Function& F as its argument 
// Steps 1 and 2 
std::string IRString; 
raw_string_ostream os(IRString); 
F.print(os, nullptr); 
os.flush(); 

// IRString has the LLVM IR for the function (currently with the BEFORE version) 
// Now it is necessary to read back this IR 
// Steps 3 and 4 
SMDiagnostic Err; 
LLVMContext Context; 
std::unique_ptr<llvm::MemoryBuffer> buff = 
llvm::MemoryBuffer::getMemBuffer(SU.getIRInfo()); 

std::unique_ptr<Module> Mod(parseIR(buff->getMemBufferRef(), Err, Context)); 
if (!Mod) { 
    Err.print("Reading Problems", errs()); 
    return 1; 
} 

... 

我怎樣才能讓:

%"class.__gnu_cxx::new_allocator" = type { i8 } 
$_ZNK9__gnu_cxx13new_allocatorIiE8max_sizeEv = comdat any 

; Function Attrs: noinline nounwind uwtable 
define linkonce_odr i64 @_ZNK9__gnu_cxx13new_allocatorIiE8max_sizeEv(%"class.__gnu_cxx::new_allocator"*) #4 comdat align 2 { 
    ret i64 4611686018427387903 
} 

我目前落實使用以下步驟1,2,3,4這個過程自動?

回答

1

看看llvm-extract或GVExtraction類(它被llvm-extract使用)。