<div dir="ltr">Hi, I want to check the return address of function.<div><div>I use the following code to build pass. </div></div><div>"</div><div>    FunctionType *func_type = FunctionType::get(ty_ptr, false);           <br>    Function *func = Function::Create(func_type, GlobalValue::ExternalLinkage, "<b>llvm.addressofreturnaddress</b>", F->getParent()); <br>    IRBuilder<> Builder(inst);<br>    Builder.CreateCall(func);<br></div><div>"</div><div>When I compiled it, the following error message appeared:<br></div><div>"</div><div>   Intrinsic name not mangled correctly for type arguments! Should be: llvm.addressofreturnaddress.p0i8<br></div>   i8* ()* @llvm.addressofreturnaddress<div>"</div><div>So I made the following modification:<br></div><div>"</div><div>    FunctionType *func_type = FunctionType::get(ty_ptr, false);           </div>    Function *func = Function::Create(func_type, GlobalValue::ExternalLinkage, "l<b>lvm.addressofreturnaddress.p0i8</b>", F->getParent()); <br>    IRBuilder<> Builder(inst);<br>    Builder.CreateCall(func);<div>"</div><div>Compile through, I get the compiled so file.<br></div><div>However, the following error occurred when I used it to optimize my code:</div><div><div>"</div><div>    Intrinsic name not mangled correctly for type arguments! Should be: llvm.addressofreturnaddress.p0i8<br>    i8* ()*<b> @llvm.addressofreturnaddress.p0i8.1</b> in function main<br></div><div>"</div></div><div><font color="#666666" face="Arial, Microsoft YaHei, \\5FAE软雅黑, \\5B8B体, Malgun Gothic, Meiryo, sans-serif"><span style="font-size:14px">I can't fix it. What should I do?</span></font></div><div><font color="#666666" face="Arial, Microsoft YaHei, \\5FAE软雅黑, \\5B8B体, Malgun Gothic, Meiryo, sans-serif"><span style="font-size:14px"><br></span></font></div><div>Then, I tried another way.<br></div><div>"</div><div> CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID,<br>751  ArrayRef<Type *> Types,<br>752  ArrayRef<Value *> Args,<br>753  Instruction *FMFSource,<br>754  const Twine &Name) {<br>755  Module *M = BB->getModule();<br>756  Function *Fn = Intrinsic::getDeclaration(M, ID, Types);<br>757  return createCallHelper(Fn, Args, this, Name, FMFSource);<br>758 }<br></div>"<div>I use the following code.</div><div>"</div><div>    Function *Fn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::addressofreturnaddress);<br></div><div>"</div><div>But,</div><div>"</div><div>Stack dump:<br>0. Program arguments: opt -load ../build/lib/LLVMMyPass.so -hello <br>1. Running pass 'Function Pass Manager' on module '<stdin>'.<br>2. Running pass 'Hello World Pass' on function '@_Z4vulnv'<br> #0 0x0000563d2d976bba llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/opt/llvm/bin/opt+0x2458bba)<br> #1 0x0000563d2d974954 llvm::sys::RunSignalHandlers() (/opt/llvm/bin/opt+0x2456954)<br> #2 0x0000563d2d974a92 SignalHandler(int) (/opt/llvm/bin/opt+0x2456a92)<br> #3 0x00007fce4a662890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)<br> #4 0x0000563d2d238bd4 DecodeFixedType(llvm::ArrayRef<llvm::Intrinsic::IITDescriptor>&, llvm::ArrayRef<llvm::Type*>, llvm::LLVMContext&) (/opt/llvm/bin/opt+0x1d1abd4)<br> #5 0x0000563d2d23b576 llvm::Intrinsic::getType(llvm::LLVMContext&, llvm::Intrinsic::ID, llvm::ArrayRef<llvm::Type*>) (/opt/llvm/bin/opt+0x1d1d576)<br> #6 0x0000563d2d240ab5 llvm::Intrinsic::getDeclaration(llvm::Module*, llvm::Intrinsic::ID, llvm::ArrayRef<llvm::Type*>) (/opt/llvm/bin/opt+0x1d22ab5)<br> #7 0x00007fce492f095a (anonymous namespace)::Hello::runOnFunction(llvm::Function&) (../build/lib/LLVMMyPass.so+0x195a)<br> #8 0x0000563d2d27db08 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/llvm/bin/opt+0x1d5fb08)<br> #9 0x0000563d2d27e1f1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/llvm/bin/opt+0x1d601f1)<br>#10 0x0000563d2d27ce61 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/llvm/bin/opt+0x1d5ee61)<br>#11 0x0000563d2bc5c193 main (/opt/llvm/bin/opt+0x73e193)<br>#12 0x00007fce49513b97 __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0<br>#13 0x0000563d2bce06ba _start (/opt/llvm/bin/opt+0x7c26ba)<br>Segmentation fault (core dumped)<br></div><div>"</div><div>I can't understand it.</div><div>I tried to use "returnaddress" to replace "addressofreturnaddress". It's OK!</div><div>They are all Intrinsic function. Why?</div><div><br></div><div>Plese help me out. </div><div>Thanks.</div></div>