<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 - Clang chooses wrong linker for OpenMP offload target"
   href="https://bugs.llvm.org/show_bug.cgi?id=41277">41277</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang chooses wrong linker for OpenMP offload target
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </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>Driver
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>bucyril@ee.ethz.ch
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Note: I had to hack in support for ARM in the libomptarget CMake files.
However, having looked at the code, this bug looks to be independent from the
offload target architecture.

I am trying to use Clang to compile an OpenMP application for an ARM host and
RISCV offload target. When linking the offloaded binary, the compiler chooses
to link the offloaded binary using the ARM linker instead of the RISCV linker.
This seems to be due to my directory structure and linker names.

This is what my <toolchain>/bin directory looks like:
<toolchain>/bin/arm-linux-gnueabihf-ld
<toolchain>/bin/riscv32-unknown-elf-ld

The relevant arguments to Clang are:
-target arm-linux-gnueabihf
--gcc-toolchain=<toolchain>/bin
-fopenmp-targets=riscv32-unknown-elf

As seen in this function:
<a href="https://github.com/llvm-mirror/clang/blob/92470c6aadff9e614bfac44f48e6e1d430e5a32d/lib/Driver/Driver.cpp#L4431">https://github.com/llvm-mirror/clang/blob/92470c6aadff9e614bfac44f48e6e1d430e5a32d/lib/Driver/Driver.cpp#L4431</a>
The Clang driver apparently only considers the linker names `ld` or
`arm-linux-gnueabihf-ld`, independent of the ToolChain TC, i.e., for the RISCV
toolchain as well.

My temporary workaround is inserting `Names.emplace_back(TC.getTripleString() +
"-" + Tool.str());` into the beginning of the linked function.</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>