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

    <tr>
        <th>Summary</th>
        <td>
            [libomptarget] Linker error on functions with the same name as zlib functions when enabling LTO and OpenMP offload on RHEL9
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          dwoodwor-intel
      </td>
    </tr>
</table>

<pre>
    I'm seeing an "undefined reference to symbol" linker error with some functions that have the same name as functions in zlib when linking with LTO and OpenMP Offload enabled on Red Hat Enterprise Linux 9:

```
$ cat zlib-omptarget-clash.c
int main() { return 0; }

void crc32_z(void) {}
$ clang -flto -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu zlib-omptarget-clash.c -o zlib-omptarget-clash
/usr/bin/ld: /tmp/zlib-omptarget-clash-e5456a.o (symbol from plugin): undefined reference to symbol 'crc32_z@@ZLIB_1.2.9'
/usr/bin/ld: /usr/lib64/libz.so.1: error adding symbols: DSO missing from command line
/iusers/dwoodwor/llvm-upstream/deploy/bin/clang-linker-wrapper: error: 'ld' failed
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
```

This is reproducible on the main branch starting with dc52712a063241bd0d3a0473b4e7ed870e41921f, which links a couple LLVM libraries (and, indirectly, zlib) into libomptarget.

The linker error only appears if `-flto` is used. It also doesn't appear on RHEL8 even with LTO enabled. RHEL8 seems to use the same version of zlib (1.2.11) but does have a different version of ld (GNU ld 2.30-93.el8 vs. RHEL9's GNU ld 2.35.2-17.el9). I've tried a few different OS versions in VMs and these are the only ones where I could reproduce this bug:

* RHEL 9.0 (GNU ld 2.35.2-17.el9)
* Fedora 34 (GNU ld 2.35.1-41.fc34)

These OS versions are not affected and don't show this linker error:

* RHEL 8.4 (GNU ld 2.30-93.el8)
* Ubuntu 20.04.3 (GNU ld 2.34)
* Ubuntu 21.04 (GNU ld 2.36.1)
* Fedora 33 (GNU ld 2.35-18.fc33)
* Fedora 35 (GNU ld 2.37-17.fc35)
* openSUSE Leap 15.4 (GNU ld 2.37.20211103-150100.7.37)
* SLES 15.4 (GNU ld 2.37.20211103-150100.7.37)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVk1v2zgQ_TXyZSBB1Kd98KHZJNsA7maxaXropaBEyuYuRQok5TT99Tsj2Y6ddQssIOuDnOG89zgzdGPF6_ohyuoevJTKbIEbiLJsNEJ2ykgBTnbSSdNKCBb8a99YjfOglflHOpDOWQcvKuzA215CN5o2KGs8hB0PsON79NtJ8BwnDd24PzNSBn5o1cDLTpppSUIwrbb5_IhQBDwO0nz6Ex67TlsuQBreaERlDfyFj48Y484E6QanvISNMuN3WEX5hyi9jdLjvUoP1_yZFdCiHwWObT8E7rYyxK3mfpe0s40yAXquTJQto2wFUX2DOoTRGUij_Aa_b88D7K0S0Lo2z779QA_6PHi9GVJQzZFd3GkUMu4sEuuH00s8w_BRfvt9WX2rinhoY0184q0ZfwIWYnt15hjzfvQO7w0RudcCdcG9vQ_9gPdrfrEsi7LiiUWz5bzX0Dnbw6DHLS1C0sIvcwM966MURYrX183DzTeWZMkKZ34NbB5EXFUxP38k3iaMZuc840JQgsyRPI3fPj1Cr7yn4Qlpa_ue8galk6doavTSeXwRL9bibwqj9308Dj44yXuakoO2rydQ02bFc5bHL44Pg3QnIDPeGoFnNXRcYUbOsWYvVl5YHkrliGy2n7NcflcBJ4QERpIjTIj3k5hSYnHsLSYqFgoJfzWVp_vnncJK8rgbg7NibBVWCBUI1R0lMTSOmxYLFLc6nApMtGVWs4ynVZ4VrBGpyHla1HlTyFqKZZ3Kgq0y1kXZb1ieCv2JhweOeMcBI2w2Xz7hGC7ulPQEH9mRtTJCOdkG_UpflGdUDVhSlsxPKZdccpCXLcUa_QqkOndIrgPkPFUOPokrKiUSeAjAtbcgrPQoUh0OHlN7-Hi3WYLcY2M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