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

    <tr>
        <th>Summary</th>
        <td>
            BOLT crashes with -update-debug-sections on clang.
        </td>
    </tr>

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

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

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

<pre>
    llvm-bolt crashes when optimizing clang binary built with `-DLLVM_BUILD_TYPE=RelWithDebInfo`. Stacktrace is included below:

```
BOLT-INFO: shared object or position-independent executable detected
BOLT-INFO: Target architecture: x86_64
BOLT-INFO: BOLT version: 3f028c02ba6a24b7230fd5907a2b7ba076664a8b
BOLT-INFO: first alloc address is 0x0
BOLT-INFO: enabling relocation mode
BOLT-INFO: enabling lite mode
BOLT-WARNING: Failed to analyze 4027 relocations
BOLT-INFO: pre-processing profile using YAML profile reader
BOLT-INFO: forcing -jump-tables=move as PIC jump table was detected in function _ZN5clang13TreeTransformIN12_GLOBAL__N_120TemplateInstantiatorEE25TransformCXXNamedCastExprEPNS_16CXXNamedCastExprE.__uniq.55632760368638704870153814335850836202/1(*2)
BOLT-WARNING: 2 collisions detected while hashing binary objects. Use -v=1 to see the list.
BOLT-INFO: 10328 out of 137230 functions in the binary (7.5%) have non-empty execution profile
BOLT-INFO: 504 functions with profile could not be optimized
BOLT-INFO: the input contains 7820 (dynamic count : 475973) opportunities for macro-fusion optimization. Will fix instances on a hot path.
BOLT-INFO: 670206 instructions were shortened
BOLT-INFO: removed 1673 empty blocks
BOLT-INFO: ICF folded 733 out of 137545 functions in 4 passes. 1 functions had jump tables.
BOLT-INFO: Removing all identical functions will save 114.34 KB of code space. Folded functions were called 137574 times based on profile.
BOLT-INFO: simplified 178 out of 4471 loads from a statically computed address.
BOLT-INFO: dynamic loads simplified: 4828
BOLT-INFO: dynamic loads found: 86157
BOLT-INFO: inlined 1193 calls at 68 call sites in 2 iteration(s). Change in binary size: 113 bytes.
BOLT-INFO: 9050 PLT calls in the binary were optimized.
BOLT-INFO: basic block reordering modified layout of 7061 (5.16%) functions
BOLT-INFO: UCE removed 1 blocks and 7 bytes of code.
BOLT-INFO: splitting separates 11625846 hot bytes from 7895664 cold bytes (59.55% of split functions is hot).
BOLT-INFO: 176 Functions were reordered by LoopInversionPass
BOLT-INFO: hfsort+ reduced the number of chains from 10098 to 1125
BOLT-INFO: program-wide dynostats after all optimizations before SCTC and FOP:

            26368242 : executed forward branches
             3451088 : taken forward branches
             5197677 : executed backward branches
             2926258 : taken backward branches
             1636564 : executed unconditional branches
             2141777 : all function calls
              730319 : indirect calls
              351324 : PLT calls
           214479309 : executed instructions
            53996055 : executed load instructions
            27601931 : executed store instructions
              289730 : taken jump table branches
                   0 : taken unknown indirect branches
            33202483 : total branches
             8013910 : taken branches
            25188573 : non-taken conditional branches
             6377346 : taken conditional branches
            31565919 : all conditional branches

            25066576 : executed forward branches (-4.9%)
             1517139 : taken forward branches (-56.0%)
             6499343 : executed backward branches (+25.0%)
             2791736 : taken backward branches (-4.6%)
             1155686 : executed unconditional branches (-29.4%)
             1789661 : all function calls (-16.4%)
              730319 : indirect calls (=)
                   0 : PLT calls (-100.0%)
           212861320 : executed instructions (-0.8%)
            53991570 : executed load instructions (-0.0%)
            27601932 : executed store instructions (+0.0%)
              289730 : taken jump table branches (=)
                   0 : taken unknown indirect branches (=)
            32721605 : total branches (-1.4%)
             5464561 : taken branches (-31.8%)
            27257044 : non-taken conditional branches (+8.2%)
             4308875 : taken conditional branches (-32.4%)
            31565919 : all conditional branches (=)

BOLT-INFO: SCTC: patched 27 tail calls (25 forward) tail calls (2 backward) from a total of 29 while removing 2 double jumps and removing 21 basic blocks totalling 105 bytes of code. CTCs total execution count is 1298 and the number of times CTCs are taken is 1269.
 #0 0x0000000000f5b863 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt+0xf5b863)
 #1 0x0000000000f597dc llvm::sys::RunSignalHandlers() (DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt+0xf597dc)
 #2 0x0000000000f5bcea SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f23fd456200 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12200)
 #4 0x0000000001ba352b llvm::bolt::BinaryContext::addDebugFilenameToUnit(unsigned int, unsigned int, unsigned int) (DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt+0x1ba352b)
 #5 0x0000000001bb394d (anonymous namespace)::BinaryEmitter::emitFunctionBody(llvm::bolt::BinaryFunction&, bool, bool) BinaryEmitter.cpp:0:0
 #6 0x0000000001bb4895 (anonymous namespace)::BinaryEmitter::emitFunction(llvm::bolt::BinaryFunction&, bool) BinaryEmitter.cpp:0:0
 #7 0x0000000001bb428b (anonymous namespace)::BinaryEmitter::emitFunctions()::$_3::operator()(std::vector<llvm::bolt::BinaryFunction*, std::allocator<llvm::bolt::BinaryFunction*>> const&) const BinaryEmitter.cpp:0:0
 #8 0x0000000001bb2472 llvm::bolt::emitBinaryContext(llvm::MCStreamer&, llvm::bolt::BinaryContext&, llvm::StringRef) (DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt+0x1bb2472)
 #9 0x0000000000fbd074 llvm::bolt::RewriteInstance::emitAndLink() (DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt+0xfbd074)
#10 0x0000000000fb54d0 llvm::bolt::RewriteInstance::run() (DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt+0xfb54d0)
#11 0x0000000000b31a6d main (DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt+0xb31a6d)
#12 0x00007f23fceac7fd __libc_start_main ./csu/../csu/libc-start.c:332:16
#13 0x0000000000b2fa0a _start (DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt+0xb2fa0a)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt DIR/source/llvm-project/relwithdeb/pgo-labels/build/bin/clang-15 -o pgo-labels/build/bin/clang-15-bolt -b pgo-labels-compiler.yaml -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions -update-debug-sections -split-all-cold -dyno-stats -icf=1 -use-gnu-stack -inline-small-functions -simplify-rodata-loads -plt=hot
Command terminated by signal 11
        Command being timed: "DIR/source/llvm-project/relwithdeb/stage1/install/bin/llvm-bolt DIR/source/llvm-project/relwithdeb/pgo-labels/build/bin/clang-15 -o pgo-labels/build/bin/clang-15-bolt -b pgo-labels-compiler.yaml -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions -update-debug-sections -split-all-cold -dyno-stats -icf=1 -use-gnu-stack -inline-small-functions -simplify-rodata-loads -plt=hot”
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWktz2zgS_jXyBUUVHnwefLAle9a1HsflOJuZvahAErI4oUgtAMbW_PrtBqkHFUpWdtaHrVqXo1AkuvH160MDdFrn68uy_L700rq0JNPSLJQhrwtVkXpli2XxZ1G9kKyU8JkWldRrkjYFDH0t7IKMQupN7-__8evs-svd_XT2_PvjzUhMn1T5FR5PVXpXzWsYNCafrcy-WS0zRQpDiiorm1zlJFVl_ToSVyM6HdHNZ0i7X_f1-tP9s3f3cPsJhhGzkBrE6vQPlVlSa7KqTWGLuvKKKlcrBR-VJepNZY2VaalIriyMVPmArmepX5QlUmeLAgc1WuHttzichf7AePxCvittYDr8LuaUxxnlqQwl99OICzrPg4RGkqdRKmkUhqEv43RA1bzQBmYuyzojMs-1MgbdQt-GbFYVWIJR0OCsTKK1ZFnn6tTQEiw6HPT16unh7uEXHHcrixLcaGsiK1mu_1TEpzzam8AMKF9p5a10nQFYnAIu56CFNO7b71e_3m9vaSVzpYfsrnWGo70_muXKcxEykC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