Putting -lm Before User Objects/Libraries on Link Line Can Impact Performance

Reference Number : DPD200121218

Version : 11.0

Operating System : Linux*

Problem Description : Starting with 11.0.081, a fix was made to the compiler driver to link the Intel Math Library libimf statically by default (the intended and documented behavior) instead of dynamically.  If -lm is used with the compiler driver (icc/icpc/ifort), the driver automatically inserts libimf before libm in the link line.  Linking in libimf.a when this is done causes a problem if -lm precedes any user-created objects or libraries.  For example:

icc -lm user1.o user2.o -luser3
Gets converted by the driver to:

ld ... -Bstatic -limf -Bdynamic -lm ... user1.o user2.o -luser3 ...
On Linux, static libraries must come after the object/library files that use them in the link line in order for the symbols to resolve.  Since libimf.a comes before the objects/libraries that use standard math functions, these math functions won't resolve to the static Intel math library.  However, the dynamic libm doesn't have an order dependency because it is a dynamic library, so the math functions will resolve to the GNU math library.  This can have a significant performance impact.

Resolution Status : Starting with 11.1.056, the compiler now emits a warning if -lm precedes other user objects or libraries on the linker command line.  If you run into a performance regression between compilers prior to 11.0.081 and compilers from 11.0.081 on, please verify that you don't have -lm being used prior to your objects/libraries in your link lines if you use icc/icpc/ifort to link. Using the above example, make the following change:

icc user1.o user2.o -luser3 -lm
[DISCLAIMER: The information on this web site is intended for hardware system manufacturers and software developers. Intel does not warrant the accuracy, completeness or utility of any information on this site. Intel may make changes to the information or the site at any time without notice. Intel makes no commitment to update the information at this site. ALL INFORMATION PROVIDED ON THIS WEBSITE IS PROVIDED "as is" without any express, implied, or statutory warranty of any kind including but not limited to warranties of merchantability, non-infringement of intellectual property, or fitness for any particular purpose. Independent companies manufacture the third-party products that are mentioned on this site. Intel is not responsible for the quality or performance of third-party products and makes no representation or warranty regarding such products. The third-party supplier remains solely responsible for the design, manufacture, sale and functionality of its products. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. *Other names and brands may be claimed as the property of others.]
For more complete information about compiler optimizations, see our Optimization Notice.

1 comment

anonymous's picture

On Fedora 11, using the -fast option with ifort produces the error ld: cannot find -lm

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.