6

I'm trying to write a program that lists all of the publicly exported variables and functions of a C or C++ program by using Clang.

I followed part 05 of this tutorial, but it doesn't work for current version of clang. Above that, I got some hints that CompilerInstance can make the code shorter, but I'm not entirely sure how to use it.

How would you implement this functionality? Can you give me any pointers into the right direction? For example: is there a large hash table of globally declared variables or do I have to traverse the AST?

1

2 Answers 2

2

publicly exported - do you mean symbols with external linkage?

You can use nm on object files, shared libraries and executables with --extern-only --defined-only --demangle options to display defined symbols with external linkage. Symbol type field tells you what kind of symbol it is, global variables normally have types B, b, C, D, d, G, g, R, r, S, s and W, w for static data members of templates declared in header files and function-scope statics.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that is indeed the case. But I'd like to have the list of symbols straight from the source code so I can tamper with them.
0

I've found a way. The result is AutoFFI, an FFI bindings generator built on top of Clang. I'll post the details on how it is done if I have the time.

1 Comment

seems this project no longer exists?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.