Like many other C/C++ compilers, LLVM also needs to inform the linker (ld, lld, etc.) how to merge global values (global variables, functions) of different modules (one module in LLVM corresponds to one object file or one translation unit for linker) at link-time. In LLVM, global values can be divided into 10 categories according to their linkage types. The linker will treat each type of global values differently based on their linkage types. Not considering the linkage types of global values when writing a LLVM Pass may result in unexpected behaviors, especially when you are manipulating the global variables by a Module Pass. In this post, I will demystify the 10 linkage types in LLVM to help you write more robust LLVM Passes.

Read more »