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

liballoc_jemalloc nallocx should be ReadOnly #46046

Closed
gnzlbg opened this issue Nov 16, 2017 · 4 comments
Closed

liballoc_jemalloc nallocx should be ReadOnly #46046

gnzlbg opened this issue Nov 16, 2017 · 4 comments
Labels
A-codegen Area: Code generation C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Nov 16, 2017

nallocx is a [[pure]] function in the GCC sense, and should have the LLVM ReadOnly attribute. I've been looking for a way to apply LLVM attributes to functions in Rust without much luck (another interesting one is ReadNone, GCC's const attribute).

Is there a way to do this?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Nov 16, 2017

Clang doesn't appear to add the readnone attribute to malloc

That's because malloc is not gcc::pure. As I mentioned, however, nallocx is.

so I am skeptical whether it would be sound for us to add it to a similar allocation function.

The C code already makes that assumption, and is compiled with it, so if it turns out that nallocx isn't really gcc::pure we will be invoking undefined behavior whether we add the readnone attribute or not.

@hanna-kruppe
Copy link
Contributor

Oh, I misunderstood what nallocx does, disregard me.

@kennytm kennytm added A-codegen Area: Code generation C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Nov 16, 2017
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Nov 17, 2017

The quick and dirty way would be to add two attributes, #[llvm_readonly] and #[llvm_readnone] behind two feature gates for internal use in core and std.

A more useful thing to do would be to add some #[c_attributes(attr...)] attribute that only works with C-FFI (which is unsafe anyways) and that recognizes the C attributes that we currently don't expose in Rust (e.g. gcc::const, gcc::pure, ...) so that we can propagate these attributes to the Rust side when doing FFI.

@workingjubilee
Copy link
Member

liballoc_jemalloc is no longer a core component of the Rust runtime, instead being used as a library by the Rust compiler.

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants