Repository: tensorflow
Issue: Failed to build `tensorflow_cc` in Windows when linking
Labels: stat:awaiting tensorflower,type:build/install,subtype:windows,2.18.rc

### Issue type

Build/Install

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

2.18.0-rc0

### Custom code

No

### OS platform and distribution

Windows 11

### Mobile device

_No response_

### Python version

3.12.7

### Bazel version

6.5.0

### GCC/compiler version

Clang 18.1.7

### CUDA/cuDNN version

No

### GPU model and memory

_No response_

### Current behavior?

I built the C++ library in Windows with LLVM/Clang 18.1.7 by command:
```bash
bazel build --config=release_cpu_windows --config=win_clang //tensorflow:tensorflow_cc
```
All compilation works well, but linking at the final task failed. It seems a lot of symbols lost when linking, such as `Session`, `SavedModelBundleInterface`, et al. They were all basic functions or classes and should not be missed.

CUDA was excluded.

I have tried many LLVM/Clang versions from 17 to 19. Looks like it has nothing to do with the compiler version.

### Standalone code to reproduce the issue

```shell
bazel build --config=release_cpu_windows --config=win_clang //tensorflow:tensorflow_cc
```


### Relevant log output

```shell
D:/tensorflow/tensorflow/BUILD:1316:21: Linking tensorflow/tensorflow_cc.dll failed: (Exit 1): lld-link.exe failed: error executing command (from target //tensorflow:tensorflow_cc.dll) 
  cd /d D:/output_base/execroot/org_tensorflow
  SET CLANG_COMPILER_PATH=C:Program FilesLLVMbinclang.exe
    SET LIB=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\ATLMFC\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.26100.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\\lib\10.0.26100.0\\um\x64;C:\Program Files\LLVM\lib\clang\18\lib\windows
    SET PATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\bin\HostX64\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\VCPackages;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\DiagnosticsHub\Collector;C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\\x64;C:\Program Files (x86)\Windows Kits\10\bin\\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\;;C:\WINDOWS\system32;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\Linux\bin\ConnectionManagerExe;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg
    SET PWD=/proc/self/cwd
    SET PYTHON_BIN_PATH=C:/Python312/python.exe
    SET PYTHON_LIB_PATH=C:/Python312/Lib/site-packages
    SET TEMP=E:\tmp
    SET TF2_BEHAVIOR=1
    SET TMP=E:\tmp
  C:\Program Files\LLVM\bin\lld-link.exe @bazel-out/x64_windows-opt/bin/tensorflow/tensorflow_cc.dll-2.params
# Configuration: ee29c35b2efb4ddb1fe39799ba1e7aae463cd78c5b2bb106c9b875ad299c989f
# Execution platform: //tensorflow/tools/toolchains/win:x64_windows-clang-cl
lld-link: warning: ignoring unknown argument '-lm'
lld-link: warning: ignoring unknown argument '-lpthread'
lld-link: warning: ignoring unknown argument '-lm'
lld-link: warning: ignoring unknown argument '-lpthread'
lld-link: warning: ignoring unknown argument '-lm'
lld-link: warning: duplicate symbol: TF_DataTypeSize
>>> defined at tf_datatype.lo.lib(tf_datatype.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_NewBuffer
>>> defined at tf_buffer.lib(tf_buffer.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_NewStatus
>>> defined at tf_status.lib(tf_status.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_GetCode
>>> defined at tf_status.lib(tf_status.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_Message
>>> defined at tf_status.lib(tf_status.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_DeleteStatus
>>> defined at tf_status.lib(tf_status.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_NewBufferFromString
>>> defined at tf_buffer.lib(tf_buffer.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_SetStatus
>>> defined at tf_status.lib(tf_status.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_DeleteTensor
>>> defined at tf_tensor.lib(tf_tensor.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_DeleteBuffer
>>> defined at tf_buffer.lib(tf_buffer.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_TensorData
>>> defined at tf_tensor.lib(tf_tensor.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_NewTensor
>>> defined at tf_tensor.lib(tf_tensor.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_SetPayload
>>> defined at tf_status.lib(tf_status.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_NumDims
>>> defined at tf_tensor.lib(tf_tensor.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_Dim
>>> defined at tf_tensor.lib(tf_tensor.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_AllocateTensor
>>> defined at tf_tensor.lib(tf_tensor.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_TensorBitcastFrom
>>> defined at tf_tensor.lib(tf_tensor.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_TensorElementCount
>>> defined at tf_tensor.lib(tf_tensor.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: warning: duplicate symbol: TF_ForEachPayload
>>> defined at tf_status.lib(tf_status.obj)
>>> defined at libtensorflow_framework.so.2.18.0

lld-link: error: <root>: undefined symbol: class tensorflow::Session * __cdecl tensorflow::NewSession(struct tensorflow::SessionOptions const &)
lld-link: error: <root>: undefined symbol: public: virtual __cdecl tensorflow::SavedModelBundleInterface::~SavedModelBundleInterface(void)
lld-link: error: <root>: undefined symbol: bool __cdecl tensorflow::MaybeSavedModelDirectory(class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> const &)
lld-link: error: <root>: undefined symbol: int `private: static class lts_20230802::container_internal::btree<struct absl::lts_20230802::container_internal::set_params<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>, struct std::less<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, class std::allocator<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, 256, 0>>::btree_node<struct absl::lts_20230802::container_internal::set_params<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>, struct std::less<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, class std::allocator<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, 256, 0>> * __cdecl absl::lts_20230802::container_internal::btree<struct absl::lts_20230802::container_internal::set_params<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>, struct std::less<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, class std::allocator<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, 256, 0>>::EmptyNode(void)'::`2'::$TSS0
lld-link: error: <root>: undefined symbol: `public: class std::unique_ptr<class tensorflow::RunHandler, struct std::default_delete<class tensorflow::RunHandler>> __cdecl tensorflow::RunHandlerPool::Impl::Get(__int64, __int64, class tensorflow::RunOptions_Experimental_RunHandlerPoolOptions const &)'::`2'::`local static thread guard'{2}
lld-link: error: <root>: undefined symbol: class std::unordered_map<enum tensorflow::DataType, enum tensorflow::FullTypeId, struct tensorflow::DataTypeHasher, struct std::equal_to<enum tensorflow::DataType>, class std::allocator<struct std::pair<enum tensorflow::DataType const, enum tensorflow::FullTypeId>>> *tensorflow::DT_TO_FT
lld-link: error: <root>: undefined symbol: private: static class std::vector<class tsl::core::RefCountPtr<class tensorflow::Rendezvous>, class std::allocator<class tsl::core::RefCountPtr<class tensorflow::Rendezvous>>> &tensorflow::LocalRendezvous::aborted_rendezs_
lld-link: error: <root>: undefined symbol: private: static class tsl::mutex &tensorflow::LocalRendezvous::aborted_rendezs_mu_
lld-link: error: <root>: undefined symbol: class tsl::monitoring::Counter<2> *tensorflow::metrics::eager_client_error_counter
lld-link: error: <root>: undefined symbol: struct absl::lts_20230802::container_internal::btree<struct absl::lts_20230802::container_internal::set_params<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>, struct std::less<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, class std::allocator<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, 256, 0>>::EmptyNodeType *`private: static class absl::lts_20230802::container_internal::btree_node<struct absl::lts_20230802::container_internal::set_params<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>, struct std::less<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, class std::allocator<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, 256, 0>> * __cdecl absl::lts_20230802::container_internal::btree<struct absl::lts_20230802::container_internal::set_params<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>, struct std::less<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, class std::allocator<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, 256, 0>>::EmptyNode(void)'::`2'::empty_node
lld-link: error: <root>: undefined symbol: private: static class tsl::mutex tensorflow::tfdbg::DebugEventsWriter::factory_mu_
lld-link: error: <root>: undefined symbol: char const *tensorflow::kDisableJitKernelsEnvVar
lld-link: error: <root>: undefined symbol: public: static __int64 tensorflow::CollectiveExecutor::kInvalidId
lld-link: error: <root>: undefined symbol: char const *tensorflow::kJitKernelLabel
lld-link: error: <root>: undefined symbol: public: static class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> const tensorflow::LogMemory::kLogMemoryLabel
lld-link: error: <root>: undefined symbol: class tsl::monitoring::Counter<5> *tensorflow::metrics::mlir_bridge_first_phase_counter
lld-link: error: <root>: undefined symbol: class tsl::monitoring::Counter<1> *tensorflow::metrics::mlir_second_phase_count
lld-link: error: <root>: undefined symbol: void * (__cdecl *nsync::nsync_malloc_ptr_)(unsigned __int64)
lld-link: error: <root>: undefined symbol: struct nsync::lock_type_s *nsync::nsync_reader_type_
lld-link: error: <root>: undefined symbol: struct nsync::lock_type_s *nsync::nsync_writer_type_
lld-link: error: too many errors emitted, stopping now (use /errorlimit:0 to see all errors)
```