Handle empty LLVMModule in GetFunction #5146
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#4847 introduces empty
LLVMModule
, which may appear when all the executable code are optimized #4748 . An emptyLLVMModule
is built from an IR file that only specifies target triplet and data layout.We just notice that existing logic in
LLVMModuleNode
may not consider this case properly. As shown by @trevor-m in this comment,LLVMModuleNode::GetFunction
doesn't work properly.We dived into this problem and found out that
LLVMModuleNode
always assumes there exists an entry function (see this line). If there is not, e.g., in an emptyLLVMModule
, we would have trouble, mostly in the form of segfault.This PR mainly deals with the empty
LLVMModule
issue inLLVMModuleNode::GetFunction
. We assume that, without losing generality, aLLVMModule
is empty if itsentry_func_
cannot be found, i.e.:GetGlobalAddr(runtime::symbol::tvm_module_main) == 0
We use this assumption as follows:
LazyInitJIT
is called byGetFunction
, we will validate the address ofentry_func_
(by the condition above) first before we refer to it.entry_func_
is empty, we can realize the currentLLVMModule
is empty and we should returnnullptr
.Please let me know whether this help address your problem @trevor-m