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

    <tr>
        <th>Summary</th>
        <td>
            LLVM instrumented with BOLT segfaults
        </td>
    </tr>

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

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

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

<pre>
    Hi! I'm trying to use BOLT on LLVM itself to try to speed up the `rustc` compiler (https://github.com/rust-lang/rust/pull/94381).

When I instrument the LLVM library (built with `LLVM_BUILD_LLVM_DYLIB=ON`) and the `rustc` compiler later uses that instrumented library, it sometimes segfaults (https://github.com/rust-lang-ci/rust/runs/5425308791?check_suite_focus=true).

This is the output I get when instrumenting BOLT:
<details>
<summary>BOLT log</summary>

```
BOLT-WARNING: debug info will be stripped from the binary. Use -update-debug-sections to keep it.
BOLT-INFO: shared object or position-independent executable detected
BOLT-INFO: Target architecture: x86_64
BOLT-INFO: BOLT version: <unknown>
BOLT-INFO: first alloc address is 0x0
BOLT-INFO: creating new program header table at address 0x5a00000, offset 0x5a00000
BOLT-INFO: enabling relocation mode
BOLT-INFO: forcing -jump-tables=move for instrumentation
BOLT-INFO: enabling -align-macro-fusion=all since no profile was specified
BOLT-INFO: enabling lite mode
BOLT-WARNING: Failed to analyze 5229 relocations
BOLT-WARNING: Ignored 0 functions due to cold fragments.
BOLT-WARNING: 19 collisions detected while hashing binary objects. Use -v=1 to see the list.
BOLT-INSTRUMENTER: Number of indirect call site descriptors: 68972
BOLT-INSTRUMENTER: Number of indirect call target descriptors: 74099
BOLT-INSTRUMENTER: Number of function descriptors: 74099
BOLT-INSTRUMENTER: Number of branch counters: 1523333
BOLT-INSTRUMENTER: Number of ST leaf node counters: 602638
BOLT-INSTRUMENTER: Number of direct call counters: 4969
BOLT-INSTRUMENTER: Total number of counters: 2130940
BOLT-INSTRUMENTER: Total size of counters: 17047520 bytes (static alloc memory)
BOLT-INSTRUMENTER: Total size of string table emitted: 6995854 bytes in file
BOLT-INSTRUMENTER: Total size of descriptors: 128931880 bytes in file
BOLT-INSTRUMENTER: Profile will be saved to file /tmp/prof.fdata
BOLT-INFO: 0 out of 74859 functions in the binary (0.0%) have non-empty execution profile
BOLT-INFO: the input contains 15962 (dynamic count : 0) opportunities for macro-fusion optimization that are going to be fixed
BOLT-INFO: 4948511 instructions were shortened
BOLT-INFO: removed 10459 empty blocks
BOLT-INFO: merged 1 duplicate CFG edge
BOLT-INFO: removed 216 'repz' prefixes with estimated execution count of 0 times.
BOLT-INFO: UCE removed 65330 blocks and 4489397 bytes of code.
BOLT-INFO: SCTC: patched 0 tail calls (0 forward) tail calls (0 backward) from a total of 0 while removing 0 double jumps and removing 0 basic blocks totalling 0 bytes of code. CTCs total execution count is 0 and the number of times CTCs are taken is 0.
BOLT-INFO: output linked against instrumentation runtime library, lib entry point is 0xede32d0
BOLT-INFO: clear procedure is 0xede13a0
```
</details>

Is there something that looks out of place?

For instrumentation I use simply `llvm-bolt -instrument <LLVM lib> -o ...`. The LLVM lib is built with `-Wl,-q`. BOLT itself is built with LLVM version 14.0.0-rc1.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydV1tz2zYT_TXyC4YaXiXxQQ-JL62nrtNJnC_TJw9ILiXUIMESoC_59d9ZkLZkh0099XhEiVjs5ezZxaIw1dP2V7WII3G5iNeNcP2TanfCGTFYEh8_Xd0I04qrq__9LpSzpGteghA_bEdUiaETbk9isQr7wboST1GaplOaerGIN3vnOrtIPiziC_zvlNsPxRIC-MHygZbtbvqORzdojUeeJptoEefLRXi2CD-Mn9_21IpLoVrr-qGh1nm73jWtil7CKdgrBqWdeIAddolXbz9-vbw6u_Vfz_68uvy4SM4-XWMRBoRsq392X0uHTwBhISPdkWnEPdlcxKdARljTkFMNJC3tajloZ98bfVCqAwD90Fo8sjTOknCzzqNFclHuqby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