[cfe-dev] Adding custom attributes/metadata to functions and globals

Félix Cloutier via cfe-dev cfe-dev at lists.llvm.org
Sat Oct 29 11:23:08 PDT 2016


Hello all,

I'm working on a project that parses C headers with the Clang static libraries for binary program analysis purposes. I consume the AST and do not rely on codegen.

I would love to be able to add some additional metadata to functions: specifically, the expected address of the function in the binary program. For instance:

int foo(int bar) __attribute__((address(0xdeadbeef)));

Attributes are especially convenient because they are easy to embed in a macro, which could end up looking like:

int foo(int bar) ADDRESS(0xdeadbeef);

Since this is an open-source project maintained by me only, I would prefer to not fork Clang, and just allow people to build my program with their distributions' stock Clang packages. Sadly, this apparently means that I can't use attributes for this purpose, because the valid attribute list appears to be hard-coded into Clang, and there doesn't seem to be any attribute that I can co-opt for this purpose.

Are there extension points that I can leverage in the Clang static libraries to allow this?

Félix

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


More information about the cfe-dev mailing list