You should be able to get this information through an AST MatchFinder. A simple matcher like
namedDecl().bind("named_decl")
will match all NamedDecl
nodes. Then in the callback, you can get the node's Linkage attribute, and process the node accordingly. A callback that printed out which symbols have external linkage might look something like this:
struct LinkagePrinter : public MatchFinder::Callback {
void run(MatchResult const & result) override {
using namespace clang;
NamedDecl const * n_decl =
result.Nodes.getNodeAs<NamedDecl("named_decl");
if(n_decl){
Linkage l = n_decl->getLinkage();
switch(l){
case ExternalLinkage:
std::cout << "symbol " << n_decl->getNameAsString()
<< " has external linkage\n";
// ... etc
}
}
return;
}
}; // LinkagePrinter
This is roughly right--I haven't checked that this compiles. Register the matcher and callback with a MatchFinder, load the MatchFinder into a Tool, and you should be in business. There are lots of examples in https://github.com/lanl/CoARCT .