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

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP] offload to x86 doesn't segfaults
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          ye-luo
      </td>
    </tr>
</table>

<pre>
    hitting segfault since 19.1.0. also tested latest main 1822462e2a0c9cc944f3ce114d8b1a71d0764350.

code `main.cpp`
```
int main()
{
#pragma omp target
{}
}
```
run and hit segfault.
```
$ clang++ -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu main.cpp
$ LIBOMPTARGET_DEBUG=1 ./a.out
omptarget --> Init offload library!
OMPT --> Entering connectLibrary
OMPT --> OMPT: Trying to load library libomp.so
OMPT --> OMPT: Trying to get address of connection routine ompt_libomp_connect
OMPT --> OMPT: Library connection handle = 0x71cf2b8dba40
OMPT --> Exiting connectLibrary
omptarget --> Loading RTLs...
omptarget --> RTLs loaded!
TARGET x86_64 RTL --> Implementing ffi_call with dlsym(ffi_call) -> 0x71cf2bd07f90
TARGET x86_64 RTL --> Implementing ffi_prep_cif with dlsym(ffi_prep_cif) -> 0x71cf2bd06180
omptarget --> Registered plugin x86_64 with 4 visible device(s)
omptarget --> Image 0x00006440394b60b0 is compatible with RTL x86_64 device 0!
omptarget --> Registering image 0x00006440394b60b0 with RTL x86_64!
omptarget --> Image 0x00006440394b60b0 is compatible with RTL x86_64 device 1!
omptarget --> Registering image 0x00006440394b60b0 with RTL x86_64!
omptarget --> Image 0x00006440394b60b0 is compatible with RTL x86_64 device 2!
omptarget --> Registering image 0x00006440394b60b0 with RTL x86_64!
omptarget --> Image 0x00006440394b60b0 is compatible with RTL x86_64 device 3!
omptarget --> Registering image 0x00006440394b60b0 with RTL x86_64!
omptarget --> Done registering entries!
omptarget --> Entering target region for device -1 with entry point 0x00006440394b6004
omptarget --> Default TARGET OFFLOAD policy is now mandatory (devices were found)
omptarget --> Use default device id 0
omptarget --> Call to omp_get_num_devices returning 4
omptarget --> Call to omp_get_num_devices returning 4
omptarget --> Call to omp_get_initial_device returning 4
omptarget --> Trans table 0x6440394bb030 : 0x6440394bb068
PluginInterface --> Load data from image 0x00006440394b60b0
PluginInterface --> Failed to read kernel environment for '__omp_offloading_25_29cb68_main_l3': Failed to find global symbol '__omp_offloading_25_29cb68_main_l3_kernel_environment' in the ELF image
Using default SPMD (2) execution mode
omptarget --> Entry point 0x00006440394b6004 maps to __omp_offloading_25_29cb68_main_l3 (0x000064404d3cb3d0)
omptarget --> loop trip count is 0.
omptarget --> Launching target execution __omp_offloading_25_29cb68_main_l3 with pointer 0x000064404d3cb3d0 (index=0).
PluginInterface --> Launching kernel __omp_offloading_25_29cb68_main_l3 with [1,1,1] blocks and [0,1,1] threads in Generic mode
Segmentation fault (core dumped)
```

gdb shows crash inside libffi.so. I'm using libffi 3.4.6.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMV81u4zgSfhr6UrBAUbJkH3ywx3GjgTQSzKTPAkWWZO5QpEBSif32C0pykkk7273YHWCAxBJYrK---mNR3HvVGsQtWe3J6rDgQzhZt73gUg92UVt52Z5UCMq04LFt-KADeGUEQrpJ0oQmwLW3ENAHlKB5fIGOKwPpmrG8YMg4FRshNnneZALTNJfrOuVlKmlZ5NmKJoTuCN0JKxFIQaNuIvqeFDQKCjr_0Z0yEzJha8I2UVju4y_LesfbjoPtegjctRhmYXkYXw4fgNxggBsJJxVenUo-7CEsB6G5aQnbE7aHZWN7NF3_-rKcLHmSHc7roiryZS-WWpnhvGzNAK9uTFD3X_cP3x6fdr9_uXuqDnf7719IdkghIezIEztEwrbrJ0hYLkl2B1-NCmCbRlsuQavacXchLCV0F5HmTXcmoIvJEdYYFOF-3veXTfGVZDt4cpe4NVh4jxmftusTb3-mFblxKR16D7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