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

remove the need for foreign ABI wrappers #10116

Closed
thestinger opened this issue Oct 28, 2013 · 6 comments · Fixed by #32080
Closed

remove the need for foreign ABI wrappers #10116

thestinger opened this issue Oct 28, 2013 · 6 comments · Fixed by #32080
Labels
I-compiletime Issue: Problems and improvements with respect to compile times. I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@thestinger
Copy link
Contributor

To generate code for extern "C" fn foo(), rustc will create a Rust function and wrap it inside a function exposing the C ABI. This is bad for compile-time, but more importantly it makes it very hard to write functions like memset, memcpy and memmove for freestanding Rust because LLVM will kindly replace their body with a call to the intrinsic, and then lower that to an infinitely recursive function.

https://github.com/thestinger/rust-core#freestanding

@nikomatsakis
Copy link
Contributor

Can you elaborate on what leads to an infinitely recursing function?

@thestinger
Copy link
Contributor Author

@nikomatsakis: LLVM's loop-idiom pass replaces loops with the memset and memcpy intrinsics. It's hardcoded to not to this in functions with the name memset or memcpy. Inlining is interleaved with the other passes so it's not enough that loop-idiom runs late.

@eholk
Copy link
Contributor

eholk commented Nov 21, 2013

Out of curiosity, is there even still a need for these wrappers? Rust seems to support multiple calling conventions without any trouble. I believe used to the challenge was we needed to pass things like a task pointer around, but now I think Rust get's these from TLS.

@thestinger
Copy link
Contributor Author

@eholk: I think the only reason the wrappers exist is that Rust doesn't currently know how to output the ABI <-> ABI casts directly inside the function it's generating. The code generation for function bodies just assumes it's directly using the parameters and only knows about the Rust ABI.

@brson
Copy link
Contributor

brson commented Jan 30, 2014

Can we run LLVM passes in different orders to make the inlining issues go away?

@thestinger
Copy link
Contributor Author

@brson: I don't think so. The inline pass is placed long before loop-idiom, but LLVM actually spreads out the inlining process. If we mess with the passes by splitting them up (run a module pass with only inline first) or changing the order, we'll also likely hurt compile-time and/or performance. This is quite feasibly fixable with some refactoring work in trans.

alexcrichton added a commit to alexcrichton/rust that referenced this issue May 15, 2014
The core library in theory has 0 dependencies, but in practice it has some in
order for it to be efficient. These dependencies are in the form of the basic
memory operations provided by libc traditionally, such as memset, memcmp, etc.
These functions are trivial to implement and themselves have 0 dependencies.

This commit adds a new crate, librlibc, which will serve the purpose of
providing these dependencies. The crate is never linked to by default, but is
available to be linked to by downstream consumers. Normally these functions are
provided by the system libc, but in other freestanding contexts a libc may not
be available. In these cases, librlibc will suffice for enabling execution with
libcore.

cc rust-lang#10116
alexcrichton added a commit to alexcrichton/rust that referenced this issue May 15, 2014
The core library in theory has 0 dependencies, but in practice it has some in
order for it to be efficient. These dependencies are in the form of the basic
memory operations provided by libc traditionally, such as memset, memcmp, etc.
These functions are trivial to implement and themselves have 0 dependencies.

This commit adds a new crate, librlibc, which will serve the purpose of
providing these dependencies. The crate is never linked to by default, but is
available to be linked to by downstream consumers. Normally these functions are
provided by the system libc, but in other freestanding contexts a libc may not
be available. In these cases, librlibc will suffice for enabling execution with
libcore.

cc rust-lang#10116
alexcrichton added a commit to alexcrichton/rust that referenced this issue May 15, 2014
The core library in theory has 0 dependencies, but in practice it has some in
order for it to be efficient. These dependencies are in the form of the basic
memory operations provided by libc traditionally, such as memset, memcmp, etc.
These functions are trivial to implement and themselves have 0 dependencies.

This commit adds a new crate, librlibc, which will serve the purpose of
providing these dependencies. The crate is never linked to by default, but is
available to be linked to by downstream consumers. Normally these functions are
provided by the system libc, but in other freestanding contexts a libc may not
be available. In these cases, librlibc will suffice for enabling execution with
libcore.

cc rust-lang#10116
@thestinger thestinger added the I-compiletime Issue: Problems and improvements with respect to compile times. label Oct 21, 2014
@emberian emberian self-assigned this Mar 25, 2015
@emberian emberian removed their assignment Jan 5, 2016
@dotdash dotdash self-assigned this Jan 11, 2016
@dotdash dotdash removed their assignment Mar 4, 2016
bors added a commit that referenced this issue Mar 18, 2016
Refactor call & function handling in trans, enable MIR bootstrap.

Non-Rust and Rust ABIs were combined into a common codepath, which means:
* The ugly `__rust_abi` "clown shoes" shim for C->Rust FFI is gone, fixes #10116.
* Methods, *including virtual ones* support non-Rust ABIs, closes #30235.
* Non-Rust ABIs also pass fat pointers in two arguments; the result should be identical.
* Zero-sized types are never passed as arguments; again, behavior shouldn't change.

Additionally, MIR support for calling intrinsics (through old trans) was implemented.
Alongside assorted fixes, it enabled MIR to launch 🚀 and do a *complete* bootstrap.
To try it yourself, `./configure --enable-orbit` *or* `make RUSTFLAGS="-Z orbit"`.
bors added a commit that referenced this issue Mar 18, 2016
Refactor call & function handling in trans, enable MIR bootstrap.

Non-Rust and Rust ABIs were combined into a common codepath, which means:
* The ugly `__rust_abi` "clown shoes" shim for C->Rust FFI is gone, fixes #10116.
* Methods, *including virtual ones* support non-Rust ABIs, closes #30235.
* Non-Rust ABIs also pass fat pointers in two arguments; the result should be identical.
* Zero-sized types are never passed as arguments; again, behavior shouldn't change.

Additionally, MIR support for calling intrinsics (through old trans) was implemented.
Alongside assorted fixes, it enabled MIR to launch 🚀 and do a *complete* bootstrap.
To try it yourself, `./configure --enable-orbit` *or* `make RUSTFLAGS="-Z orbit"`.
bors added a commit that referenced this issue Mar 18, 2016
Refactor call & function handling in trans, enable MIR bootstrap.

Non-Rust and Rust ABIs were combined into a common codepath, which means:
* The ugly `__rust_abi` "clown shoes" shim for C->Rust FFI is gone, fixes #10116.
* Methods, *including virtual ones* support non-Rust ABIs, closes #30235.
* Non-Rust ABIs also pass fat pointers in two arguments; the result should be identical.
* Zero-sized types are never passed as arguments; again, behavior shouldn't change.

Additionally, MIR support for calling intrinsics (through old trans) was implemented.
Alongside assorted fixes, it enabled MIR to launch 🚀 and do a *complete* bootstrap.
To try it yourself, `./configure --enable-orbit` *or* `make RUSTFLAGS="-Z orbit"`.
flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 29, 2022
`not_unsafe_ptr_arg_deref` update documentation

changelog: [`not_unsafe_ptr_arg_deref`]: strengthened documentation wording, fixes rust-lang#7714
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-compiletime Issue: Problems and improvements with respect to compile times. I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants