I am looking at a llvm ir file converted from a cpp file by clang. But I found there were several functions in llvm ir file only with declaration without definition. And all these functions are not the "build-in" functions like:
declare i32 @puts(i8* nocapture)
It's like:
declare void @_ZNK5Arrow7BaseRow9getColumnINS_11IpGenPrefixEEEvtRT_(%"class.Arrow::BaseRow"*, i16 zeroext, %"class.Arrow::IpGenPrefix"* dereferenceable(24)) #0
It seems like those functions are using some external definition? I am new to LLVM IR. And I was wondering is there a way that LLVM IR can do like cpp library, I can store the functions I will use in some LLVM IR libraries and use them in a .ll file by just do something like include ?
Thanks
Exactly.
declarekeyword indicates a function declaration, as opposed to function definition, and function declarations can only be linked externally:The reason Clang generated declarations instead of definitions is (most likely) that these functions were not defined in the translation unit that was given to it.
The declarations are resolved during linking. To link several LLVM modules together, use llvm-link tool.
For example, suppose
lib.cppdefines functionfoo()which is used inmain.cpp.This command compiles these files to LLVM IR and creates two modules
main.bcandlib.bc.main.bccontains just a declaration offoo()because this function is defined in a separate translation unit. The definition offoo()is inlib.bc.This command links
main.bcandlib.bcinto a single module, which now contains the definition offoo().