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

    <tr>
        <th>Summary</th>
        <td>
            [BOLT] Optimized binary segfaults when using --use-old-text
        </td>
    </tr>

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

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

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

<pre>
    I'm using BOLT built from LLVM 18.1.4, I also see a segfault on 18.1.3 and 16 (though the backtrace is different on 16).

I run `bolt libjulia-internal.so.1.12.0.original -o libjulia-internal.so.1.12.0 --use-old-text -no-huge-pages` (`-no-huge-pages` is needed otherwise it doesn't use the old text). Here's the log
```
BOLT-INFO: shared object or position-independent executable detected
BOLT-INFO: Target architecture: x86_64
BOLT-INFO: BOLT version: 499f87882a4ba1837ec12a280478cf4cb0d2753d
BOLT-INFO: first alloc address is 0x0
BOLT-INFO: creating new program header table at address 0x61e000, offset 0x61e000
BOLT-WARNING: debug info will be stripped from the binary. Use -update-debug-sections to keep it.
BOLT-INFO: enabling relocation mode
BOLT-INFO: enabling -align-macro-fusion=all since no profile was specified
BOLT-WARNING: Failed to analyze 22 relocations
BOLT-INFO: forcing -jump-tables=move as PIC jump table was detected in function scm_to_julia_/1(*2)
BOLT-INFO: 0 out of 5651 functions in the binary (0.0%) have non-empty execution profile
BOLT-INFO: the input contains 597 (dynamic count : 0) opportunities for macro-fusion optimization that are going to be fixed
BOLT-INFO: 36848 instructions were shortened
BOLT-INFO: removed 12783 empty blocks
BOLT-INFO: UCE removed 0 blocks and 0 bytes of code.
BOLT-INFO: SCTC: patched 77 tail calls (71 forward) tail calls (6 backward) from a total of 77 while removing 0 double jumps and removing 52 basic blocks totalling 260 bytes of code. CTCs total execution count is 0 and the number of times CTCs are taken is 0.
BOLT-INFO: using original .text for new code with 0x1000 alignment
BOLT-INFO: setting _end to 0x6666a0
BOLT-INFO: patched build-id (flipped last bit)
```

I compiled with gcc with `-fno-reorder-blocks-and-partition` and `-Wl,--emit-relocs`.

Binaries are [here](https://github.com/Zentrik/temp-binary-store/) if you want them.

If you want to reproduce the segfault on x86_64 linux you can download julia here https://buildkite.com/julialang/julia-master/builds/34942#018e6d3a-e24c-4bad-8406-6fbb670d9309. You can then BOLT the [original binary](https://github.com/Zentrik/temp-binary-store/blob/main/libjulia-internal.so.1.12.0.original) or use the one I've already BOLTED [here](https://github.com/Zentrik/temp-binary-store/blob/main/libjulia-internal.so.1.12.0) and replace `libjulia-internal.so.1.12.0` in `lib/julia` with it. Then just run `bin/julia` from the root directory.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVl1v67jR_jXKzUACRcmSfOGLfKzfN8DpOUWb7aK9CShyZPGEIgWSOk721xdD2U6yNQ4WaIEgtqXh8JlnPp4RIeiDRdxlm7ts83Ajljg6v_sX2uj1y03v1NvuMePtBEvQ9gB33748Qb9oE2HwboIvX_7xFyi7oizqjN_DIwgTHAREEBDwMIjFRHB2NalAWAVlAxnv4uiWwwhxROiFfIleSAQdQOlhQI92PdVkfFtk7CFjt-v_R_CLhaxhvTMRjO6_L0aLXNuI3gpTBFeURckLVjivD9oKA7n7mR3k-RIwd0blEV8j5Nbl43LAfBYHDFnDCGzWsP98rgNYRIUKXBzRH3VA0BGUw2Az3kZYAqb4nFFAvikW-H_0mPE2pDfGHU7BNez0l34Sy_nj1_23rLqFMApPl_TfUUZwHmYXdNTO5toqnNEqYgtfUS5R9AZBYUQZUV3x9ST8ASMIL0dNRotHevzaNc9NfcU-pfsH-qCdpd_1djt0bddxUfei7KoWZckF71jddnKoZc8UbzfVtasH7UMEYYyTIJTyGAJRyF6vxSw9ikj1ZvEIs3cHLyYYUSj0sAYp4sULe21KZIxRAbphCBjfH727_u32b18fv_4feVfYLwfQdnBw1MZAjxCi1_OMaq3qVJXaCv9WwK8BIV9mJSLm6WAeUBL9A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