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

Tracking Issue for core compilation to C #10

Open
2 of 6 tasks
zlfn opened this issue Oct 14, 2024 · 5 comments
Open
2 of 6 tasks

Tracking Issue for core compilation to C #10

zlfn opened this issue Oct 14, 2024 · 5 comments
Labels
bug Something isn't working external This issue requires contribute to external tools long term plan It's a work that requires a lot of effort to implement tracking-issue A tracking issue for unstable or not implemented feature

Comments

@zlfn
Copy link
Owner

zlfn commented Oct 14, 2024

I tried core compilation with llvm-cbe, but the following problem occurs.

Missing intrinsics

u128/i128 (in core::{fmt, num, slice})

llvm-cbe does not support data types that exceed 64 bits, and of course SDCC does, so it must be removed before compilation.
There is already a function to turn off floating point fmt as a cfg option (no_fp_fmt_parse), so I'm going to make similar function and contribute to Rust. (like no_128_fmt_parse)
I think It can be solved by removing the 128bits parts that don't used with llvm-link.

LLVM-CBE error 1

  • (In progress)
    When hiding all the above issues by editing llvm-ir, I get an llvm-cbe error.
    This error occured in CBackend.cpp#L4558

I think it's caused by an unsupported instruction, but I'm not sure exactly where it happened.

elemT == funT->getParamType(i) in:   ret void @
elemT == funT->getParamType(i)
UNREACHABLE executed at /home/zlfn/rust-z80/llvm-project/llvm/projects/llvm-cbe/lib/Target/CBackend/CBackend.cpp:5754!
 #0 0x000056109454cd72 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/zlfn/rust-z80/llvm-project/llvm/lib/Support/Unix/Signals.inc:602:22
 #1 0x000056109454d143 PrintStackTraceSignalHandler(void*) /home/zlfn/rust-z80/llvm-project/llvm/lib/Support/Unix/Signals.inc:675:1
 #2 0x000056109454a881 llvm::sys::RunSignalHandlers() /home/zlfn/rust-z80/llvm-project/llvm/lib/Support/Signals.cpp:104:20
 #3 0x000056109454c6cd SignalHandler(int) /home/zlfn/rust-z80/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007efc0acc81d0 (/usr/lib/libc.so.6+0x3d1d0)
 #5 0x00007efc0ad213f4 (/usr/lib/libc.so.6+0x963f4)
 #6 0x00007efc0acc8120 raise (/usr/lib/libc.so.6+0x3d120)
 #7 0x00007efc0acaf4c3 abort (/usr/lib/libc.so.6+0x244c3)
 #8 0x0000561094484c6d bindingsErrorHandler(void*, char const*, bool) /home/zlfn/rust-z80/llvm-project/llvm/lib/Support/ErrorHandling.cpp:221:55
 #9 0x00005610932d6fc8 std::pair<std::__strip_reference_wrapper<std::decay<llvm::AttributeList>::type>::__type, std::__strip_reference_wrapper<std::decay<llvm::CallingConv::._anon_132>::type>::__type> std::make_pair<llvm::AttributeList, llvm::CallingConv::._anon_132>(llvm::AttributeList&&, llvm::CallingConv::._anon_132&&) /usr/include/c++/14.2.1/bits/stl_pair.h:1132:5
#10 0x00005610932d0b67 llvm_cbe::CWriter::printIntrinsicDefinition(llvm::FunctionType*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, llvm::raw_ostream&) /home/zlfn/rust-z80/llvm-project/llvm/projects/llvm-cbe/lib/Target/CBackend/CBackend.cpp:4563:7
#11 0x00005610932d2052 llvm_cbe::CWriter::printIntrinsicDefinition(llvm::Function&, llvm::raw_ostream&) /home/zlfn/rust-z80/llvm-project/llvm/projects/llvm-cbe/lib/Target/CBackend/CBackend.cpp:4777:27
#12 0x00005610932ca44e llvm_cbe::CWriter::generateHeader(llvm::Module&) /home/zlfn/rust-z80/llvm-project/llvm/projects/llvm-cbe/lib/Target/CBackend/CBackend.cpp:3398:3
#13 0x00005610932c3f17 llvm_cbe::CWriter::doFinalization(llvm::Module&) /home/zlfn/rust-z80/llvm-project/llvm/projects/llvm-cbe/lib/Target/CBackend/CBackend.cpp:2400:50
#14 0x0000561093cdf43b llvm::FPPassManager::doFinalization(llvm::Module&) /home/zlfn/rust-z80/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1499:13
#15 0x0000561093cdfa0e (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/zlfn/rust-z80/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1586:13
#16 0x0000561093cda448 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/zlfn/rust-z80/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:13
#17 0x0000561093ce0045 llvm::legacy::PassManager::run(llvm::Module&) /home/zlfn/rust-z80/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1678:1
#18 0x0000561090a3443c compileModule(char**, llvm::LLVMContext&) /home/zlfn/rust-z80/llvm-project/llvm/projects/llvm-cbe/tools/llvm-cbe/llvm-cbe.cpp:352:12
#19 0x0000561090a337cd main /home/zlfn/rust-z80/llvm-project/llvm/projects/llvm-cbe/tools/llvm-cbe/llvm-cbe.cpp:204:35
#20 0x00007efc0acb0e08 (/usr/lib/libc.so.6+0x25e08)
#21 0x00007efc0acb0ecc __libc_start_main (/usr/lib/libc.so.6+0x25ecc)
#22 0x0000561090a32fa5 _start (/home/zlfn/rust-gb/source/out/../../ext/llvm-cbe+0x922fa5)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/zlfn/rust-gb/source/out/../../ext/llvm-cbe core-2ed864bedde1aa0b.ll

LLVM-CBE errror 2

  • (In Progress)
    After upgrading the version to LLVM-19, the following error occurs. It seems to be an error related to LegacyPassManager, and I think it will be resolved by migrating to ModulePassManager. (but not sure)
#0 0x000055d2da99280c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/zlfn/rust-gb/ext/./llvm-cbe+0x22ea80c)
#1 0x000055d2da98fc9b SignalHandler(int) Signals.cpp:0:0
#2 0x00007fabac4bf1d0 (/usr/lib/libc.so.6+0x3d1d0)
#3 0x000055d2d99625a5 llvm_cbe::CWriter::generateHeader(llvm::Module&) (/home/zlfn/rust-gb/ext/./llvm-cbe+0x12ba5a5)
#4 0x000055d2da1a23b0 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> llvm::function_ref<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> ()>::callback_fn<llvm::FPPassManager::runOnFunction(llvm::Function&)::'lambda'()>(long) LegacyPassManager.cpp:0:0
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/zlfn/rust-gb/ext/./llvm-cbe core-c7f0b5febd1c5ff8.ll
1.      Running pass 'Function Pass Manager' on module 'core-c7f0b5febd1c5ff8.ll'.
2.      Running pass 'C backend' on function '@_ZN4core3num3fmt4Part5write17h3ba8354fc9370b66E'
@zlfn zlfn added enhancement New feature or request external This issue requires contribute to external tools long term plan It's a work that requires a lot of effort to implement labels Oct 14, 2024
@zlfn
Copy link
Owner Author

zlfn commented Oct 15, 2024

If we raise the Rust version to the latest Nightly, no_fp_fmt_parse works properly, so we don't have to worry about llvm.is.fpclass. But for this, llvm-cbe's LLVM version must be upgraded to LLVM-19.

@zlfn
Copy link
Owner Author

zlfn commented Oct 16, 2024

Implementation PR for llvm.uadd.sat.i32 and llvm.usub.sat.i16 submitted.
JuliaHubOSS/llvm-cbe#210

@zlfn
Copy link
Owner Author

zlfn commented Oct 17, 2024

If we raise the Rust version to the latest Nightly, no_fp_fmt_parse works properly, so we don't have to worry about llvm.is.fpclass. But for this, llvm-cbe's LLVM version must be upgraded to LLVM-19.

LLVM-19 Support PR for llvm-cbe submitted.
JuliaHubOSS/llvm-cbe#211

@zlfn
Copy link
Owner Author

zlfn commented Oct 20, 2024

Partial compilation of the core via llvm-link succeeded. core::fmt is now available for u8/u16/i8/i16

@zlfn zlfn changed the title core compilation to C Full core compilation to C Oct 20, 2024
@zlfn
Copy link
Owner Author

zlfn commented Oct 21, 2024

Thanks to the latest optimize_for_size flag, It looks like we can reduce the size of fmt a little bit. However, since llvm-cbe causes Pass related errors, we need to resolve LLVM-CBE error2.
rust-lang/rust#125612

@zlfn zlfn changed the title Full core compilation to C Tracking Issue for core compilation to C Oct 21, 2024
@zlfn zlfn added bug Something isn't working tracking-issue A tracking issue for unstable or not implemented feature and removed enhancement New feature or request labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external This issue requires contribute to external tools long term plan It's a work that requires a lot of effort to implement tracking-issue A tracking issue for unstable or not implemented feature
Projects
None yet
Development

No branches or pull requests

1 participant