<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/193340>193340</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLGO] Build fails with modern TensorFlow due to unlinked constant/metadata object files
</td>
</tr>
<tr>
<th>Labels</th>
<td>
cmake,
mlgo
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nickdesaulniers
</td>
</tr>
</table>
<pre>
When building LLVM with MLGO enabled (-DTENSORFLOW_AOT_PATH=...) using a recent version of TensorFlow, the build fails during the final link step with undefined symbol errors related to constant buffers.
Newer versions of TensorFlow's AOT compiler (saved_model_cli / tfcompile) generate multiple object files to separate code, metadata, and constants (e.g., InlinerSizeModel.o, InlinerSizeModel_metadata.o, and InlinerSizeModel_constants.o).
Currently, llvm/cmake/modules/TensorFlowCompile.cmake only tracks the primary object file (${obj_file}). Because the _constants.o and _metadata.o files are not added to GENERATED_OBJS, they are not included in the final archive (libLLVMAnalysis.a), leading to linkage failures.
## Error Messages:
```
ld.lld: error: undefined symbol: __tfcompile_llvm_InlinerSizeModel_Constant_0_constant_buffer_contents
>>> referenced by MLInlineAdvisor.cpp
>>> MLInlineAdvisor.cpp.o:(llvm::InlinerSizeModel::EmbeddedConstantBuffers()) in archive lib/libLLVMAnalysis.a
```
## Steps to Reproduce:
1. Install a recent TensorFlow pip package. In my case, 2.21.0 is broken. (`python3 -c "import tensorflow as tf; print(tf.__version__)"`)
2. Configure LLVM with MLGO enabled (e.g., -DTENSORFLOW_AOT_PATH=$TF_PIP -DLLVM_INLINER_MODEL_PATH=...).
3. Build Clang.
## Proposed Solution:
Update TensorFlowCompile.cmake to dynamically detect if the installed TensorFlow version emits these extra object files (either by checking the TF version via Python or by probing the output of a dummy compilation during configuration). If present, these extra objects must be added to the OUTPUT of the add_custom_command and appended to the GENERATED_OBJS list.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8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