[llvm] [MC][RISCV][LoongArch] Add AlignFragment size if layout is available and not need insert nops (PR #76552)
Nathan Chancellor via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 5 08:36:12 PST 2024
nathanchance wrote:
I bisected a crash that I see in a particular translation unit when building the Linux kernel for RISC-V, [`arch/riscv/kernel/kexec_relocate.S`](https://elixir.bootlin.com/linux/v6.7-rc8/source/arch/riscv/kernel/kexec_relocate.S), which is built with `-mno-relax`, to this change.
`cvise --not-c` spits out:
```asm
.section ""
riscv_kexec_relocate:
la s6, f
.align 2
riscv_kexec_relocate_end:
.long riscv_kexec_relocate_end - riscv_kexec_relocate
```
```
$ clang --target=riscv64-linux-gnu -c -o /dev/null kexec_relocate.s
$ clang --target=riscv64-linux-gnu -c -o /dev/null kexec_relocate.s -mno-relax
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: clang --target=riscv64-linux-gnu -c -o /dev/null kexec_relocate.s -mno-relax
#0 0x0000000003629a08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x3629a08)
#1 0x0000000003627914 llvm::sys::RunSignalHandlers() (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x3627914)
#2 0x00000000035af2d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000ffffb09b87a0 (linux-vdso.so.1+0x7a0)
#4 0x00000000028fead8 llvm::RISCVAsmBackend::shouldInsertExtraNopBytesForCodeAlign(llvm::MCAlignFragment const&, unsigned int&) RISCVAsmBackend.cpp:0:0
#5 0x00000000033c99c8 AttemptToFoldSymbolOffsetDifference(llvm::MCAssembler const*, llvm::MCAsmLayout const*, llvm::DenseMap<llvm::MCSection const*, unsigned long, llvm::DenseMapInfo<llvm::MCSection const*, void>, llvm::detail::DenseMapPair<llvm::MCSection const*, unsigned long>> const*, bool, llvm::MCSymbolRefExpr const*&, llvm::MCSymbolRefExpr const*&, long&) MCExpr.cpp:0:0
#6 0x00000000033c92b8 EvaluateSymbolicAdd(llvm::MCAssembler const*, llvm::MCAsmLayout const*, llvm::DenseMap<llvm::MCSection const*, unsigned long, llvm::DenseMapInfo<llvm::MCSection const*, void>, llvm::detail::DenseMapPair<llvm::MCSection const*, unsigned long>> const*, bool, llvm::MCValue const&, llvm::MCValue const&, llvm::MCValue&) MCExpr.cpp:0:0
#7 0x00000000033c8ef8 llvm::MCExpr::evaluateAsRelocatableImpl(llvm::MCValue&, llvm::MCAssembler const*, llvm::MCAsmLayout const*, llvm::MCFixup const*, llvm::DenseMap<llvm::MCSection const*, unsigned long, llvm::DenseMapInfo<llvm::MCSection const*, void>, llvm::detail::DenseMapPair<llvm::MCSection const*, unsigned long>> const*, bool) const (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x33c8ef8)
#8 0x00000000033a332c llvm::MCAssembler::evaluateFixup(llvm::MCAsmLayout const&, llvm::MCFixup const&, llvm::MCFragment const*, llvm::MCValue&, llvm::MCSubtargetInfo const*, unsigned long&, bool&) const (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x33a332c)
#9 0x00000000033a5984 llvm::MCAssembler::layout(llvm::MCAsmLayout&) (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x33a5984)
#10 0x00000000033a6240 llvm::MCAssembler::Finish() (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x33a6240)
#11 0x00000000033c4f04 llvm::MCELFStreamer::finishImpl() (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x33c4f04)
#12 0x00000000034231f8 (anonymous namespace)::AsmParser::Run(bool, bool) AsmParser.cpp:0:0
#13 0x0000000002258898 cc1as_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x2258898)
#14 0x00000000022521e4 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#15 0x0000000003f1f800 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) Job.cpp:0:0
#16 0x00000000035af02c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x35af02c)
#17 0x0000000003f1ee34 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x3f1ee34)
#18 0x0000000003ee696c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x3ee696c)
#19 0x0000000003ee6bbc clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x3ee6bbc)
#20 0x0000000003eff03c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x3eff03c)
#21 0x00000000022515f0 clang_main(int, char**, llvm::ToolContext const&) (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x22515f0)
#22 0x000000000225fcc8 main (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x225fcc8)
#23 0x0000ffffb03209dc __libc_start_call_main (/lib64/libc.so.6+0x309dc)
#24 0x0000ffffb0320ab0 __libc_start_main at GLIBC_2.17 (/lib64/libc.so.6+0x30ab0)
#25 0x000000000224eb30 _start (/home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin/clang-18+0x224eb30)
clang: error: clang integrated assembler command failed with exit code 139 (use -v to see invocation)
ClangBuiltLinux clang version 18.0.0git (https://github.com/llvm/llvm-project 0731567a31e4ade97c27801045156a88c4589704)
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/nathan/tmp/cvise.fJmmocO8l2/install/llvm-bad/bin
clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
```
I've included the full preprocessed file below, in case you want full introspection.
<details>
<summary>Full <code>arch/riscv/kernel/kexec_relocate.s</code></summary>
```asm
.macro nops, num
.rept \num
nop
.endr
.endm
.macro asm_per_cpu dst sym tmp
ld \tmp, 32(tp)
slli \tmp, \tmp, 3
la \dst, __per_cpu_offset
add \dst, \dst, \tmp
ld \tmp, 0(\dst)
la \dst, \sym
add \dst, \dst, \tmp
.endm
.macro load_per_cpu dst ptr tmp
asm_per_cpu \dst \ptr \tmp
ld \dst, 0(\dst)
.endm
.macro load_global_pointer
.endm
.macro save_from_x6_to_x31
sd x6, 48(sp)
sd x7, 56(sp)
sd x8, 64(sp)
sd x9, 72(sp)
sd x10, 80(sp)
sd x11, 88(sp)
sd x12, 96(sp)
sd x13, 104(sp)
sd x14, 112(sp)
sd x15, 120(sp)
sd x16, 128(sp)
sd x17, 136(sp)
sd x18, 144(sp)
sd x19, 152(sp)
sd x20, 160(sp)
sd x21, 168(sp)
sd x22, 176(sp)
sd x23, 184(sp)
sd x24, 192(sp)
sd x25, 200(sp)
sd x26, 208(sp)
sd x27, 216(sp)
sd x28, 224(sp)
sd x29, 232(sp)
sd x30, 240(sp)
sd x31, 248(sp)
.endm
.macro restore_from_x6_to_x31
ld x6, 48(sp)
ld x7, 56(sp)
ld x8, 64(sp)
ld x9, 72(sp)
ld x10, 80(sp)
ld x11, 88(sp)
ld x12, 96(sp)
ld x13, 104(sp)
ld x14, 112(sp)
ld x15, 120(sp)
ld x16, 128(sp)
ld x17, 136(sp)
ld x18, 144(sp)
ld x19, 152(sp)
ld x20, 160(sp)
ld x21, 168(sp)
ld x22, 176(sp)
ld x23, 184(sp)
ld x24, 192(sp)
ld x25, 200(sp)
ld x26, 208(sp)
ld x27, 216(sp)
ld x28, 224(sp)
ld x29, 232(sp)
ld x30, 240(sp)
ld x31, 248(sp)
.endm
.section ".rodata"
.globl riscv_kexec_relocate ; .balign 4 ; riscv_kexec_relocate:
mv s0, a0
mv s1, a1
mv s2, a2
mv s3, a3
mv s4, a4
mv s5, zero
mv s6, zero
csrw 0x104, zero
csrw 0x144, zero
la s6, 1f
sub s6, s6, s4
csrw 0x105, s6
nop
.align 2
1:
ld t0, 0(s0)
addi s0, s0, 8
andi t1, t0, 0x1
beqz t1, 2f
andi s5, t0, ~0x1
j 1b
2:
andi t1, t0, 0x2
beqz t1, 2f
andi s0, t0, ~0x2
csrw 0x180, zero
jr s6
2:
andi t1, t0, 0x4
beqz t1, 2f
j 4f
2:
andi t1, t0, 0x8
beqz t1, 1b
andi t0, t0, ~0x8
li t3, ((1 << (12)) / 8)
3:
ld t1, (t0)
sd t1, (s5)
addi t0, t0, 8
addi s5, s5, 8
addi t3, t3, -0x1
beqz t3, 1b
j 3b
4:
mv a0, s3
mv a1, s2
mv a2, s1
mv a3, zero
mv a4, zero
mv a5, zero
mv a6, zero
mv a7, zero
mv s0, zero
mv s1, zero
mv s2, zero
mv s3, zero
mv s4, zero
mv s5, zero
mv s6, zero
mv s7, zero
mv s8, zero
mv s9, zero
mv s10, zero
mv s11, zero
mv t0, zero
mv t1, zero
mv t2, zero
mv t3, zero
mv t4, zero
mv t5, zero
mv t6, zero
csrw 0x141, zero
csrw 0x142, zero
csrw 0x140, zero
fence.i
jr a2
.type riscv_kexec_relocate STT_NOTYPE ; .set .L__sym_size_riscv_kexec_relocate, .-riscv_kexec_relocate ; .size riscv_kexec_relocate, .L__sym_size_riscv_kexec_relocate
riscv_kexec_relocate_end:
.section ".text"
.globl riscv_kexec_norelocate ; .balign 4 ; riscv_kexec_norelocate:
mv s0, a1
mv s1, a2
mv s2, a3
csrw 0x104, zero
csrw 0x144, zero
mv a0, s2
mv a1, s1
mv a2, s0
mv a3, zero
mv a4, zero
mv a5, zero
mv a6, zero
mv a7, zero
mv s0, zero
mv s1, zero
mv s2, zero
mv s3, zero
mv s4, zero
mv s5, zero
mv s6, zero
mv s7, zero
mv s8, zero
mv s9, zero
mv s10, zero
mv s11, zero
mv t0, zero
mv t1, zero
mv t2, zero
mv t3, zero
mv t4, zero
mv t5, zero
mv t6, zero
csrw 0x141, zero
csrw 0x142, zero
csrw 0x140, zero
csrw 0x105, a2
csrw 0x180, zero
.type riscv_kexec_norelocate STT_NOTYPE ; .set .L__sym_size_riscv_kexec_norelocate, .-riscv_kexec_norelocate ; .size riscv_kexec_norelocate, .L__sym_size_riscv_kexec_norelocate
.section ".rodata"
.globl riscv_kexec_relocate_size ; ; riscv_kexec_relocate_size: ; .long riscv_kexec_relocate_end - riscv_kexec_relocate ; .type riscv_kexec_relocate_size STT_OBJECT ; .set .L__sym_size_riscv_kexec_relocate_size, .-riscv_kexec_relocate_size ; .size riscv_kexec_relocate_size, .L__sym_size_riscv_kexec_relocate_size
```
</details>
<details>
<summary>Bisect log</summary>
```
# bad: [597086c60959dd5b3c032552e8b42dd1d053f233] DAG: Implement promotion for strict_fp_round (#74332)
# good: [7e405eb722e40c79b7726201d0f76b5dab34ba0f] [FuncAttrs] Don't infer `noundef` for functions with `sanitize_memory` attribute (#76691)
git bisect start '597086c60959dd5b3c032552e8b42dd1d053f233' '7e405eb722e40c79b7726201d0f76b5dab34ba0f'
# bad: [0faf46befa7c07e58034ef8c6a7cd4bd5715de0a] [coroutines][DPValue] Update DILocation in DPValue for hoisted dbg.declare (#76765)
git bisect bad 0faf46befa7c07e58034ef8c6a7cd4bd5715de0a
# good: [1fa18fee72639944291b1300a6995abde9b9f51a] [ConstraintElim] Add test case for #76713
git bisect good 1fa18fee72639944291b1300a6995abde9b9f51a
# bad: [c054d8f47d2642de722d64811d9908b6514ea012] [AArch64][LLVM]SME2.1 non-widening BFloat instructions now depend on … (#76222)
git bisect bad c054d8f47d2642de722d64811d9908b6514ea012
# bad: [0731567a31e4ade97c27801045156a88c4589704] [MC][RISCV][LoongArch] Add AlignFragment size if layout is available and not need insert nops (#76552)
git bisect bad 0731567a31e4ade97c27801045156a88c4589704
# good: [41a07e668c29e219ed2f26d61da8b6b3295ff967] [mlir][sparse] recognize NVidia 2:4 type for matmul (#76758)
git bisect good 41a07e668c29e219ed2f26d61da8b6b3295ff967
# good: [7122f55c639a00e719b6088249f4fca1810cf04c] [-Wunsafe-buffer-usage] Warning for unsafe invocation of span::data (#75650)
git bisect good 7122f55c639a00e719b6088249f4fca1810cf04c
# good: [d933b88b71b00461815667d7cd0bb2fecd8606db] [mlir][sparse] use a common util function to query the tensor level s… (#76764)
git bisect good d933b88b71b00461815667d7cd0bb2fecd8606db
# good: [7d81e072712f4e6a150561b5538ccebda289aa13] [SimplifyCFG] When only one case value is missing, replace default with that case (#76669)
git bisect good 7d81e072712f4e6a150561b5538ccebda289aa13
# first bad commit: [0731567a31e4ade97c27801045156a88c4589704] [MC][RISCV][LoongArch] Add AlignFragment size if layout is available and not need insert nops (#76552)
```
</details>
https://github.com/llvm/llvm-project/pull/76552
More information about the llvm-commits
mailing list