[cfe-dev] output metadata for extern declared functions?

Lewis Burns lewisurn at gmail.com
Sat Nov 16 21:27:06 PST 2013


On 11/16/2013 06:48 PM, David Blaikie wrote:
>
>
>
> On Sat, Nov 16, 2013 at 12:30 PM, Lewis Burns <lewisurn at gmail.com 
> <mailto:lewisurn at gmail.com>> wrote:
>
>     I've finally figured out where a function declaration is lazily
>     emitted. It is done in the
>     CodeGenModule::GetOrCreateLLVMFunction() function, which is in
>     turned called by EmitCall functions. I wrote a function which is
>     similar to the CGDebugInfo::EmitFunctionStart() function and
>     hooked it into the GetOrCreateLLVMFunction function. It seems to
>     work, since it passed all LLVM & Clang regression tests except two.
>
>     I'm now having two other questions.
>
>     (1) How to add a Clang command line option to control the call to
>     my function? The hook-up point in my code is as follows:
>
>     llvm::Constant *
>     CodeGenModule::GetOrCreateLLVMFunction(StringRef MangledName,
>                                            llvm::Type *Ty,
>                                            GlobalDecl D, bool ForVTable,
>     llvm::AttributeSet ExtraAttrs) {
>       ...
>       llvm::Function *F = llvm::Function::Create(FTy,
>     llvm::Function::ExternalLinkage,
>     MangledName, &getModule());
>       ...
>       if (ExtraAttrs.hasAttributes(llvm::AttributeSet::FunctionIndex)) {
>         llvm::AttrBuilder B(ExtraAttrs,
>     llvm::AttributeSet::FunctionIndex);
>     F->addAttributes(llvm::AttributeSet::FunctionIndex,
>     llvm::AttributeSet::get(VMContext,
>     llvm::AttributeSet::FunctionIndex,
>                                                  B));
>       }
>
>       // Emit subprogram debug descriptor for this new declaration
>       // if "-gg" is given like clang -gg, then call this function
>       EmitFunctionDeclaration(D, F); -- hook up line
>
>       // This is the first use or definition of a mangled name.  If
>     there is a
>       // deferred decl with this name, remember that we need to emit
>     it at the end
>       // of the file.
>       llvm::StringMap<GlobalDecl>::iterator DDI =
>     DeferredDecls.find(MangledName);
>       ...
>     }
>
>     It seems to be very complicated to do this in Clang. I've spent
>     hours and still couldn't solve it.
>
>
> Have you looked at how other command line arguments are handled in Clang?
Sure, I've followed other flags and examples, especially one from here: 
http://permalink.gmane.org/gmane.comp.compilers.clang.devel/27289. 
However, it worked finally when I changed -gg to some other value, say 
-declaration-descriptor. Clang doesn't want to other people to use "-gg." :(


-- 
Lewis

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131116/fd3fa049/attachment.html>


More information about the cfe-dev mailing list