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

Write a document for others wanting to implement a rustc codegen backend #647

Closed
bjorn3 opened this issue Jul 27, 2019 · 1 comment
Closed

Comments

@bjorn3
Copy link
Member

bjorn3 commented Jul 27, 2019

It should at least include assumptions made by rustc and libstd, like:

  • fn((), u8) and fn(u8) are abi compatible (assumes by ClosureFnPointer, found in https://github.com/bjorn3/rustc_codegen_cranelift/issues/413)
  • BinOp::Offset and the offset and arith_offset use pointer arithmetic (found in https://github.com/bjorn3/rustc_codegen_cranelift/issues/341)
  • Don't ever stub out unimplemented stuff by using a dummy value, instead use a trap. Even something simple as making checked binops never overflow causes hard to debug breakage at many places, especially 128bit int emulation and bigint arithmetic, as those need the overflow flag as carry/borrow. (eg https://github.com/bjorn3/rustc_codegen_cranelift/issues/381#issuecomment-475882825)
  • Dont implement stuff the way you think it should, without a test using it. See for example bjorn3@0d16dcf for the fix of a problem that could probably have been prevented that way.
  • Alignment of stuff is important. libcore contains alignment debug asserts and some os functions will return an error on wrong alignment.
  • DST's are hard to get right. Write many tests for then!
  • Add many asserts, for example check that types are compatible when writing a value to a place.
  • SysV abi requires ByRef params to be passed at the right memory offset, not passing a pointer to the value in register.

https://github.com/dropbox/rust-brotli-decompressor is a good example of a simple project which contains a binary.

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 25, 2022

This is not something actionable on cg_clif's side. Tracking this in rust-lang/rustc-dev-guide#442 instead would be better I think.

@bjorn3 bjorn3 closed this as completed Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant