<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - libomp.so: Missing linking against libm.so when compiled by Clang on Linux systems"
   href="https://bugs.llvm.org/show_bug.cgi?id=52115">52115</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>libomp.so: Missing linking against libm.so when compiled by Clang on Linux systems
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>OpenMP
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Runtime Library
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arfrever.fta@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Gentoo report: <a href="https://bugs.gentoo.org/816831">https://bugs.gentoo.org/816831</a>

As reported there, libomp.so compiled by Clang (instead of GCC) uses at least
fmaxl, which is defined in libm.so, but build system does not pass -lm to
consider linking against libm.so.

<span class="quote">> $ nm -D /usr/lib64/libomp.so | grep fmaxl
>   U fmaxl
> $ readelf -d /usr/lib64/libomp.so | grep NEEDED
>  0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
>  0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
>  0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
>  0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
>  0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]</span >


<a href="https://github.com/llvm/llvm-project/blob/37109974af4b33189a599735afa67ed57c27b8ab/openmp/runtime/cmake/LibompHandleFlags.cmake#L138-L144">https://github.com/llvm/llvm-project/blob/37109974af4b33189a599735afa67ed57c27b8ab/openmp/runtime/cmake/LibompHandleFlags.cmake#L138-L144</a>
contains:
<span class="quote">>   if(${CMAKE_SYSTEM_NAME} MATCHES "DragonFly|FreeBSD")
>     libomp_append(libflags_local "-Wl,--no-as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
>     libomp_append(libflags_local "-lm")
>     libomp_append(libflags_local "-Wl,--as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
>   elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
>     libomp_append(libflags_local -lm)
>   endif()</span >


I do not know why this code uses --no-as-needed to forcefully link against
libm.so on DragonFly and FreeBSD, but I am not asking to use --no-as-needed on
Linux.

Probable solutions:
Linux-specific solution:
     libomp_append(libflags_local "-Wl,--as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
-  elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
+  elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD")
     libomp_append(libflags_local -lm)

More generic solution:
     libomp_append(libflags_local "-Wl,--as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
-  elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
+  else()
     libomp_append(libflags_local -lm)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>