Understanding the different linkage types of global values in LLVM IR with examples

Viewed 1060

The LLVM IR doc discusses the IR in detail, much of which is clear. However, I get particularly confused with the Linkage Types. The linkage types apart from private, internal, external become quite confusing without an example.

Can someone throw some light here? (Probably relating the use-cases with a language like C/C++?)

(I am trying to understand the IR clearly, since I am building analyzers for the LLVM modules.)

1 Answers

LLVM's linkage definition is complicated as it must be able to represent notions from different programming languages, systems, object file formats etc.

The only definitive reference is the code. In particular look at how clang translates from C++ standard linkage to its own codegen linkage in ASTContext::GetGVALinkageForFunction and from there into llvm's in CodeGenModule::getLLVMLinkageForDeclarator.

And then there's of course some code (haven't found it yet) translating LLVM linkage into an object file equivalent like COMDATs or weak symbols using e.g. GlobalValue::isWeakForLinker

The appending linkage is a very special low-level one used for constructing arrays of pointers to global constructors for example.

Related