-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
System.alloc returns unaligned pointer if align > size #45955
Comments
I think some explanation for what's going on is that it actually seems to use jemalloc, even though I explicitly called the system allocator. That can't be right, can it? If I add #[global_allocator]
static GLOBAL: System = System; the buggy behavior disappears, but shouldn't I be able to use the system allocator locally without affecting the global default? |
I did some digging. The https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf#subsection.3.1.2
“Global array variable” presumably applies to I haven’t looked if other architecture’s ABIs have a similar requirement that we can rely on. I did look in the C standard. It says that However [1] It looks like when C11 referenceshttps://port70.net/~nsz/c/c11/n1570.html#7.22.3
https://port70.net/~nsz/c/c11/n1570.html#6.2.8p2
https://port70.net/~nsz/c/c11/n1570.html#7.19p2
|
Firefox ran into crashes when mozjemalloc did not guarantee 8 / 16: https://www.erahm.org/2016/03/24/minimum-alignment-of-allocation-across-platforms/ GNU libc’s allocator does guarantee 8 / 16 (https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html), but we apparently can’t rely on it being behind the |
#46117 should fix this. |
The following code:
prints
8 0
on my machine and on the playground. That's a bug; since I requested alignment 16 for both pointers, it should only ever print0 0
.This is probably caused by the
MIN_ALIGN
optimization inalloc_system
. This optimization is currently mostly useless, but it also seems to be wrong. I do not know what the actual alignment guarantees are; maybe the values are wrong or maybe the guarantee only holds forsize >= align
.The text was updated successfully, but these errors were encountered: