Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6977 Discussions

segmentation fault when linking libc and mkl statically

may_ka
Beginner
973 Views

Hi there,

 

the following program crashes when libc and mkl are both linked statically. I found this for compilers g++ and intel clang++ for linux kernels 5.10 and 3.10. Under kernel 3.10 the crash occurs with g++/libc version >=8.3.

 

 

#include <string>
#include <iostream>
#include "mkl.h"
void zzzz(){
  double *z,*zz;
  double x=cblas_ddot(10,z,1,zz,1);
}
int main(int argc, char** argv){
  std::string msg;
  try{
    msg="bla";throw msg;
  }catch(std::string msg){
    std::cout<<"an error has occured."<<std::endl;
    return(1);
  }
  return(0);
}

 

 

the makefile was

 

SHELL := /bin/bash
intel_loc=/opt/intel
export LD_LIBRARY_PATH=$(intel_loc)/oneapi/compiler/2021.2.0/linux/compiler/lib/intel64_lin:$LD_LIBRARY_PATH
a=$(shell source $(intel_loc)/oneapi/setvars.sh; echo $$PATH)
export PATH = $(a)
gnu:
	g++ -march=native -O3 -ffast-math -static -static-libstdc++ main1.cpp -I /opt/intel/oneapi/mkl/2021.2.0//include/ -I /opt/intel/oneapi/mkl/2021.2.0//include/intel64/ilp64 -Wl,--start-group /opt/intel/oneapi/mkl/2021.2.0//lib/intel64/libmkl_intel_ilp64.a /opt/intel/oneapi/mkl/2021.2.0//lib/intel64/libmkl_core.a /opt/intel/oneapi/mkl/2021.2.0//lib/intel64/libmkl_sequential.a -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lm -ldl
iclang:
	clang++ -march=native -O3 -static  -static-libstdc++ main1.cpp -I /opt/intel/oneapi/mkl/2021.2.0//include/ -I /opt/intel/oneapi/mkl/2021.2.0//include/intel64/ilp64 -Wl,--start-group /opt/intel/oneapi/mkl/2021.2.0//lib/intel64/libmkl_intel_ilp64.a /opt/intel/oneapi/mkl/2021.2.0//lib/intel64/libmkl_core.a /opt/intel/oneapi/mkl/2021.2.0//lib/intel64/libmkl_sequential.a -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lm -ldl

 

A workaround is to change from "-static" to "-static-intel". However any other suggestions/workaround for this?

 

Thanks

0 Kudos
5 Replies
VidyalathaB_Intel
Moderator
951 Views

Hi Karl,

 

Thanks for reaching out to us.

 

>> A workaround is to change from "-static" to "-static-intel"

 

As you wanted to link the MKL statically you need to use -static-intel flag during compiling your code, as per the documentation when you use

 

-static --- It prevents the code from linking with shared libraries

-static-intel --- It is used to link the Intel provided libraries statically

 

Please refer to the below documentation link for more details

https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-reference/compiler-options/alphabetical-list-of-compiler-options.html

 

Regards,

Vidya.

 

 

0 Kudos
may_ka
Beginner
941 Views

Hi,

 

thank you for your response.

 

I am aware that for clang++ the workaround flags are "-static -shared-libgcc" and for icpc "-static-intel" .....................

 

However, the question was how I can link libgcc AND mkl statically (with clang++) *without* having a segfault in case an exceptions is thrown.

 

Best

0 Kudos
VidyalathaB_Intel
Moderator
884 Views

Hi Karl,

 

>>how I can link libgcc AND mkl statically (with clang++) *without* having a segfault in case an exceptions is thrown.

 

Could you please try with the below command and let us know if it helps in resolving the issue?

 

clang++ -march=native -O3 -qmkl -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_ilp64.a ${MKLROOT}/lib/intel64/libmkl_sequential.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm -ldl -static-libgcc -static <file.cpp>

 

Please find the below screenshot for more details.

 

VidyalathaB_Intel_0-1639504123158.png

 

 

Regards,

Vidya.

 

 

0 Kudos
VidyalathaB_Intel
Moderator
837 Views

Hi Karl,


Reminder:


Has the solution provided above helped? If yes, could you please confirm whether we can close this thread from our end?


Regards,

Vidya.


0 Kudos
VidyalathaB_Intel
Moderator
775 Views

Hi Karl,


As we have not heard back from you, we are closing this thread assuming that your issue is resolved.

Please post a new question if you need any additional information from Intel as this thread will no longer be monitored.


Regards,

Vidya.


0 Kudos
Reply