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

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP] Crash in libomptarget from symbols being optimized out
        </td>
    </tr>

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

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

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

<pre>
    OpenMP uses a section to map the symbol names between the host and device. However, some symbols on the device get an entry in this section but can have the symbol be optimized out. This will cause a failure at runtime when we attempt to load it.
```
#pragma omp begin declare target
struct S {
  static constexpr int x = 1;
};
#pragma omp end declare target

int main() {
#pragma omp target
  { int x = S::x; }
}
```
```shell
> clang++ test.cpp -fopenmp --offload-arch=gfx1030 -O0
> ./a.out 
> clang++ test.cpp -fopenmp --offload-arch=gfx1030 -O3
> ./a.out 
"PluginInterface" error: Failure to load binary image 0x56530fcfdb40 on device 0: Error in hsa_executable_get_symbol_by_name(_ZN1S1xE): HSA_STATUS_ERROR_INVALID_SYMBOL_NAME: There is no symbol with the given name.
Libomptarget error: Unable to generate entries table for device id 0.
Libomptarget error: Failed to init globals on device 0
Libomptarget error: Consult https://openmp.llvm.org/design/Runtimes.html for debugging options.
Libomptarget error: Source location information not present. Compile with -g or -gline-tables-only.
Libomptarget fatal error 1: failure of target construct while offloading is mandatory
[1]    214058 IOT instruction (core dumped)  ./a.out
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVd9vozgQ_mucl1EQmKSUhzwkTaOttLtdNd2T7l4iYwbwytjIHprk_vqTgSTt3apPJ1UN4Jlvfvj7ZoT3qjaIK7bcsOV2JnpqrFv9avoC3d2ssOV59dyh-fYDeo8eBHiUpKwBstCKDqhB8Oe2sBqMaNFDgXRENMNBYz2BMCWU-KYkRvDFHvENHeMP4G178fRgR_vRDGoMXoCG3BlUOF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