rdaly525 / linker

Repo for the coreir linker paper
0 stars 0 forks source link

Segfault in popcount example if I don't run printer pass #7

Closed leonardt closed 6 years ago

leonardt commented 6 years ago

If I take out the printer pass:

diff --git a/experiment/cpp_magma_popcount/create_popcount.cpp b/experiment/cpp_magma_popcount/create_popcount.cpp
index b5c742a..0953d9f 100644
--- a/experiment/cpp_magma_popcount/create_popcount.cpp
+++ b/experiment/cpp_magma_popcount/create_popcount.cpp
@@ -30,7 +30,7 @@ int main() {
   top->setDef(def);
   c->setTop(top);
-  c->runPasses({"rungenerators", "cullgraph", "printer"});
+  c->runPasses({"rungenerators", "cullgraph"});
   if (!saveToFile(c,"popcount.json")) {
     cout << "Save to file Failed!!!";
     exit(1);

I'll get an occasional segfault:

❯ PYTHONPATH=. make
./create_popcount
Generator: PopCount
    Params: (width:Int)
    TypeGen: TODO
    Def? No
Generator: PopCount
    Params: (width:Int)
    TypeGen: TODO
    Def? Yes
hasdef:1
In Run Generators
Running magma generator
Done running generators
make: *** [counters.json] Segmentation fault: 11

If I run it in lldb, i get the following output

❯ PYTHONPATH=. lldb -- ./create_popcount
(lldb) target create "./create_popcount"
Current executable set to './create_popcount' (x86_64).
(lldb) r
Process 26632 launched: './create_popcount' (x86_64)
Generator: PopCount
    Params: (width:Int)
    TypeGen: TODO
    Def? No
Generator: PopCount
    Params: (width:Int)
    TypeGen: TODO
    Def? Yes
hasdef:1
In Run Generators
Running magma generator

Done running generators
Process 26632 exited with status = 0 (0x00000000)
(lldb) r
Process 26637 launched: './create_popcount' (x86_64)
Generator: PopCount
    Params: (width:Int)
    TypeGen: TODO
    Def? No
Generator: PopCount
    Params: (width:Int)
    TypeGen: TODO
    Def? Yes
hasdef:1
In Run Generators
Running magma generator

Done running generators
Process 26637 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x000000010029de3c libcoreir.dylib`CoreIR::GlobalValue::getRefName() const + 28
libcoreir.dylib`CoreIR::GlobalValue::getRefName:
->  0x10029de3c <+28>: movq   0x20(%rsi), %rcx
    0x10029de40 <+32>: movq   %rdi, -0x170(%rbp)
    0x10029de47 <+39>: movq   %rcx, %rdi
    0x10029de4a <+42>: movq   %rax, -0x178(%rbp)
Target 0: (create_popcount) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x000000010029de3c libcoreir.dylib`CoreIR::GlobalValue::getRefName() const + 28
    frame #1: 0x00000001003c3fa4 libcoreir.dylib`(anonymous namespace)::Instances2Json(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, CoreIR::Instance*, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, CoreIR::Instance*> > >&, int) + 1220
    frame #2: 0x00000001003bb8c5 libcoreir.dylib`(anonymous namespace)::Module2Json(CoreIR::Module*, int) + 7685
    frame #3: 0x00000001003be564 libcoreir.dylib`(anonymous namespace)::Generator2Json(CoreIR::Generator*) + 2740
    frame #4: 0x00000001003b6898 libcoreir.dylib`CoreIR::Passes::CoreIRJson::runOnNamespace(CoreIR::Namespace*) + 3080
    frame #5: 0x0000000100326217 libcoreir.dylib`CoreIR::PassManager::runNamespacePass(CoreIR::Pass*) + 439
    frame #6: 0x0000000100328e9a libcoreir.dylib`CoreIR::PassManager::runPass(CoreIR::Pass*) + 378
    frame #7: 0x000000010032c3c6 libcoreir.dylib`CoreIR::PassManager::run(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >) + 5190
    frame #8: 0x0000000100149a16 libcoreir.dylib`CoreIR::Context::runPassesOnAll(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >) + 1974
    frame #9: 0x0000000100274e34 libcoreir.dylib`CoreIR::saveToFile(CoreIR::Context*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) + 2820
    frame #10: 0x000000010001912b create_popcount`main + 7467
    frame #11: 0x00007fff504ec015 libdyld.dylib`start + 1
    frame #12: 0x00007fff504ec015 libdyld.dylib`start + 1
(lldb)
leonardt commented 6 years ago

Here is the output of the printer pass

{"top":"global.top",
"namespaces":{
  "global":{
    "modules":{
      "Op":{
        "type":["Record",[
          ["I0","BitIn"],
          ["I1","BitIn"],
          ["I2","BitIn"],
          ["O","Bit"]
        ]],
        "instances":{
          "inst0":{
            "modref":"global.and_wrapped"
          },
          "inst1":{
            "modref":"global.and_wrapped"
          },
          "inst2":{
            "modref":"global.and_wrapped"
          },
          "inst3":{
            "modref":"global.Or3xNone"
          }
        },
        "connections":[
          ["self.I0","inst0.I0"],
          ["self.I1","inst0.I1"],
          ["inst3.I0","inst0.O"],
          ["self.I1","inst1.I0"],
          ["self.I2","inst1.I1"],
          ["inst3.I1","inst1.O"],
          ["self.I2","inst2.I0"],
          ["self.I0","inst2.I1"],
          ["inst3.I2","inst2.O"],
          ["self.O","inst3.O"]
        ]
      },
      "Or3xNone":{
        "type":["Record",[
          ["I0","BitIn"],
          ["I1","BitIn"],
          ["I2","BitIn"],
          ["O","Bit"]
        ]],
        "instances":{
          "inst0":{
            "genref":"coreir.orr",
            "genargs":{"width":["Int",3]}
          }
        },
        "connections":[
          ["self.I0","inst0.in.0"],
          ["self.I1","inst0.in.1"],
          ["self.I2","inst0.in.2"],
          ["self.O","inst0.out"]
        ]
      },
      "and_wrapped":{
        "type":["Record",[
          ["I0","BitIn"],
          ["I1","BitIn"],
          ["O","Bit"]
        ]],
        "instances":{
          "inst0":{
            "modref":"corebit.and"
          }
        },
        "connections":[
          ["self.I0","inst0.in0"],
          ["self.I1","inst0.in1"],
          ["self.O","inst0.out"]
        ]
      },
      "fold_xor3None":{
        "type":["Record",[
          ["I0","BitIn"],
          ["I1","BitIn"],
          ["I2","BitIn"],
          ["O","Bit"]
        ]],
        "instances":{
          "inst0":{
            "modref":"global.xor_wrapped"
          },
          "inst1":{
            "modref":"global.xor_wrapped"
          }
        },
        "connections":[
          ["self.I0","inst0.I0"],
          ["self.I1","inst0.I1"],
          ["inst1.I0","inst0.O"],
          ["self.I2","inst1.I1"],
          ["self.O","inst1.O"]
        ]
      },
      "top":{
        "type":["Record",[
          ["I",["Array",16,"BitIn"]],
          ["O",["Array",5,"Bit"]]
        ]],
        "instances":{
          "popcount16":{
            "genref":"rosslib.PopCount",
            "genargs":{"width":["Int",16]}
          }
        },
        "connections":[
          ["self.I","popcount16.I"],
          ["self.O","popcount16.O"]
        ]
      },
      "xor_wrapped":{
        "type":["Record",[
          ["I0","BitIn"],
          ["I1","BitIn"],
          ["O","Bit"]
        ]],
        "instances":{
          "inst0":{
            "modref":"corebit.xor"
          }
        },
        "connections":[
          ["self.I0","inst0.in0"],
          ["self.I1","inst0.in1"],
          ["self.O","inst0.out"]
        ]
      }
    }
  }
}
}
rdaly525 commented 6 years ago

Fixed by removing cullgraph