Intel® oneAPI Base Toolkit
Support for the core tools and libraries within the base toolkit that are used to build and deploy high-performance data-centric applications.
419 Discussions

Is it possible to create a dynamic shared object (DSO) with no dependencies on libimf.so

Richard_P_1
Beginner
1,732 Views

I was using the classic Intel compiler (icc and icpc) to create a “standalone” dynamic shared object (DSO). In short these link-time flags did the trick: "-shared -static-intel -static" to create a standalone shared library (mylib-icc.so) that I was able to distribute to my clients without having to distribute any Intel's DSO.

Dependencies:
[rp]$ ldd mylib-icc.so
                linux-vdso.so.1 (0x00007ffd94bb4000)
                librt.so.1 => /lib64/librt.so.1 (0x00007f0d78127000)
                libm.so.6 => /lib64/libm.so.6 (0x00007f0d77da5000)
                libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f0d77a10000)
                libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f0d777f8000)
                libc.so.6 => /lib64/libc.so.6 (0x00007f0d77435000)
                libdl.so.2 => /lib64/libdl.so.2 (0x00007f0d77231000)
                libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f0d77011000)
                /lib64/ld-linux-x86-64.so.2 (0x00007f0d78956000)

I am now updating to the new oneAPI base kit but I'm not able to achieve the same result. That is to create a standalone shared library for Linux to be linked and used with an application that is built using GCC.

[rp]$ icx -dumpversion
result is 12.0.0
[rp]$ icpx -dumpversion
result is 12.0.0

I compile my C source files using the following command line:
[rp] icx -fvisibility=hidden -march=corei7 -fPIC -c myfilex.c

Linking with the following:
[rp]$ icpx -o mylib.so -shared myfile1.o myfile2.o allmyotherfiles.o

I get the following dependencies:
[rp]$ ldd mylib.so
   linux-vdso.so.1 (0x00007ffdbe51d000)
                libsvml.so => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libsvml.so (0x00007f6399c5f000)
                libirng.so => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libirng.so (0x00007f63998f5000)
                libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f6399560000)
                libimf.so => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libimf.so (0x00007f6398ed8000)
                libm.so.6 => /lib64/libm.so.6 (0x00007f6398b56000)
                libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f639893e000)
                libintlc.so.5 => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libintlc.so.5 (0x00007f63986c6000)
                libdl.so.2 => /lib64/libdl.so.2 (0x00007f63984c2000)
                libc.so.6 => /lib64/libc.so.6 (0x00007f63980ff000)
                /lib64/ld-linux-x86-64.so.2 (0x00007f639bbf7000)

Adding the "-static-intel" option I still get dependencies on Intel's libimf.so and libintlc.so although libirng.so and libsmvl.so have disappeared

[rp]$ icpx -o mylib.so -shared -static-intel myfile1.o myfile2.o myotherfiles.o
[rp]$ ldd mylib.so
                linux-vdso.so.1 (0x00007fff457ca000)
                libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f9538ef5000)
                libimf.so => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libimf.so (0x00007f953886d000)
                libm.so.6 => /lib64/libm.so.6 (0x00007f95384eb000)
                libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f95382d3000)
                libdl.so.2 => /lib64/libdl.so.2 (0x00007f95380cf000)
                libc.so.6 => /lib64/libc.so.6 (0x00007f9537d0c000)
                /lib64/ld-linux-x86-64.so.2 (0x00007f9539786000)
                libintlc.so.5 => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libintlc.so.5 (0x00007f9537a94000)

Adding the "--as-needed" option I still get dependencies on Intel's libimf.so and libintlc.so
[rp]$ icpx -o mylib.so -shared -static-intel Wl,--as-needed myfile1.o myfile2.o myotherfiles.o
[rp]$ ldd mylib.so
                linux-vdso.so.1 (0x00007fff1b76d000)
                libimf.so => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libimf.so (0x00007fc3e24d7000)
                libc.so.6 => /lib64/libc.so.6 (0x00007fc3e2114000)
                libintlc.so.5 => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libintlc.so.5 (0x00007fc3e1e9c000)
                /lib64/ld-linux-x86-64.so.2 (0x00007fc3e305b000)

[rp]$ ldd -u mylib.so
Unused direct dependencies:
                /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libimf.so

The strange thing here is that libimf doesn't seem to be used (see above ldd -u result) but it is needed when linking my test app using GCC otherwise it complains.  When I give access to only libimf.so GCC tells me that libintlc.so.5 is needed by libimf.so. All works fine when I gave GCC access to both libs.

Any help here would be greatly appreciated. Thanks.

0 Kudos
8 Replies
RahulV_intel
Moderator
1,712 Views

Hi,

 

Could you please attach a small reproducer code if possible?

Also specify your OS, oneAPI version.

 

Thanks,

Rahul

0 Kudos
RahulV_intel
Moderator
1,703 Views

Hi,


Just a quick reminder to share your reproducer code.


Thanks,

Rahul


0 Kudos
Richard_P_1
Beginner
1,696 Views

Hi Rahul, sorry for  the delay. Here’s a short piece of code that reproduces the situation:

/*
                icxTest4so.c
*/

#include <math.h>
#include <float.h>

float externFunc( float *dn0, float *dn1 );

void test_function( float dn[] )
{
   float k_cn, k_dn, sum;

   sum = 0.01F;
   k_cn = ( float )( 1 / sqrt( sum ) );
   sum += externFunc( dn, dn );
   k_dn = ( float )( 1 / sqrt( sum ) );
}

[rp]$ icx -fPIC -c icxTest4so.c -o icxTest4so.o
[rp]$ icx -o test_shared.so -shared -static-intel -Wl,--as-needed icxTest4so.o
[rp]$ ldd test_shared.so
                linux-vdso.so.1 (0x00007ffe490e1000)
                libimf.so => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libimf.so (0x00007f1aa8448000)
                libdl.so.2 => /lib64/libdl.so.2 (0x00007f1aa8244000)
                libc.so.6 => /lib64/libc.so.6 (0x00007f1aa7e81000)
                libintlc.so.5 => /opt/intel/oneapi/compiler/2021.1.1/linux/compiler/lib/intel64_lin/libintlc.so.5 (0x00007f1aa7c09000)
                /lib64/ld-linux-x86-64.so.2 (0x00007f1aa8cdd000)
[rp]$

Thanks.

0 Kudos
RahulV_intel
Moderator
1,686 Views

Hi Richard,

 

You're right. Nextgen compilers(ICX/ICPX) does seem to have a dependency on libimf.so when following your steps.

 

However, there seems to be no dependency on libimf.so with the classic compilers (ICC/ICPC).

 

ldd test_shared.so

    linux-vdso.so.1 (0x00007fffff9c2000)

    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f735f538000)

    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f735f346000)

    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f735f340000)

    /lib64/ld-linux-x86-64.so.2 (0x00007f735f56b000)

 

 

Intel classic compilers(ICC/ICPC) comes along with the HPC toolkit. Please find the download link below:

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

 

 

Thanks,

Rahul

 

0 Kudos
Richard_P_1
Beginner
1,676 Views

Many thanks Rahul for confirming that it is not possible to create a dynamic shared object (DSO) with no dependencies on libimf.so when the math lib is used. At the end it is not so big of an issue, we would just have to distribute the necessary Intel's DSO with along with our own DSO. However with all these tests I came to an unfortunate conclusion. It may not be the right place to discuss this but my preliminary tests show that gcc 8.3 is more efficient on an corei7. I tried icx 2021.1, icc 2021.1 and icc 19.0.0.117. We were using icc because it was significantly more efficient than gcc 4.x and older.

One more thing that I would need clarification on if I may. I was under the impression that icc 19.0.0.117 created DSOs that are universal and could run on virtually any cpu and that it would select the specific math routine depending on the cpu it was running on. Is this true? I wasn't able to confirm the prior by searching through the documentation. If it is true, is it also true for icc 2021.1 and icx 2021.1?

Thanks and regards,

Richard

 

0 Kudos
RahulV_intel
Moderator
1,659 Views

Hi Richard,

 

Thanks for providing your inputs. I have forwarded your query to the subject matter experts. They will let you know if there is any way to bypass libimf.so with ICX/ICPX and also clarify your other queries.

 

Thanks and regards,

Rahul

0 Kudos
Anoop_M_Intel
Employee
1,497 Views

ICPX compiler is linking with libimf dynamically unlike the ICPC behavior of static linking. Using -static-intel is not making that behavior change with ICPX. Have escalated this case to Compiler Development.


0 Kudos
User01
New Contributor II
649 Views

I see cases where I must explicitly add "-lintlc" when using `icpx` as the linker command as of 2023.2.

$ icpx --version
Intel(R) oneAPI DPC++/C++ Compiler 2023.2.0 (2023.2.0.20230721)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /glob/development-tools/versions/oneapi/2023.2.0.1/oneapi/compiler/2023.2.1/linux/bin-llvm
Configuration file: /glob/development-tools/versions/oneapi/2023.2.0.1/oneapi/compiler/2023.2.1/linux/bin-llvm/../bin/icpx.cfg

Are there any updates on the relationship between the math library, intlc, and linking?  What should developers expect to need to specify explicitly to the linker?

0 Kudos
Reply