<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/143575>143575</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            MSVC Linker Issue When Targeting ARM64EC
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          JiachenYuan
      </td>
    </tr>
</table>

<pre>
    Hi! A [recent commit](https://github.com/llvm/llvm-project/pull/125320) has caused a linker issue when cross-compiling the LLVM project targeting ARM64EC on a AMD64 host Windows machine. The reduced steps to reproduce the linker error is listed below.

### Prerequisite
MSVC
- Visual Studio Community 2022 17.14.4

Individual MSVC components:
- MSVC v143 - VS 2022 C++ ARM64/ARM64EC build tools (Latest)
- C++ ATL for latest v143 build tools (ARM64/ARM64EC)
- C++ ATL for latest v143 build tools (x86 & x64)
### Build for arm64ec
1. Open a x64 Native Tools Command Prompt for VS 2022
2. The linker error can be reproduced by
```
git clone https://github.com/llvm/llvm-project.git
mkdir build
cd build

cmake -G "Visual Studio 17 2022" -A ARM64EC -DLLVM_ENABLE_PROJECTS="llvm" -DLLVM_TARGETS_TO_BUILD="AArch64" -DLLVM_OPTIMIZED_TABLEGEN=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_FLAGS="/wd4146 /wd4244 /wd4267 /wd4996 /wd4800 /D_HAS_EXCEPTIONS=0" -DCMAKE_EXE_LINKER_FLAGS="softintrin.lib arm64rt.lib" -DCMAKE_SHARED_LINKER_FLAGS="softintrin.lib arm64rt.lib" -DCMAKE_MODULE_LINKER_FLAGS="softintrin.lib arm64rt.lib" -DLLVM_DISABLE_ASSEMBLY_FILES=ON  ..\llvm-project\llvm

msbuild LLVM.sln /m /p:Platform=ARM64EC /p:Configuration=Release
```

(The `-DLLVM_DISABLE_ASSEMBLY_FILES` flag is suggested in https://github.com/llvm/llvm-project/issues/100335 to ignore problem: `LNK1372: hybrid map entry target function 'llvm_blake3_compress_in_place_sse41' is not 4-byte aligned`)

### Linker Error Message
```
LINK : error LNK2001: unresolved external symbol "??_C@_0L@OHILDFJG@" (??_C@_0L@OHILDFJG@) (EC Symbol) 
```
### Triage
Dumping the symbol tables of the generated object files shows that the unresolved symbol is probably related to the `HybridPatchableTargetSuffix` global variable in `AsmPrinter.cpp` introduced by the aforementioned commit. Directly substituting the literal strings to its uses does not solve the problem. A dirty workaround that works for me is to divide up the string at its definition and re-concatenate the parts at the original uses.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVl9z4roO_zTmRUMmcQIpDzykJLTsAmUKZ8_ufck4iQi-dWyu7bTl29-xQ7vbPpyZ3TOTAf-Rf5Kln2QxY3grEedkcksm-Yj19qT0_Atn9Qnlj57JUaWay_yeExpBBmRyq7FGaaFWXcctmeSE3pysPRsSZ4QuCV223J76KqhVR-hSiOe3v_FZq_9ibQldnnshCF1GdBLTkNAZnJiBmvUGG2AguHxCDdyYHuHlhBJqrYwZ16o7c8FlC_aEsF5_28AVEizTLVq3lT1upkmxACWBQbbJpwmclLHwN5eNejHQsfrEJQZwOCFobPoaGzAWzwasAo1nrdyaV3E1BLVWzhwQ3FhsoEKhXgISZu6j8fDBTqPG__XccIskzDb7bwsSZmP4xk3PBOxt33AFC9V1veT2AjSkFKI0iJIgGbBWsuHPvHHS7rRz8VlJlNb71mH55ecoiWEM3_YDxILQW0Jvh4sTunxzQNVz0YBVShgg9GbNLBpL6MwDvR86rOGoNAi_O0B_OvgJ9w8QXm-mQOgUXh3O7IPTbr2kO890N02wJmEWBfBwRhe-12kCW2b5M8LBgznvMdnATqvubP25qxtImNEhph-CVjMJFf4MawPVxRkwDa9fmLXcQi2URPg9GgcttyTMuqeG6-HGJMzq5n3oZh17QhjfAaH0Iw2idLCaUhhn75wd547UZbHNbtdFuXt8-FIsDnsS54TSwQL6JnPIHu-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