<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59590>59590</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            PPC: Undefined references linking to LLVM from TensorFlow
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Flamefire
      </td>
    </tr>
</table>

<pre>
    I'm trying to build TensorFlow 2.7.1 (yes not the latest) on PowerPC (ppc64le) and run into a problem that the JIT compiler generated X86 code instead of PPC code which I traced down to the default at https://github.com/llvm/llvm-project/blob/43d6991c2a4cc2ac374e68c029634f2b59ffdfdf/utils/bazel/llvm-project-overlay/llvm/config.bzl#L82

I was able to fix this by including a backported version of https://github.com/tensorflow/tensorflow/pull/55306 basically adding `"@bazel_tools//src/conditions:linux_ppc64le": native_arch_defines("PowerPC", "powerpc64le-unknown-linux-gnu"),` to the list.

However I now get an error while linking a test:

> `bazel-out/ppc-opt/bin/_solib_local/libtensorflow_Scompiler_Smlir_Stools_Skernel_Ugen_Slibtf_Uframework_Uc_Uinterface.so: error: undefined reference to 'LLVMInitializePowerPCAsmPrinter'`

I traced that down to a call to `llvm::InitializeNativeTarget()` which is https://github.com/llvm/llvm-project/blob/43d6991c2a4cc2ac374e68c029634f2b59ffdfdf/llvm/include/llvm/Support/TargetSelect.h#L119 and uses the macro `LLVM_NATIVE_TARGETMC` (and others) which expands to the missing symbols (as kinda expected)

So it seems that some Bazel target in LLVM is missing a dependency to pull in the PPC functions as it obviously works for the X86 target. I can't find anything in the TensorFlow sources, every place that pulls in `@llvm-project//llvm:X86CodeGen` also pulls in `@llvm-project//llvm:PowerPCCodeGen` so it must be in the LLVM sources where (likely) the `@llvm-project//llvm:Support` target depends on (among others) `X86CodeGen` but not `PowerPCCodeGen` so it works when "native" is x86, ARM, ... but I can't find where.

I expect that this is already fixed here but as I need this for TF 2.7 I can't upgrade LLVM so I'd need to cherry-pick the commit.

Could anyone point me to that commit or in a direction where I can find the place where it would be patched?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vs9z4jwS_WvEpQvKyGDwgQNfvmGWrZmp1JBMzc0lS22sRZZckhzC_PVbLcOEZGt_Xb5LCEb9uvu91y2LEPTRIm7Y8g-2_HMihtg6v9kZ0WGjPU5qpy6bPeOrDqK_aHuE6KAetFHwhDY4vzPuDHy2ms2B8fUFA1gXIbYIRkQMkfESnIVHd0b_-EBn-l4WC4P0g7AK_GBB2-hAQO9dbbCD2IoR4u_7J5Cu67VBD0e06EVEBT_XBUinELQNEYUC18Dj48P47Nxq2cIeohcSFSh3tlQzwSlsxGAiiAhtjH1g-ZbxHeO7o47tUM-k6xjfGfNy-5j23v0DZWR8VxtXM75b5Kooy7nkYiElFzJfLbBYy4yXRb5oeL0sm0Y1qmF8N0RtAkWKX2g-AE7dC3ojLm_ppLONPs7qX4bx_Muas-xPlm3Hv3s4iwCiNkidNPoVYqsD1BfQVppBkSwCaiFPvfNE0Av6oJ0lXv5DozEJ2Bh3_vilHwxVvFzmWQG1CFoKYy4gVErFioxxzhZZ6qyKzqU-Gd8FL8dWlI7aWcprtB1eq9-ac5ZvwYqoX7ASXraVwkZbDIyvGedXl9AxTl7hPT0YY6eDPVl3ttOEOD3aIR0rGX9gRXaT2OgQZ_fc_c2d8QU97MG6MxwxgrCA3jtPTjEUYU8jgcmu-fY-muWfqN3U6NQNZIS-l1PXJ0toy_iuCs7oujJOiqSyrt-orA4391aHzmhfHRJZ1eGE3qKpno9oqwOFNNVz40WHZ-dP1bOsnrWN6BshcRYccZZKpn8GO1KmwGODHq1MrmB89eXLj697q6MWRv_CK5fb0D36BMb4ipR756vrkKSBu02KAFI7YRZZcme-Zfn2Dflbku9J-CPGpFtJAoxzp8NfMVpXnNH9-PbgMPQ0AYzvxuoOaFDGWUsjNZ-P-2YIGJJVOiF96pF4q75tn_Y_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