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

    <tr>
        <th>Summary</th>
        <td>
            BOLT optimization fails with "symbol is already defined"
        </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>
    I have tried to use BOLT `16.0.0` to optimize a position independent shared library (the Rust compiler, basically), which was itself compiled with LLVM.

This is the command that I execute:
```
$ llvm-bolt librustc_driver.so -data <profiles> -o <otput> -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions -split-all-cold -jump-tables=move -icf=1 -update-debug-sections -dyno-stats
```
The library can be found [here](https://ci-artifacts.rust-lang.org/rustc-builds/33a2c2487ac5d9927830ea4c1844335c6b9f77db/rustc-nightly-x86_64-unknown-linux-gnu.tar.xz), at `rustc-nightly-x86_64-unknown-linux-gnu/rustc/lib/`.

The process ends with the following error:

<details>
<summary>Output</summary>

```
2023-07-12T16:32:40.4406752Z BOLT-INFO: shared object or position-independent executable detected
2023-07-12T16:32:40.4407127Z BOLT-INFO: Target architecture: x86_64
2023-07-12T16:32:40.4407424Z BOLT-INFO: BOLT version: <unknown>
2023-07-12T16:32:40.4407735Z BOLT-INFO: first alloc address is 0x0
2023-07-12T16:32:40.4408152Z BOLT-INFO: creating new program header table at address 0x4400000, offset 0x4400000
2023-07-12T16:32:40.4408494Z BOLT-INFO: enabling relocation mode
2023-07-12T16:32:40.6729388Z BOLT-INFO: enabling lite mode
2023-07-12T16:32:44.1620976Z BOLT-WARNING: split function detected on input : _ZN10__cxxabiv111__terminateEPFvvE.cold.0/1. The support is limited in relocation mode
2023-07-12T16:32:44.1621917Z BOLT-WARNING: disabling lite mode (-lite) when split functions are present
2023-07-12T16:32:45.3463359Z BOLT-WARNING: Failed to analyze 93 relocations
2023-07-12T16:32:45.3488885Z BOLT-INFO: pre-processing profile using branch profile reader
2023-07-12T16:33:00.0180927Z BOLT-WARNING: 549 collisions detected while hashing binary objects. Use -v=1 to see the list.
2023-07-12T16:33:00.6072163Z BOLT-WARNING: skipped 2 functions due to cold fragments
2023-07-12T16:33:01.7282745Z BOLT-WARNING: 31 (0.2% of all profiled) functions have invalid (possibly stale) profile. Use -report-stale to see the list.
2023-07-12T16:33:01.7283503Z BOLT-INFO: 16122 out of 116266 functions in the binary (13.9%) have non-empty execution profile
2023-07-12T16:33:01.7286943Z BOLT-WARNING: 81943911 out of 119144256074 samples in the binary (0.1%) belong to functions with invalid (possibly stale) profile.
2023-07-12T16:33:01.7287718Z BOLT-INFO: 454 functions with profile could not be optimized
2023-07-12T16:33:01.7288344Z BOLT-INFO: profile for 13896 objects was ignored
2023-07-12T16:33:01.7288957Z BOLT-INFO: the input contains 9807 (dynamic count : 802623545) opportunities for macro-fusion optimization. Will fix instances on a hot path.
2023-07-12T16:33:03.0229274Z BOLT-INFO: validate-mem-refs updated 88 object references
2023-07-12T16:33:03.1214169Z BOLT-INFO: 819530 instructions were shortened
2023-07-12T16:33:03.2268840Z BOLT-INFO: removed 5158 empty blocks
2023-07-12T16:33:07.6211474Z BOLT-INFO: ICF folded 8404 out of 116682 functions in 8 passes. 227 functions had jump tables.
2023-07-12T16:33:07.6212281Z BOLT-INFO: Removing all identical functions will save 1417.75 KB of code space. Folded functions were called 6914603 times based on profile.
2023-07-12T16:33:13.4416956Z BOLT-INFO: basic block reordering modified layout of 10456 functions (64.86% of profiled, 9.66% of total)
2023-07-12T16:33:13.9116858Z BOLT-INFO: UCE removed 1161 blocks and 2331 bytes of code.
2023-07-12T16:33:14.8035830Z BOLT-INFO: splitting separates 13716120 hot bytes from 5165217 cold bytes (72.64% of split functions is hot).
2023-07-12T16:33:14.8165680Z BOLT-INFO: 217 Functions were reordered by LoopInversionPass
2023-07-12T16:33:16.8628674Z BOLT-INFO: hfsort+ reduced the number of chains from 16416 to 5396
2023-07-12T16:33:17.1535077Z BOLT-INFO: program-wide dynostats after all optimizations before SCTC and FOP:
2023-07-12T16:33:17.1535404Z 
2023-07-12T16:33:17.1535560Z 74969461148 : executed forward branches
2023-07-12T16:33:17.1535891Z 7309842165 : taken forward branches
2023-07-12T16:33:17.1536488Z 14321857064 : executed backward branches
2023-07-12T16:33:17.1536817Z 8449773791 : taken backward branches
2023-07-12T16:33:17.1537151Z 4016050841 : executed unconditional branches
2023-07-12T16:33:17.1537472Z           5634561457 : all function calls
2023-07-12T16:33:17.1537750Z           2836938796 : indirect calls
2023-07-12T16:33:17.1538028Z            105516367 : PLT calls
2023-07-12T16:33:17.1538326Z         643870545435 : executed instructions
2023-07-12T16:33:17.1538638Z         161262146913 : executed load instructions
2023-07-12T16:33:17.1538953Z          93862246224 : executed store instructions
2023-07-12T16:33:17.1539270Z 1436249615 : taken jump table branches
2023-07-12T16:33:17.1539587Z 0 : taken unknown indirect branches
2023-07-12T16:33:17.1539881Z          93307369053 : total branches
2023-07-12T16:33:17.1540158Z          19775666797 : taken branches
2023-07-12T16:33:17.1540554Z          73531702256 : non-taken conditional branches
2023-07-12T16:33:17.1540884Z          15759615956 : taken conditional branches
2023-07-12T16:33:17.1541187Z 89291318212 : all conditional branches
2023-07-12T16:33:17.1541373Z 
2023-07-12T16:33:17.1541606Z          69667033904 : executed forward branches (-7.1%)
2023-07-12T16:33:17.1542015Z           3894884377 : taken forward branches (-46.7%)
2023-07-12T16:33:17.1542347Z 19624284308 : executed backward branches (+37.0%)
2023-07-12T16:33:17.1542748Z           8305616293 : taken backward branches (-1.7%)
2023-07-12T16:33:17.1543181Z 2880036565 : executed unconditional branches (-28.3%)
2023-07-12T16:33:17.1543513Z           5634561457 : all function calls (=)
2023-07-12T16:33:17.1543939Z           2836938796 : indirect calls (=)
2023-07-12T16:33:17.1544167Z            105516367 : PLT calls (=)
2023-07-12T16:33:17.1544468Z         640268950085 : executed instructions (-0.6%)
2023-07-12T16:33:17.1544733Z         161262146913 : executed load instructions (=)
2023-07-12T16:33:17.1545001Z 93862246224 : executed store instructions (=)
2023-07-12T16:33:17.1545260Z 1436249615 : taken jump table branches (=)
2023-07-12T16:33:17.1545623Z                    0 : taken unknown indirect branches (=)
2023-07-12T16:33:17.1545964Z          92171354777 : total branches (-1.2%)
2023-07-12T16:33:17.1546244Z          15080537235 : taken branches (-23.7%)
2023-07-12T16:33:17.1546612Z          77090817542 : non-taken conditional branches (+4.8%)
2023-07-12T16:33:17.1546949Z 12200500670 : taken conditional branches (-22.6%)
2023-07-12T16:33:17.1547206Z          89291318212 : all conditional branches (=)
2023-07-12T16:33:17.1547353Z 
2023-07-12T16:33:17.5858718Z BOLT-INFO: SCTC: patched 2851 tail calls (2842 forward) tail calls (9 backward) from a total of 2851 while removing 12 double jumps and removing 2782 basic blocks totalling 13910 bytes of code. CTCs total execution count is 3276925 and the number of times CTCs are taken is 2393901.
2023-07-12T16:33:24.5533047Z <unknown>:0: error: symbol '_ZNSt8numpunctIcE22_M_initialize_numpunctEP15__locale_struct.cold.0/1' is already defined
2023-07-12T16:33:24.5534301Z <unknown>:0: error: symbol '_ZNSt10moneypunctIcLb1EE24_M_initialize_moneypunctEP15__locale_structPKc.cold.0/1' is already defined
2023-07-12T16:33:24.5538671Z <unknown>:0: error: symbol '_ZNSt7__cxx1110moneypunctIcLb1EE24_M_initialize_moneypunctEP15__locale_structPKc.cold.0/1' is already defined
2023-07-12T16:33:29.9833663Z BOLT-ERROR: Emission failed.
```

</details>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWllv2zi7_jXKDSGB-3KRizaJD4rp1xb9MmeA3AS0RMecyqJBUln66w9Iybbspl5mLo4xk8Jannd_Xr6kdQj2qTPmumAfC3Z7pfu4dP76Dzf_6dqruWverj-BpX42IHprGhAd6IMBH79-vgcFh4hXsIIFh-mGW0e7sj8N0GDtgo3WdcB2jVmbrjFdBGGpvWlAa-de-zdQYBmXBnzv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