Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig stuck at llvm emit object on riscv64-linux sifive_u74 #18872

Open
RossComputerGuy opened this issue Feb 9, 2024 · 16 comments · May be fixed by #21183
Open

zig stuck at llvm emit object on riscv64-linux sifive_u74 #18872

RossComputerGuy opened this issue Feb 9, 2024 · 16 comments · May be fixed by #21183
Labels
arch-riscv RISCV-32 and RISCV-64 backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior upstream An issue with a third party project that Zig uses.
Milestone

Comments

@RossComputerGuy
Copy link
Sponsor Contributor

RossComputerGuy commented Feb 9, 2024

Zig Version

0.12.0-dev.2058+04ac028a2

Steps to Reproduce and Observed Behavior

Run zig build -Dcpu=sifive_u74 in this repo on a Sifive U74 system such as a VisionFive 2. This can also occur with zig-bootstrap (even if updated to use zig master).

After waiting 3 hours or longer, nothing happens during the LLVM Emit Object stage for building the zig executable itself. On the other hand, the build runnable builds in 6 minutes on the VisionFive 2 so this likely isn't just a LLVM is entirely broken.

Expected Behavior

Zig should finish.

@RossComputerGuy RossComputerGuy added the bug Observed behavior contradicts documented or intended behavior label Feb 9, 2024
@Vexu
Copy link
Member

Vexu commented Feb 9, 2024

Are you also setting -Dtarget=riscv64-linux? Without it I get a panic on this line (which is a bug in itself #18876).

With riscv32 I get error: unsupported arch and with riscv64 error: root struct of file 'os.linux.riscv64' has no member named 'ucontext_t'.

@RossComputerGuy
Copy link
Sponsor Contributor Author

I have a few PR's merged, the RISC-V glibc, CPU model, and the other one. I don't set the target when I run on the VisionFive2 but I do when zig-bootstrap or cross compiling.

@Vexu
Copy link
Member

Vexu commented Feb 9, 2024

By the mention of the glibc PR I'm guessing that you're linking libc?

@RossComputerGuy
Copy link
Sponsor Contributor Author

No, I'm not linking libc. I just have the patch.

@Vexu
Copy link
Member

Vexu commented Feb 9, 2024

Then I'm not sure how you're getting to LLVM Emit Object unless you're talking about building the build script? Does zig build -Dno-lib -Dcpu=sifive_u74 -Dtarget=riscv64-linux --help print usage for you?

@RossComputerGuy
Copy link
Sponsor Contributor Author

RossComputerGuy commented Feb 9, 2024

It's not with the builder, it's with building a zig test or zig executable itself. It just gets stuck. Tried getting the tests for std itself to run but it's been stuck for like 14 hours.

$ ~/zig/zig test -ODebug -I /home/user/ExpidusOS/zig/test -Mroot=/home/user/ExpidusOS/zig/lib/std/std.zig --cache-dir /home/user/ExpidusOS/zig/zig-cache --global-cache-dir /home/user/.cache/zig --name test --zig-lib-dir /home/user/ExpidusOS/zig/lib -target riscv64-linux-musl -lc -mcpu baseline_rv64 --verbose-cc
LLVM Emit Object..

~/zig is an rsync copy of a baseline_rv64 zig-bootstrap build of Zig. You can try reproducing this with building zig-bootstrap with riscv64-linux sifive_u74.

@RossComputerGuy
Copy link
Sponsor Contributor Author

I've found the problem:

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&)

This is where LLVM gets stuck.

Backtrace:

Thread 1 "zig" received signal SIGINT, Interrupt.
0x0000ffffeea65b20 in 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&) ()
   from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
(gdb) bt
#0  0x0000ffffeea65b20 in 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&) ()
   from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
#1  0x0000ffffeea66044 in 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::MCSymbolRefExpr const*, llvm::MCSymbolRefExpr const*, long, llvm::MCValue&) () from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
#2  0x0000ffffeea650d8 in 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 ()
   from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
#3  0x0000ffffeea39e5c in llvm::MCAssembler::evaluateFixup(llvm::MCAsmLayout const&, llvm::MCFixup const&, llvm::MCFragment const*, llvm::MCValue&, unsigned long&, bool&) const ()
   from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
#4  0x0000ffffeea3de88 in llvm::MCAssembler::layout(llvm::MCAsmLayout&) () from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
#5  0x0000ffffeea3e050 in llvm::MCAssembler::Finish() () from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
#6  0x0000ffffeda6e600 in llvm::AsmPrinter::doFinalization(llvm::Module&) () from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
#7  0x0000ffffed1b5410 in llvm::FPPassManager::doFinalization(llvm::Module&) () from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
#8  0x0000ffffed1c0180 in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /nix/store/y0pcvaby42h59svn6xzf08ivcs60py6s-llvm-17.0.6-lib/lib/libLLVM-17.so
#9  0x0000000003e09974 in ZigLLVMTargetMachineEmitToFile (targ_machine_ref=0x4446930, module_ref=0x43f8970, error_message=0xfffffffe7400, is_debug=true, is_small=false,
    time_report=false, tsan=false, lto=false, asm_filename=0x0, bin_filename=0x439889e3 "zig.o", llvm_ir_filename=0x0, bitcode_filename=0x0)
    at /home/ross/ExpidusOS/zig/src/zig_llvm.cpp:357
#10 0x000000000194fe94 in codegen.llvm.Object.emit (self=0x442a390, options=...) at /home/ross/ExpidusOS/zig/src/codegen/llvm.zig:1273
#11 0x000000000195ac40 in Compilation.emitLlvmObject (comp=0x4428b90, arena=..., default_emit=..., bin_emit_loc=..., llvm_object=0x442a390, prog_node=0xfffffffeccf8)
    at Compilation.zig:2661
#12 0x000000000244e6cc in link.File.emitLlvmObject (base=..., arena=..., llvm_object=0x442a390, prog_node=0xfffffffeccf8) at link.zig:1001
#13 0x000000000201cc60 in link.Elf.flushModule (self=0x4429ca8, arena=..., prog_node=0xfffffffeccf8) at /home/ross/ExpidusOS/zig/src/link/Elf.zig:1045
#14 0x0000000002013da0 in link.Elf.linkWithLLD (self=0x4429ca8, arena=..., prog_node=0xfffffffeccf8) at /home/ross/ExpidusOS/zig/src/link/Elf.zig:2333
#15 0x0000000001c93588 in link.Elf.flush (self=0x4429ca8, arena=..., prog_node=0xfffffffeccf8) at /home/ross/ExpidusOS/zig/src/link/Elf.zig:1032
#16 0x000000000199bbf8 in link.File.flush (base=0x4429f60, arena=..., prog_node=0xfffffffeccf8) at link.zig:588
#17 0x000000000199b218 in Compilation.flush (comp=0x4428b90, arena=..., prog_node=0xfffffffeccf8) at Compilation.zig:2322
#18 0x000000000199ea10 in Compilation.update (comp=0x4428b90, main_progress_node=0xfffffffeccf8) at Compilation.zig:2313
#19 0x00000000019cab8c in main.updateModule (comp=0x4428b90, color=auto) at main.zig:4502
#20 0x00000000019e7648 in main.buildOutputType (gpa=..., arena=..., all_args=..., arg_mode=...) at main.zig:3355
#21 0x00000000017eff20 in main.mainArgs (gpa=..., arena=..., args=...) at main.zig:277
#22 0x00000000017ece10 in main.main () at main.zig:223

@Vexu
Copy link
Member

Vexu commented Feb 9, 2024

I was able to reproduce it.

@Vexu Vexu added upstream An issue with a third party project that Zig uses. arch-riscv RISCV-32 and RISCV-64 backend-llvm The LLVM backend outputs an LLVM IR Module. labels Feb 9, 2024
@Vexu Vexu added this to the 0.15.0 milestone Feb 9, 2024
@RossComputerGuy
Copy link
Sponsor Contributor Author

That's great, I thought I was going crazy yesterday when Zig was just constantly getting stuck. There's been times where zig-bootstrap work with baseline but there's times where it doesn't work. Should an issue be opened on LLVM's side reporting this bug?

@Vexu
Copy link
Member

Vexu commented Feb 9, 2024

Yes but it'd be good to investigate a bit first. You happen to have a debug build of LLVM handy? I'll start the build otherwise.

@RossComputerGuy
Copy link
Sponsor Contributor Author

RossComputerGuy commented Feb 9, 2024

I don't have one right now but I can get one built in like 20 minutes.

@Vexu
Copy link
Member

Vexu commented Feb 9, 2024

I'll let you have the honors. And you might also benefit from having a debug build in the future seeing as you'll probably continue tinkering with riscv.

@RossComputerGuy
Copy link
Sponsor Contributor Author

Yeah, it's already 14% done (Apple M1 Pro go brrr). Having this debug build will definitely be useful.

@RossComputerGuy
Copy link
Sponsor Contributor Author

I'm having some issues with building Zig with a debug build of LLVM 17 on my M1 Pro system (the fastest system I got). I'll try it one more time and if that doesn't work, I'll try my desktop which should have enough RAM but if neither of those work I might need you (@Vexu) to try it.

@RossComputerGuy
Copy link
Sponsor Contributor Author

#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

I got a backtrace finally.

@alexrp
Copy link
Contributor

alexrp commented Aug 12, 2024

Potentially fixed by llvm/llvm-project@b06e736? Should re-evaluate this with LLVM 19.

@alexrp alexrp linked a pull request Aug 24, 2024 that will close this issue
7 tasks
alexrp added a commit to alexrp/zig that referenced this issue Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-riscv RISCV-32 and RISCV-64 backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants