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

    <tr>
        <th>Summary</th>
        <td>
            [BOLT] BOLT optimised shared library causes segmentation fault
        </td>
    </tr>

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

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

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

<pre>
    I attempted to use BOLT to optimise SVT-AV1 (also the latest git) for encoding video through ffmpeg, running ffmpeg after BOLT optimising libSvtAv1Enc.so.1.6.0 results in a segfault unfortunately. The steps taken were as follows:

1. Compile SVT-AV1 with the following flags added to the Arch Linux PKGBUILD, might be of note that this was done on Clang 15.0.6 as it's the current version in the Arch Linux repo:
`-march=native -mtune=native -Ofast -flto -fprofile-instr-use`

2. Collect PGO profile data by encoding a 1 minute long file with the following encode options
`ffmpeg -i EncodeSpeedTest.mkv -c:v libsvtav1 -crf 10 -preset 4 -g 240 -svtav1-params tune=0:enable-overlays=1:scd=1:rc=0:keyint=240:input-depth=10:film-grain=10:film-grain-denoise=0 -pix_fmt yuv420p10le -c:a copy ESTPGO.mkv `

3. Rebuild with profile data used, binary stripping disabled, and emitting relocs. (It runs at this point with a notable performance uplift)

4: Add instrumentation with llvm-bolt

5: Collect BOLT profile data with a repeat of the previous encode

6: Optimise with BOLT using the example command

7: Attempt to encode once again, a segfault occurs

I attempted to grab the backtrace from the core dump but I'm very much a novice with these things so I'm not sure if this is useful:

```
(gdb) bt
#0 0x00007f9bca0f2640 in svt_aom_highbd_h_predictor_4x16_sse2 () at /usr/lib/libSvtAv1Enc.so.1
#1  0x00007f9bca0e6f61 in svt_dav1d_inv_txfm_add_avx2 () at /usr/lib/libSvtAv1Enc.so.1
#2 0x00007f9bca070a4d in svt_aom_full_loop_uv () at /usr/lib/libSvtAv1Enc.so.1
#3  0x00007f9bca05f860 in full_loop_core () at /usr/lib/libSvtAv1Enc.so.1
#4  0x00007f9bca055ce8 in md_encode_block () at /usr/lib/libSvtAv1Enc.so.1
#5  0x00007f9bca0476ee in svt_aom_mode_decision_sb () at /usr/lib/libSvtAv1Enc.so.1
#6 0x00007f9bca0439ea in svt_aom_mode_decision_kernel () at /usr/lib/libSvtAv1Enc.so.1
#7  0x00007f9bcd6970af in  () at /usr/lib/libc.so.6
#8  0x00007f9bcd7299f0 in  () at /usr/lib/libc.so.6
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVltv2zwS_TXyy0CGbpbtBz-4TVMUWyDFl2xfBYocStxQpEAOlfjfLyg59WUvwBfAkCWRPIdzZuaIzHvVGcRDsvmSbB5WLFBv3eGvnPeE7pkzjavWitPhBzAiHEZCAWQheIQvTz9f4r0dSQ3KIzz_fkmPv3NIih3T3gL1CJoReoJOUVLsQVoHaLgVynQwKYFxkrOh60HKYcQuKb6CC8bE8eUNMEnoFrIzUxzUqn2e6Djl3wxfe7vO1_U6A4c-aPKgDDDw2EkWNEEw0joKhhHq0xpeegRPOHog9ooG3tAhMA_Sam3ffFIek-whyc7XfA1f7TAqfYnvTVE_B7esmPeqWeeBCbHIEwePjvfwU5nwDr_-8f3LP3_8fIjRDarrCVoEK8FYQqCeEVCvPLwxD8IaBGvgq2amg3yzztZ13FzUb-tnYB6cQ0MwofPKmhjsHZ_D0V7CqLN0YI73SflgGKkJIR0oGLx6fpLME6RSk4VUjs5KpTFVxpNLg8ekzq4lKaIkWiMn-PX9Cc7TQTBi0J4uCWaQw6BMIARto0hx1n8Rb16Ac3at8X92fc5_quDbPOF5RBQv6Gk9vE6Q8qQ8TrEO_ERsyiHlTkKeQTo69EhQQdpBUWWQLhPSkTk2eDiHniXlEQ1rNaZ2QqfZySflQ56UR8_F-c7x88RXPClDSflQVPFRmTFQKnCkKGoeX0mlh7RzTJn_fJMKNFb5mRXSUb03ciA4hakqsjHPNC7BMOB2PMG355df35_mGO90L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