[cfe-dev] Scrape Decls from Include Header/Directory

Trevor Black via cfe-dev cfe-dev at lists.llvm.org
Mon May 13 11:58:12 PDT 2019


I have a project with a number of large constraints, and am uncertain of
the optimal means of completion.

Sorry if this question is answered elsewhere on the forum, I couldn't find
specifically what I was looking for.



Project Abstract:

Arbitrary code injection on a specified library using clang and
DYLD_INSERT_LIBRARIES (LD_PRELOAD)



Project In English:

With the primary operating system being MacOS, I want to be able to point
at the include header or include directory for a library of interest
(Metal, OpenGL, OpenCL, Vulkan, DX). Clang will parse through and collect
all class and function decls (and any necessary typedefs and enums) and
spit out a YAML of all functions. The user would then specify what code to
be injected for which functions. Later, during runtime runtime for an
application that uses that library, apply dynamic library injection to shim
those function calls and execute the user's arbitrary code. This project
can be thought of as a very lightweight general shim. The primary
application is performance capture for graphics applications.



Constraints

1. Installing LLVM or clang with "make" is not an option, more
specifically, nothing can be copied to /usr and no aliases or links can be
made. Only libraries and tools included with Xcode are viable.

2. The arbitrary code will always be c++, but the library includes can be
any of the clang family languages (c, c++, obj-c, ...).

3. Xcode is only expected on Mac, but this must work on all the three
primary OSes (Win, Mac, Linux). i.e. the subset of clang on Win, Linux, and
constraint #1.

4. The person doing arbitrary code execution should be allowed as limited
an understanding of clang and LLVM as possible, ideally nothing (they are
expected to understand the consequence of code injection).



Effectively I want one large AST where there are no incomplete types, and
everything is packaged as one.

I would then parse through this AST scraping all Decls.

The YAML and code execution stuff has already been completed. This project
is a generalization of an existing project that is specific to one graphics
API.



So my questions:

1. Is there any way to get Libtooling to work with the native Xcode (w/o
violating constraint #1)?

2. For the Metal API there is a single header file Metal.h that an
application would #include in its source. This Metal.h file #import(s) all
of the other metal header files. Is there any way to run libclang in a
manner similar to "-fsyntax-only" where the preprocessor is run and those
other metal files are included in the AST?

3. If question #2 is a no, is there any one to use the preprocessor for
includes and imports with libclang? I can't seem to get the AST of
#imported files?

4. If libtooling is a no, and libclang is a no, would it be a mistake to
just string parse over the "-ast-dump" output? Cause that's my backup.



Thank you,

Trevor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190513/39a97a9b/attachment.html>


More information about the cfe-dev mailing list