Closed connorkuehl closed 5 years ago
I found this in the Compiler Internals Manual. I haven't found an appropriate analog from the context of the Clang Plugin API.
So we already have randstruct registered randstruct with the FrontendPluginRegistry, so we can call our plugin from command line via -plugin randstruct, is that correct?
So at this point what we need is a way for the plugin to be called from structs declared with a calling component, and attributes won't work because we're not going to modify the attr.td file (which is a route we would go if we were not doing a plugin).
Currently looking at other plugins to see how they manage this, nothing so far though.
@jeffreytakahashi any progress on this?
This is a lead from March 2017 that makes me believe we cannot add custom attributes without directly editing Clang. http://clang-developers.42468.n3.nabble.com/User-defined-attributes-in-clang-plugins-td4055940.html
This is a blog post that (kind of?) outlines using the clang attribute "annotate", to create a custom annotation that we can pull off at the "bitcode level": https://blog.quarkslab.com/implementing-a-custom-directive-handler-in-clang.html - I want to speak with ya'll about this tomorrow, because I don't have enough contextual knowledge to understand if we can use this.
Official docs for the llvm "intrinsic" leveraged by the blog post. I dont feel like it provided me with much information, but maybe someone can connect the dots? - http://llvm.org/docs/LangRef.html#llvm-var-annotation-intrinsic
@tim-pugh See above post from Cole, we're really struggling with this.
My idea of an alternative wouldn't fix anything (it would make it more complicated actually). It would be adding a keyword to clang which they state can be more error prone.
https://clang.llvm.org/docs/ClangPlugins.html
in here you can read a section talking about "pragmas". I'm really not sure if using this would be the correct approach, but it talks about registering them with the clang compiler via a plugin.
So after a lot of reading and a bit of poking we can add annotations to both variables and functions such that they show up in llvm metadata, however they do not when assigned to structs. In either case, if we are reading this correctly (and we would really like someone to verify that we are). I will post screenshots soon, and we will get some links up soon, but it appears that even using attribute((packed)) does not show up in the bytecode so we're not sure if it's just there in a way we cannot see.
Found a half-baked explanation for parsing the metadata: https://stackoverflow.com/questions/15114284/llvm-get-annotations
Now discussing possibly attempting to actually get the attributes we needed upstreamed.
Here is an example of an attribute in clang that applies to struct/class/union as a starting point:
https://github.com/llvm-mirror/clang/search?q=empty_bases&unscoped_q=empty_bases https://clang.llvm.org/docs/AttributeReference.html#empty-bases
Per some other reading, boilerplate might be relevant to future research in order to implement this properly: https://clang.llvm.org/docs/InternalsManual.html#boilerplate
Once we have our attributes based on the research and discussion here, there are separate issues for integrating them into the plugin with their corresponding behaviors. #98 #97
Looks like they've updated their Getting Started page with instructions for working with their official git repo due to their migration! Yay! :confetti_ball:
Once our fork of Clang has the required attributes we need, let's prepare the patch and disseminate it to the team so that we can implement manual structure selection as part of our MVP ASAP.
https://llvm.org/docs/GettingStarted.html#sending-patches
We'll also then be able to prepare the e-mail for the mailing list, get Bart's sign off, then send it off to the clang commits mailing list.
I've fired off a email to the sponsor letting him know the game plan. You can find the email in the google team drive.
This guide may be beneficial to read as well:
https://llvm.org/docs/DeveloperPolicy.html
I have the contact at Intel I can reach out to once more which I suggest we do. He may be able to shed some light on the process and help guide us.
We've got the instructions to build LLVM (Linux based systems) here:
https://docs.google.com/document/d/1uJjruksHppqdo3GA2fv3OsyIJpXW_hALRvKC-2oWXSo/edit
We've attempted to add the attribute, but working on this yesterday the build failed.
Connor mentioned sending a patch out. In the meantime I'll help people get things setup on their machines.
I suspect there is a repo waiting for us to commit to, but will need to discuss this with other team members. This will likely be the method we go to receive the patch, after some git fu changing the origin.
Closed by the following commits:
3b9829ee86f311ab232f8cbb49cf5b5e7fcd70ef f8da259829202a755af6c788d24fd049c3e65950
How do we add support for things like
__randomize_layout
and__no_randomize_layout
?