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

    <tr>
        <th>Summary</th>
        <td>
            [Bug Report][LLD]Assertion `isa<X>(Val) && "cast_if_present<Ty>() argument of incompatible type!"' failed.
        </td>
    </tr>

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

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

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

<pre>
    when i compile my demo with the compile option: `-fuse-ld=lld`, Clang crashed
#### Error
```
ld.lld: llvm/llvm/include/llvm/Support/Casting.h:701: auto llvm::cast_if_present(Y*) [with X = lld::elf::InputSection; Y = lld::elf::SectionBase]: Assertion `isa<X>(Val) && "cast_if_present<Ty>() argument of incompatible type!"' failed.
```
#### Stack dump
```
ld.lld: /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/llvm/include/llvm/Support/Casting.h:701: auto llvm::cast_if_present(Y*) [with X = lld::elf::InputSection; Y = lld::elf::SectionBase]: Assertion `isa<X>(Val) && "cast_if_present<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/ld.lld --sysroot=/home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/../sysroot --be8 -EB -z relro --hash-style=gnu --eh-frame-hdr -m armelfb_linux_eabi -static -o ../exe/t_0070 /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/../sysroot/usr/lib/../lib/crt1.o /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/../sysroot/usr/lib/../lib/crti.o /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/BiSheng_arm32be/lib/clang/15.0.4/lib/linux/clang_rt.crtbegin-arm.o -Llib -L../work32be/lib -L/home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/../sysroot/lib/../lib -L/home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/../sysroot/usr/lib/../lib -L/home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/../sysroot/lib -L/home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/../sysroot/usr/lib -L/home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/../armeb-linux-gnueabi/lib /tmp/t_0070-544c1c.o -lst -lm -lc++ -lm --start-group /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/BiSheng_arm32be/lib/clang/15.0.4/lib/linux/libclang_rt.builtins-arm.a -l:libunwind.a -lc --end-group /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/BiSheng_arm32be/lib/clang/15.0.4/lib/linux/clang_rt.crtend-arm.o /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/../sysroot/usr/lib/../lib/crtn.o
 #0 0x0000562eeafc514c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/llvm/lib/Support/Unix/Signals.inc:569:0
 #1 0x0000562eeafc5203 PrintStackTraceSignalHandler(void*) /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/llvm/lib/Support/Unix/Signals.inc:636:0
 #2 0x0000562eeafc2e96 llvm::sys::RunSignalHandlers() /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/llvm/lib/Support/Signals.cpp:103:0
 #3 0x0000562eeafc4ab9 SignalHandler(int) /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/llvm/lib/Support/Unix/Signals.inc:407:0
 #4 0x00007f7e3be01980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007f7e3a8aae87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007f7e3a8ac7f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
 #7 0x00007f7e3a89c3fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
 #8 0x00007f7e3a89c472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #9 0x0000562eeb23aff0 auto llvm::cast_if_present<lld::elf::InputSection, lld::elf::SectionBase>(lld::elf::SectionBase*) /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/llvm/include/llvm/Support/Casting.h:701:0
#10 0x0000562eeb3e0c12 lld::elf::addArmInputSectionMappingSymbols() /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/lld/ELF/Arch/ARM.cpp:962:0
#11 0x0000562eeb380c0a (anonymous namespace)::Writer<llvm::object::ELFType<(llvm::support::endianness)0, false>>::finalizeSections() /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/lld/ELF/Writer.cpp:2184:0
#12 0x0000562eeb377a8d (anonymous namespace)::Writer<llvm::object::ELFType<(llvm::support::endianness)0, false>>::run() /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/lld/ELF/Writer.cpp:551:0
#13 0x0000562eeb3b0da8 void lld::elf::writeResult<llvm::object::ELFType<(llvm::support::endianness)0, false>>() /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/lld/ELF/Writer.cpp:100:0
#14 0x0000562eeb17cfdf lld::elf::LinkerDriver::link(llvm::opt::InputArgList&) /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/lld/ELF/Driver.cpp:2855:0
#15 0x0000562eeb16cf38 lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/lld/ELF/Driver.cpp:605:0
#16 0x0000562eeb169382 lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/lld/ELF/Driver.cpp:128:0
#17 0x0000562eeaee6779 lldMain(int, char const**, llvm::raw_ostream&, llvm::raw_ostream&, bool) /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/lld/tools/lld/lld.cpp:164:0
#18 0x0000562eeaee6b40 main /home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/open_source/BiSheng_arm32be_build_src/llvm/lld/tools/lld/lld.cpp:226:0
#19 0x00007f7e3a88dc87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#20 0x0000562eeaee59aa _start (/home/mls/workspace/BigEndien/Change/SDK_CPU_HCC/build/BiSheng_arm32be/arm32be_build_dir/./BiSheng_arm32be/bin/ld.lld+0x1e019aa)
clang-15: error: unable to execute command: Aborted
clang-15: error: linker command failed due to signal (use -v to see invocation)
```
#### compile command
`clang++  -Ih -I.  -O0  -static -Wno-deprecated -std=c++11 -o t_0070  t_0070.C -Llib -lst -lm -L lib -fuse-ld=lld`
#### demo: t_0070.C

```
#include <cerrno>

int test_it (void) {
 return 91 != 0 ;
}

void TEST__MAIN(void) {
 CVAL_HEADER_FUNC("The header <cerrno> is described in Table 43.");
 CVAL_VERIFY_FUNC(test_it(), "test_it()", 20);
}
```
`CVAL_HEADER_FUNC `and `CVAL_VERIFY_FUNC `are in `libst.a` which is in `lib/`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWlmP2zgS_jXsl4IEirSuh36QL0x2ndmguycz2ReBkmiLG4kySCodz69fkJIPOT1JdvZoB1jDgCSe9X1VKrGKZFqLneT8HoVzFC7vWG_qTt2_3eiay91d0VWH--eaSxBQdu1eNBzaA1S87eBZmBpMzU8V3d6ITiKaAYqwt-0195oK0WXTVCjCiCxg0TC5g1IxXfMK4SXCGSL09IeVUp0ayyM8_t1jU_l2GJpB03xqEVmPFyHLpq_4ueCx3-87ZRBZL5g2Qu78GtEsxoHty3rTDQPQDNGsZNrkYpvvFddcGkSSD4hkiKSAwrmD9xsguoRhZkQz3myHmzdy35tHXg6A5_DhD9qNTeZMcxQurQiZ1lzZMkuS0AzRxW-IrhBJ3rPGTU0iRCJAhFyLRxdPh6GpbcfUrm-5NNBtQUirA2ZE0XAwhz1HJECEIBLDlomGV_6LpE64fzSs_AhV3-6_oQBE1nXXWsrbRiOyfu7UR71npS2Zi91KVoJLy3_N5M4WPi7_mi_e_ZL_tFggsu72XOa669XY4dEaWs5US0nB86IXTZVrVZ41-n9N_wlNv9ussscV6L5ohQEGRb8DxS1fYDqojdlrKzdZI7LeCVP3hV927ZR0b6-6f_DSMiy07rlVNjBZwaiK4eW3LzMUrPxoFCv5OP2FMdFsKMI-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