Comments (6)
@kazcw what is our alternative? How likely is this to fail in practice?
from remacs.
If it were just a matter of breaking rustc
's invariants that might not be as bad, because rustc
itself doesn't do a lot of wild optimizations; but it compiles to getelementptr inbounds { ... }, { ... }* null, ...
, which is a trap value to LLVM, causing the subsequent ptrtoint
to be UB, and leaving you at LLVM's mercy. LLVM's mercy tends to involve nasal demons.
In this case one option would be: instead of doing the address calculations using a hypothetical instance at NULL, use a real instance. Since this macro is only used with C structs, and Rust has no constraints on the value range of fields in C structs, the example value can be conjured with mem::zeroed
. You could use a trivial trait to mark that the types it operates on can be zero-initialized safely, and then use the trait's method instead of ptr::null()
. In release builds the example value will be optimized away.
from remacs.
Thank you for the explanation @kazcw that is very helpful.
from remacs.
Ok, let's try moving to https://github.com/Gilnaa/memoffset.
This does NOT fix the problem that @kazcw raises. However, it moves the problem of solving it out of our code base. They have ideas and are looking at using solutions from the RFC mentioned which has actually been more than partially implemented. Long term, there may end up being a supported macro from the Rust core and we drop the dependency. A pre-RFC exists for such a macro currently.
from remacs.
In that case I presume we need to replace the usage of offset_of!
the field-offset crate in LispBufferRef::reset_local_variables
as well? (I didn't realize we had our own macro when I imported that crate)
from remacs.
FWIW, the latest version of https://github.com/Gilnaa/memoffset actually works in a way that is compliant with the Rust Reference. :)
But doing *
on a NULL pointer is still UB, even inside addr_of!
.
from remacs.
Related Issues (20)
- Making Emacs truly modular? HOT 6
- I had to run autogen.sh twice HOT 11
- The build process is so slow, it's already been a day and it's still compiling. HOT 7
- macOS: cannot build remacs due to libxml/tree.h file not found HOT 10
- WASM plugin support HOT 5
- lsp: wrong-number-of-arguments json-serialize 5 HOT 2
- eglot: wrong-number-of-arguments HOT 2
- Still Alive/Lost Momentum? HOT 35
- setq scroll-up-aggressively reversed logic HOT 2
- Unable to compile vm-limit.o on WSL HOT 3
- Build fails with master branch (28ae673b26): make[1]: *** [bootstrap-emacs] segment violation (core dumped)
- Mission criticality of remacs? HOT 2
- error: unexpected closing delimiter: `]` in src/../generated/bindings.rs:15424:39
- Is it possible to merge these rust code to main Emacs repos? HOT 1
- Make this project more viable: change the license HOT 9
- Add: Cargo.lock for create a PR in nixpkgs HOT 5
- To rust is to miss the point
- [make error] sysdep.c:1741:22: error: variably modified 'sigsegv_stack' at file scope HOT 1
- go not found mac
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remacs.