Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7679 Discussions

Linking issue using thread_local std::vector.

AC_Simon
Beginner
749 Views

Hi,

i've encountered a weird issue when I tried to use a thread_local std::vector as a member variable inside a templated class/struct. The code compiles with icl but the linker says that the object file is basically corrupted (see pictures).

 

This is the minimal example that reproduces the issue on my machines:

 

#include <vector>

template<typename TA>
struct A {
  static thread_local std::vector<int> s;
};

template<typename TA>
thread_local std::vector<int> A<TA>::s;

template struct A<double>;

int main() {
  return 0;
}

 

 

This works in gcc, clang, icc, msvc (all versions that support thread_local). Through a bit of testing I found out that the issue vanishes if:

  - the struct is not templated.

  - the variable is a global variable outside of the class 

  - std::vector is replace by std::array (all other containers fail though)

 

Additional information:

OS Name: Microsoft Windows 10 Enterprise LTSC (64bit)

OS Version: 10.0.17763 Build 17763

Processor: Intel(R) Xeon(R) Gold 5218 CPU

 

Compiler Version: 19.0.5.281 Build 20190815 and 19.1.3.311 Build 20201010_000000

VS Version: 2017 (Linker Version 14.16.27045.0) and 2019 (Linker Version 14.28.29335.0)

Compile command: icl test.cpp

 

The dumbin.exe output is attached.

 

Best regards,

Simon

 

0 Kudos
1 Solution
VidyalathaB_Intel
Moderator
696 Views

Hi,

Thanks for reaching out to us.

Could you please try compiling the code using icx compiler on windows as it is working fine without giving any such errors.

icx is intel's oneAPI compiler which comes with oneAPI toolkits.

You can download it from the below links

oneAPI Base toolkit:

https://software.intel.com/content/www/us/en/develop/tools/oneapi/base-toolkit/download.html

oneAPI HPC toolkit:

https://software.intel.com/content/www/us/en/develop/tools/oneapi/hpc-toolkit/download.html

We suggest you to try using latest oneAPI compilers and let us know if you face any issues.

Regards,

Vidya.


View solution in original post

5 Replies
VidyalathaB_Intel
Moderator
697 Views

Hi,

Thanks for reaching out to us.

Could you please try compiling the code using icx compiler on windows as it is working fine without giving any such errors.

icx is intel's oneAPI compiler which comes with oneAPI toolkits.

You can download it from the below links

oneAPI Base toolkit:

https://software.intel.com/content/www/us/en/develop/tools/oneapi/base-toolkit/download.html

oneAPI HPC toolkit:

https://software.intel.com/content/www/us/en/develop/tools/oneapi/hpc-toolkit/download.html

We suggest you to try using latest oneAPI compilers and let us know if you face any issues.

Regards,

Vidya.


AC_Simon
Beginner
676 Views

Hi, 

Thanks for the reply.

icx works indeed, thanks for the suggestion.

For my icl pipeline I'll use __declspec(thread) for now since that seems to work:

#ifdef __ICL
  #define MY_THREAD_LOCAL __declspec(thread)
#else
  #define MY_THREAD_LOCAL thread_local
#endif

 

Best regards,

Simon

VidyalathaB_Intel
Moderator
666 Views

Hi,

>>since that seems to work

Glad to know that your issue is resolved.

As your issue has beed resolved could you please confirm whether we can close this thread from our.

Regards,

Vidya.



AC_Simon
Beginner
620 Views
I’m ok with using that workaround. If icl is replaced by icx in the future anyway then there is probably no need for a fix.

Best regards,
Simon
VidyalathaB_Intel
Moderator
559 Views

Hi,

Thanks for accepting our solution.

As the issue is resolved we are closing this thread from our end.

Please raise a new thread if you have any other queries.

Regards,

Vidya.

 

Reply