Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

llvm

llvm-ir

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.)

like image 865
codeman48 Avatar asked Nov 17 '17 11:11

codeman48


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.

like image 70
Trass3r Avatar answered Sep 25 '22 09:09

Trass3r