[cfe-dev] [PATCH/DRAFT] Embed metadata into object file
Adrian Prantl via cfe-dev
cfe-dev at lists.llvm.org
Wed Mar 30 13:26:24 PDT 2016
> On Mar 30, 2016, at 6:47 AM, Christian Dietrich via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>
> Hi,
>
> so this is my first contribution to LLVM/clang, so I hope I come close
> to the required coding standards and guidelines.
>
> First, I will describe the scenario I want to solve: For a few days, the
> clang plugin interface allows to execute the a plugin just before the
> actual main action (e.g., compiling an translation unit). In my case,
> the plugin we're developing will analyze the AST and generate some
> information. This information should be available in the generated
> object file. So, I had to solve the question: how do I smuggle some
> metadata on the module level, from the frontend to the generated object
> file (in an hopefully sane and reusable manner).
>
> So, the solution I thought about was the following. The gathered
> information is but into a NamedMetadataStringAttr and attached to the
> TranslationUnitDecl. This would be, as far as I can see, the first
> annotation on the TranslationUnit level. Attributes seem to me the best
> solution at that point, since there is already a good infrastructure in
> clang.
>
> TranslationUnitDecl
> | NamedMetadataAttr implicit llvm.extra_section clang.analysis "Information"
>
> The clang CodeGen then generates a named metadata node on the
> llvm::Module level:
>
> !llvm.extra_sections = {!0}
> !0 = !{!"clang.analysis", !"Information"}
>
> The attached patch, then takes all key-value pairs from the named
> llvm.extra_sections named metadata, and appends them as zero-terminated
> strings to the desired section.
Depending on your needs, just using a global with the “section” attribute might also work for you:
http://llvm.org/docs/LangRef.html#global-variables
-- adrian
>
> I'm not sure, wheter this is the best solution to the problem, and
> wheter it is general enough. I was also thinking about the possibility
> to attach LLVM passes from the plugin interface to the clang/CodeGen
> backend, but I could not figure out how to do this without breaking all
> the used abstraction.
>
> I post this to llvm-dev, as well as, to cfe-dev, since both changes,
> although idependend of each other, relate to one another.
>
> chris
> --
> Christian Dietrich, M.Sc. (Wissenschaftlicher Mitarbeiter)
> Lehrstuhl für Informatik 4 (Verteilte Systeme und Betriebssysteme)
> Friedrich-Alexander-Universität Erlangen-Nürnberg
> Martensstr. 1
> 91058 Erlangen
>
> Tel: (09131) 85-27280
> Fax: (09131) 85-28732
> eMail: christian.dietrich at fau.de
> WWW: http://www4.cs.fau.de/~dietrich
> <0001-Attach-LLVM-metadata-with-NamedMetadataStringAttr.patch><0001-Use-llvm.extra_section-to-smuggle-data-into-object-s.patch>_______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list