Error in Object File Generation from Legacy Pass Manager

Hello,

I am trying out the Object File Generation Tutorial in Kaleidoscope, for the IR I have generated through CodeGenerator. The compilation is successful and the Obj file of the Compiler project is successfully built, but when I execute the Obj file of my project it is giving me a segmentation fault, I debugged my code for possible errors and found that when I comment out the line

pass.run(*module);

to the LegacyPassManager it doesn’t give me a segmentation fault error. I could not figure what the issue is with this call? I have created Passes for generating Obj file for generated IR using the call to TargetMachine

TargetMachine->addPassesToEmitFile(pass,dest,nullptr,FileType);

Regards
Jagrat Patkar