草庐IT

c++ - llvm 通过段错误 :(Core dumped)

coder 2024-02-12 原文

我写了一个简单的 llvm Pass 来计算 C++ 源文件中的操作码。我对源文件没有任何问题,我已经成功地获取了它的 .bc 文件。现在,当我通过我的通行证运行它时,它崩溃了。 pass 的代码如下(源代码不是问题):

#define DEBUG_TYPE "opCounter"
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include <map>

using namespace llvm;
namespace
{
  struct CountOperands : public FunctionPass
  {
    std::map<std::string,int> opCounter;
    static char ID;

    /*Constructor*/ 
    CountOperands() : FunctionPass(ID) {}

    /*RunOnFuntion Method*/
    virtual bool runOnFunction( Function &F)
    {
      errs() << "Function Name: " << F.getName() << "\n";

      /*Reading the OpCode in the function*/
      for (Function::iterator bb = F.begin(), e = F.end(); bb != e; ++bb)
      {    
        BasicBlock &b = *bb;
        errs() << "##########Works fine till here!"<<"\n";

        for (BasicBlock::iterator i = b.begin(), e2 = b.end(); i != e2; ++i)
        {

          if ( opCounter.find(i->getOpcodeName()) == opCounter.end() )
          {
            opCounter[i->getOpcodeName()] = 1; //New OpCode in the list
          }
          else
          {
            opCounter[i->getOpcodeName()] += 1; //Incrementing the old one
          }    
        }
      }
      std::map <std::string, int>::iterator i = opCounter.begin();
      std::map <std::string, int>::iterator e3 = opCounter.end();

      while(i != e3)
      {
        errs() << i->first << ": " << i->second << "\n";
        i++;
      }
      errs() << "\n";
      opCounter.clear();
      return false;
    }
  }; 
}
/*Registering the Pass to PassManager*/
char CountOperands::ID = 0;
static RegisterPass<CountOperands> X("opCounter", "Counts the OpCodes in a single Function");

我正在运行这些命令以通过 pass 运行我的 test.cpp 程序:

clang++ -emit-llvm testOp.cpp -c -o test.bc 然后制作,最后制作

opt -load ../../../Release+Asserts/lib/LLVMopCounter.so -opCounter /dev/null

输出如下:

homer@ubuntu:~/sbx/walle_code_execution/codeexe/aspire/bin2vm/LLVM-3.6.0/llvm.src/lib/Transforms/OperandCounter$ opt -load ../../../Release+Asserts/lib/LLVMopCounter.so -opCounter < test.bc >/dev/null

Function Name: main

 ##########Works fine till here!

0  libLLVM-3.4.so.1 0x00007f9bfecea5d2 llvm::sys::PrintStackTrace(_IO_FILE*) + 34
1  libLLVM-3.4.so.1 0x00007f9bfecea3c4
2  libc.so.6        0x00007f9bfd769ff0
3  LLVMopCounter.so 0x00007f9bfc7730a4
4  libLLVM-3.4.so.1 0x00007f9bfe6baf77 llvm::FPPassManager::runOnFunction(llvm::Function&) + 471
5  libLLVM-3.4.so.1 0x00007f9bfe6baffb llvm::FPPassManager::runOnModule(llvm::Module&) + 43
6  libLLVM-3.4.so.1 0x00007f9bfe6bd4b5 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 693
7  opt              0x0000000000412c8d main + 2461
8  libc.so.6        0x00007f9bfd754ec5 __libc_start_main + 245
9  opt              0x0000000000413b40
Stack dump:
0.      Program arguments: opt -load ../../../Release+Asserts/lib/LLVMopCounter.so -opCounter 
1.      Running pass 'Function Pass Manager' on module '<stdin>'.
2.      Running pass 'Counts the OpCodes in a single Function' on function '@main'

Segmentation fault (core dumped)

最佳答案

答案是:我在 clang 中使用了不兼容的 LLVM 库。当我使用 LLVMlib 3.4 开发 Clang 3.5 时。将两者提升到相同水平后,现在所有通行证都可以正常工作。 删除旧的 llvm 库并从 llvm.org 添加新的 3.5 版本

关于c++ - llvm 通过段错误 :(Core dumped),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29558839/

有关c++ - llvm 通过段错误 :(Core dumped)的更多相关文章

  1. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  2. ruby - 通过 rvm 升级 ruby​​gems 的问题 - 2

    尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub

  3. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  4. ruby - 通过 erb 模板输出 ruby​​ 数组 - 2

    我正在使用puppet为ruby​​程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby​​不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这

  5. ruby - 通过 ruby​​ 进程共享变量 - 2

    我正在编写一个gem,我必须在其中fork两个启动两个webrick服务器的进程。我想通过基类的类方法启动这个服务器,因为应该只有这两个服务器在运行,而不是多个。在运行时,我想调用这两个服务器上的一些方法来更改变量。我的问题是,我无法通过基类的类方法访问fork的实例变量。此外,我不能在我的基类中使用线程,因为在幕后我正在使用另一个不是线程安全的库。所以我必须将每个服务器派生到它自己的进程。我用类变量试过了,比如@@server。但是当我试图通过基类访问这个变量时,它是nil。我读到在Ruby中不可能在分支之间共享类变量,对吗?那么,还有其他解决办法吗?我考虑过使用单例,但我不确定这是

  6. ruby - 通过 RVM (OSX Mountain Lion) 安装 Ruby 2.0.0-p247 时遇到问题 - 2

    我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search

  7. ruby-on-rails - Enumerator.new 如何处理已通过的 block ? - 2

    我在理解Enumerator.new方法的工作原理时遇到了一些困难。假设文档中的示例:fib=Enumerator.newdo|y|a=b=1loopdoy[1,1,2,3,5,8,13,21,34,55]循环中断条件在哪里,它如何知道循环应该迭代多少次(因为它没有任何明确的中断条件并且看起来像无限循环)? 最佳答案 Enumerator使用Fibers在内部。您的示例等效于:require'fiber'fiber=Fiber.newdoa=b=1loopdoFiber.yieldaa,b=b,a+bendend10.times.m

  8. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  9. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  10. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

随机推荐