[LLVMdev] addPassesToEmitFile

Álvaro Castro Castilla alvaro.castro.castilla at gmail.com
Sun Mar 8 15:16:46 PDT 2009


Well, I've been before hours trying this, but soon after I sent the
email I found something. However is quite intriguing.
I just changed the order of and the static libraries that I was linking.

How can this be possible??

I'm using Cmake for building my llvm projects, so I choose the order
and I pick the .a libraries I want to link by hand...

Thank you,

alvaro




2009/3/8 Álvaro Castro Castilla <alvaro.castro.castilla at gmail.com>:
> Hi,
>
>
> Long time ago (llvm-svn june 2008) I asked here about a way to output
> the assembly code of my JIT generated code to a string, so I could use
> it to read it on the screen. I came up with this solution:
>
>    std::string Err;
>    const llvm::TargetMachineRegistry::entry* _arch =
> llvm::TargetMachineRegistry::getClosestTargetForJIT(Err);
>
>    std::string FeaturesStr;
>    llvm::TargetMachine* target(_arch->CtorFn(*_module, FeaturesStr));
>    assert(target && "Could not allocate target machine!");
>
>    std::ostringstream os;
>
>    target->addPassesToEmitFile(*_passManager, os,
> llvm::TargetMachine::AssemblyFile, true);
>    target->addPassesToEmitFileFinish(*_passManager, 0, true);
>
>
>
> However, in newer versions of llvm, like 2.5 that I'm testing now, I
> had to change the code to something like this:
>
>
>    std::string Err;
>    const llvm::TargetMachineRegistry::entry* _arch =
> llvm::TargetMachineRegistry::getClosestTargetForJIT(Err);
>
>    std::string FeaturesStr;
>    std::auto_ptr<llvm::TargetMachine> target(_arch->CtorFn(*_module,
> FeaturesStr));
>
>    std::ostringstream os;
>    llvm::raw_ostream *Out = new llvm::raw_os_ostream(os);
>    target->addPassesToEmitFile(*_passManager, *Out,
> llvm::TargetMachine::AssemblyFile, true);
>    target->addPassesToEmitFileFinish(*_passManager, 0, true);
>
>
>
> Both versions were based on the code from llc of its release.
> Everything compiles perfectly in both versions. However, when the
>
> _passManager->run(*_module);
>
> is called, I get a Segmentation fault that I'm unable to figure out,
> as I can't track it with gdb. The first version was working perfectly.
>
>
> I would really appreciate if someone could give me a clue of what I'm
> doing wrong...
>
> Thank you,
>
>
> Bests,
>



-- 
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> http://www.alvarocastro.es




More information about the llvm-dev mailing list