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

    <tr>
        <th>Summary</th>
        <td>
            [lld] lld-link 21.1.0-rc3: undefined reference to _Avx2WmemEnabled
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld
      </td>
    </tr>

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

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

<pre>
    Possible related commit: https://github.com/llvm/llvm-project/commit/bbc8346e6bb543b0a87f52114fed7d766446bee1

Windows' `ucrt/wchar.h` contains:

```
    #if !defined(_M_CEE)
    #if (defined(_M_IX86) && !defined(_M_HYBRID_X86_ARM64)) || (defined(_M_X64) && !defined(_M_ARM64EC))
    extern int _Avx2WmemEnabled;
 __declspec(selectany) int _Avx2WmemEnabledWeakValue = 0;
    #if defined(_M_IX86)
    #pragma comment(linker, "/alternatename:__Avx2WmemEnabled=__Avx2WmemEnabledWeakValue")
    #else
 #pragma comment(linker, "/alternatename:_Avx2WmemEnabled=_Avx2WmemEnabledWeakValue")
    #endif
 #endif
    #endif
```

then later, in `wmemchr()`:

```
    #if !defined(__clang__) || defined(__AVX2__)
        if (_Avx2WmemEnabled && _N >= 16)
        {
            __m256i __v2 = _mm256_broadcastw_epi16(_mm_cvtsi32_si128(_C));
```

When compiling with AVX2 and then linking a DLL, lld-link fails with
```
lld-link: undefined reference to _Avx2WmemEnabled
```

21.1.0-rc1 works fine.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVFFvozgQ_jXDi9UIDBjngQfaJLqVdk-nfdj2nixjT4K3xkS2k-z--5Np2qZNT7oeihTwfPPNfMPHyBDMziG2UN9CvcrkIQ6Tb8Nk-5-Td1k_6d_tX1MIprdIPFoZURM1jaOJUHZkiHEfoOyAboBudiYOh36hphHoxtrj89_N3k8_UUWgm3Mq3fS94mXFkPV9XZV9LnmzrWlRVFvUjW4YqyrWIxaQd5B398bp6RSANgRYflA-UZzUIP1iAJYTNbkojZtbmROA5edf3hFCCNDSbAnQQuPWONRAufgm7tZroMt3EP4G8uWBM6BLApQBZVcMf_x9-_3LSjxwJrrv31iV6BK6uYPm7orsYQb8G9dMsL57ojg3hb8iekeMi0R0x1_0fsRx7WRvUUN5m0BCaFQ27FEB5QEtqijd71Tmo6R7lI8_pD0ggXJF8jPHi_qPpL8C9l7uRjm_fnQRKLfGPaIHmpRSoBtpU7cyopMjQtmJ655XV2cvLc0cF-XQBkxP_6vyB4X_c12nzfZc-OX-bejSXpB3cUBH0rcxd2RcMulpxFENHihP5Cz_lDWFstLthLjw0mW0-_FA5-CZIl1P3n0v8tlr4k8C5Tq984K9zYPm9uIpXUKMtGaGCHGks03EmA5E7yeplQzxJHBvEg8X4yjUMQZTUhFMkbRy8ezg2VvvJnWfJqWmcW-scTtyMnEgSQ2RTpOnMRr3mEKSrL5-TeO0Vt-kQ7KVxoY55R3vMyJtpIM7D4p43KJHp5DE6frjueqMFotikd94VZDT5B8DSSyLTLelXpZLmWFbNHXdFHVVFdnQotZ6q2tZYcFqzQteKd70uqm3he5LxMy0NKd1zmle8KrKi4Vu-pwzXZWM1wyZhirHURq7SCtyMfldZkI4YFvUVb2sMyt7tGFezJRaq5NL61Xm23mj9oddgCq3JsTwShBNtPMuT_h69Tq6F3HlJ2aUHbxtP73hZxEB6Oas49jSfwIAAP__433mkA">