Skip to content

Stuck when compiling RISC-V #81440

Closed
Closed

Description

@RossComputerGuy

Found in Zig ziglang/zig#18872 with LLVM 17.

LLVM gets stuck in AttemptToFoldSymbolOffsetDifference for forever. The longest I've ran a build for is 14 hours on an Apple M1 Pro generating for riscv64-linux baseline.

#0  AttemptToFoldSymbolOffsetDifference (Asm=0x1fd10c10, Layout=0x7ffffffe3570, Addrs=0x0, InSet=true, A=@0x7ffffffe2d88: 0xff381058, B=@0x7ffffffe2d80: 0x0, Addend=@0x7ffffffe2d78: 0) at /home/ross/zig-bootstrap/llvm/lib/MC/MCExpr.cpp:596
#1  0x000000000c3a2bb8 in EvaluateSymbolicAdd (Asm=0x1fd10c10, Layout=0x7ffffffe3570, Addrs=0x0, InSet=true, LHS=..., RHS_A=0x0, RHS_B=0xff381070, RHS_Cst=0, Res=...) at /home/ross/zig-bootstrap/llvm/lib/MC/MCExpr.cpp:775
#2  0x000000000c3a399f in llvm::MCExpr::evaluateAsRelocatableImpl (this=0xff381088, Res=..., Asm=0x1fd10c10, Layout=0x7ffffffe3570, Fixup=0x0, Addrs=0x0, InSet=true) at /home/ross/zig-bootstrap/llvm/lib/MC/MCExpr.cpp:965
#3  0x000000000c3a2164 in llvm::MCExpr::evaluateAsAbsolute (this=0xff381088, Res=@0x7ffffffe3178: 4298713344, Asm=0x1fd10c10, Layout=0x7ffffffe3570, Addrs=0x0, InSet=true) at /home/ross/zig-bootstrap/llvm/lib/MC/MCExpr.cpp:583
#4  0x000000000c3a20c1 in llvm::MCExpr::evaluateKnownAbsolute (this=0xff381088, Res=@0x7ffffffe3178: 4298713344, Layout=...) at /home/ross/zig-bootstrap/llvm/lib/MC/MCExpr.cpp:567
#5  0x000000000c350d27 in llvm::MCAssembler::relaxDwarfLineAddr (this=0x1fd10c10, Layout=..., DF=...) at /home/ross/zig-bootstrap/llvm/lib/MC/MCAssembler.cpp:1099
#6  0x000000000c3512a1 in llvm::MCAssembler::relaxFragment (this=0x1fd10c10, Layout=..., F=...) at /home/ross/zig-bootstrap/llvm/lib/MC/MCAssembler.cpp:1178
#7  0x000000000c3513f3 in llvm::MCAssembler::layoutSectionOnce (this=0x1fd10c10, Layout=..., Sec=...) at /home/ross/zig-bootstrap/llvm/lib/MC/MCAssembler.cpp:1205
#8  0x000000000c3514d0 in llvm::MCAssembler::layoutOnce (this=0x1fd10c10, Layout=...) at /home/ross/zig-bootstrap/llvm/lib/MC/MCAssembler.cpp:1221
#9  0x000000000c34fc07 in llvm::MCAssembler::layout (this=0x1fd10c10, Layout=...) at /home/ross/zig-bootstrap/llvm/lib/MC/MCAssembler.cpp:843
#10 0x000000000c3504a8 in llvm::MCAssembler::Finish (this=0x1fd10c10) at /home/ross/zig-bootstrap/llvm/lib/MC/MCAssembler.cpp:944
#11 0x000000000c3c495e in llvm::MCObjectStreamer::finishImpl (this=0x176d3240) at /home/ross/zig-bootstrap/llvm/lib/MC/MCObjectStreamer.cpp:932
#12 0x000000000c397dba in llvm::MCELFStreamer::finishImpl (this=0x176d3240) at /home/ross/zig-bootstrap/llvm/lib/MC/MCELFStreamer.cpp:721
#13 0x000000000c3e9dee in llvm::MCStreamer::finish (this=0x176d3240, EndLoc=...) at /home/ross/zig-bootstrap/llvm/lib/MC/MCStreamer.cpp:1021
#14 0x000000000a60ce05 in llvm::AsmPrinter::doFinalization (this=0x1740d7b0, M=...) at /home/ross/zig-bootstrap/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2396
#15 0x000000000c76afad in llvm::FPPassManager::doFinalization (this=0x389ef1f0, M=...) at /home/ross/zig-bootstrap/llvm/lib/IR/LegacyPassManager.cpp:1499
#16 0x000000000c76b552 in (anonymous namespace)::MPPassManager::runOnModule (this=0x9326ed40, M=...) at /home/ross/zig-bootstrap/llvm/lib/IR/LegacyPassManager.cpp:1586
#17 0x000000000c766518 in llvm::legacy::PassManagerImpl::run (this=0x742575c0, M=...) at /home/ross/zig-bootstrap/llvm/lib/IR/LegacyPassManager.cpp:535
#18 0x000000000c76baed in llvm::legacy::PassManager::run (this=0x7ffffffe4160, M=...) at /home/ross/zig-bootstrap/llvm/lib/IR/LegacyPassManager.cpp:1677
#19 0x000000000292a368 in ZigLLVMTargetMachineEmitToFile (targ_machine_ref=0x17058820, module_ref=0x17050ee0, error_message=0x7ffffffe5da8, is_debug=true, is_small=false, time_report=false, tsan=false, lto=false, asm_filename=0x0, bin_filename=0x9348ace3 "zig.o", llvm_ir_filename=0x0, bitcode_filename=0x0)
    at /home/ross/zig-bootstrap/zig/src/zig_llvm.cpp:357
#20 0x00000000004a10bf in codegen_llvm_Object_emit__13929 (a0=0x7fffeb9994e8, a1=...) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:368532
#21 0x00000000004a1a7d in Compilation_emitLlvmObject__5131 (a0=0x7fffeb997ce0, a1=..., a2=..., a3=..., a4=0x7fffeb9994e8, a5=0x7ffffffebfe0) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:368669
#22 0x0000000000bdeed2 in link_File_emitLlvmObject__4801 (a0=..., a1=..., a2=0x7fffeb9994e8, a3=0x7ffffffebfe0) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:987633
#23 0x0000000000c71e80 in link_Elf_flushModule__4835 (a0=0x7fffeb998da8, a1=..., a2=0x7ffffffebfe0) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:1030814
#24 0x00000000008b7015 in link_Elf_linkWithLLD__4855 (a0=0x7fffeb998da8, a1=..., a2=0x7ffffffebfe0) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:703231
#25 0x00000000008d0f00 in link_Elf_flush__4834 (a0=0x7fffeb998da8, a1=..., a2=0x7ffffffebfe0) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:707770
#26 0x000000000064eb70 in link_File_flush__4777 (a0=0x7fffeb998da8, a1=..., a2=0x7ffffffebfe0) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:494132
#27 0x00000000004a1ba5 in Compilation_flush__5123 (a0=0x7fffeb997ce0, a1=..., a2=0x7ffffffebfe0) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:368732
#28 0x00000000004a7ab3 in Compilation_update__5122 (a0=0x7fffeb997ce0, a1=0x7ffffffebfe0) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:370261
#29 0x00000000004d3e4d in main_updateModule__216 (a0=0x7fffeb997ce0, a1=0 '\000') at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:379451
#30 0x0000000000502897 in main_buildOutputType__206 (a0=..., a1=..., a2=..., a3=...) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:390743
#31 0x000000000050e6db in main_mainArgs__194 (a0=..., a1=..., a2=...) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:394280
#32 0x00000000004257a9 in main_main__192 () at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:330827
#33 0x00000000004242aa in main (a0=318, a1=0x7fffffff46f8, a2=0x7fffffff50f0) at /home/ross/zig-bootstrap/out/build-zig-host/zig2.c:330446

Activity

  1. added
    llvm:mcMachine (object) code
    hangCompiler hang (infinite loop)
    and removed on Feb 12, 2024
  2. EugeneZelenko commented on Feb 12, 2024

    @EugeneZelenko
    Contributor

    Could you please try 18 or main branch?

  3. RossComputerGuy commented on Feb 12, 2024

    @RossComputerGuy
    MemberAuthor

    Will have to do the LLVM upgrade process unless you know of any easy way to reproduce this outside of Zig.

  4. dtcxzyw commented on Feb 12, 2024

    @dtcxzyw
    Member

    @RossComputerGuy Could you please provide the LLVM IR?

  5. added
    incompleteIssue not complete (e.g. missing a reproducer, build arguments, etc.)
    on Feb 12, 2024
  6. RossComputerGuy commented on Feb 15, 2024

    @RossComputerGuy
    MemberAuthor

    I'm having trouble sending the IR since it's 608MB.

  7. RossComputerGuy commented on Feb 15, 2024

    @RossComputerGuy
    MemberAuthor

    https://termbin.com/2oij ok, i think this should do.

  8. alexrp commented on Aug 24, 2024

    @alexrp
    Member

    I believe b06e736 fixed this.

  9. psilva261 commented on Jan 29, 2026

    @psilva261

    I believe b06e736 fixed this.

    Yeah this matches also my observation. At some point I got a profile, pointing me to this thread in the first place:

      %   cumulative   self              self     total           
     time   seconds   seconds    calls   s/call   s/call  name    
     70.69    119.48   119.48   508356     0.00     0.00  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&)
      2.41    123.56     4.08  3004970     0.00     0.00  llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel)
      1.19    125.58     2.02 29385170     0.00     0.00  llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int)
      0.61    126.61     1.03 171423097     0.00     0.00  void std::__introsort_loop<(anonymous namespace)::LoadedSlice*, long, __gnu_cxx::__ops::_Iter_comp_iter<adjustCostForPairing(llvm::SmallVectorImpl<(anonymous namespace)::LoadedSlice>&, (anonymous namespace)::LoadedSlice::Cost&)::{lambda((anonymous namespace)::LoadedSlice const&, (anonymous namespace)::LoadedSlice const&)#1}> >((anonymous namespace)::LoadedSlice*, (anonymous namespace)::LoadedSlice*, long, __gnu_cxx::__ops::_Iter_comp_iter<adjustCostForPairing(llvm::SmallVectorImpl<(anonymous namespace)::LoadedSlice>&, (anonymous namespace)::LoadedSlice::Cost&)::{lambda((anonymous namespace)::LoadedSlice const&, (anonymous namespace)::LoadedSlice const&)#1}>)
      0.52    127.49     0.89 21903373     0.00     0.00  llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const
    ...
    

    But with LLVM 19 and later I don't see this issue anymore

  10. EugeneZelenko commented on Jan 29, 2026

    @EugeneZelenko
    Contributor

    Could you please try 22 release candidate or main branch? Only most recent release is maintained.

  11. psilva261 commented on Feb 6, 2026

    @psilva261

    Yeah I now tried with release/22.x and it seems okay as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hangCompiler hang (infinite loop)incompleteIssue not complete (e.g. missing a reproducer, build arguments, etc.)llvm:mcMachine (object) code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions